From: Mikko Rasa Date: Tue, 7 Mar 2023 23:57:30 +0000 (+0200) Subject: Install headers of non-installed components in a staging directory X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=a8dd31308dfef6da930c261779d4e9ebfc2af838 Install headers of non-installed components in a staging directory This allows components to include headers from other local components in a controlled fashion. --- diff --git a/source/lib/binarycomponent.cpp b/source/lib/binarycomponent.cpp index 0b5d3cf..c626536 100644 --- a/source/lib/binarycomponent.cpp +++ b/source/lib/binarycomponent.cpp @@ -95,7 +95,7 @@ void BinaryComponent::create_targets() const if(tool->accepts_suffix(ext)) { t = &dynamic_cast(*tool->create_target(*t)); - if(type==LIBRARY && install) + if(type==LIBRARY) create_install(*t); } } @@ -106,7 +106,7 @@ void BinaryComponent::create_targets() const vector group = extract_group(pending, *tool); FileTarget &tgt = dynamic_cast(*tool->create_target(group)); pending.push_back(&tgt); - if(type==LIBRARY && install) + if(type==LIBRARY) create_install(tgt); } } @@ -159,7 +159,7 @@ vector BinaryComponent::create_sources() const if(FileTarget *file = dynamic_cast(src)) { targets.push_back(file); - if(type==LIBRARY && install) + if(type==LIBRARY) create_install(*file); } } @@ -193,13 +193,14 @@ vector BinaryComponent::extract_group(vector &targets, c void BinaryComponent::create_install(FileTarget &target) const { BuildGraph &build_graph = package.get_builder().get_build_graph(); + auto add_func = (install ? &BuildGraph::add_installed_target : &BuildGraph::add_staged_target); if(target.is_installable()) - build_graph.add_installed_target(target); + (build_graph.*add_func)(target); for(Target *s: target.get_side_effects()) if(dynamic_cast(*s).is_installable()) - build_graph.add_installed_target(*s); + (build_graph.*add_func)(*s); } diff --git a/source/lib/buildgraph.cpp b/source/lib/buildgraph.cpp index 070f934..e440cf8 100644 --- a/source/lib/buildgraph.cpp +++ b/source/lib/buildgraph.cpp @@ -55,6 +55,11 @@ void BuildGraph::add_installed_target(Target &t) get_target("install")->add_dependency(*inst_tgt); } +void BuildGraph::add_staged_target(Target &t) +{ + builder.get_toolchain().get_tool("CP").create_target(t, "//"); +} + void BuildGraph::add_goal(Target &t) { goals->add_dependency(t); diff --git a/source/lib/buildgraph.h b/source/lib/buildgraph.h index 9092532..8b7a0ca 100644 --- a/source/lib/buildgraph.h +++ b/source/lib/buildgraph.h @@ -41,6 +41,8 @@ public: created and added as a dependency to the "install" virtual target. */ void add_installed_target(Target &); + void add_staged_target(Target &); + /** Adds a target as a toplevel goal. These are stored as dependencies of the "goals" virtual target. */ void add_goal(Target &); diff --git a/source/lib/installedfile.cpp b/source/lib/installedfile.cpp index ef7a770..bf542b0 100644 --- a/source/lib/installedfile.cpp +++ b/source/lib/installedfile.cpp @@ -26,18 +26,18 @@ FS::Path InstalledFile::generate_target_path(const FS::Path &global_prefix, cons if(!tgt.get_package()) throw invalid_argument("No private install location for "+tgt.get_name()); - prefix = tgt.get_package()->get_temp_directory(); + prefix = tgt.get_package()->get_staging_directory(); mid = loc.substr(2); } else { prefix = global_prefix; + mid = loc; + } - if(!loc.empty()) - mid = loc; - else if(const Component *comp = tgt.get_component()) + if(mid.empty()) + if(const Component *comp = tgt.get_component()) mid = comp->get_install_map().get_install_location(tgt); - } if(mid.empty()) mid = tgt.get_install_location(); diff --git a/source/lib/sourcepackage.cpp b/source/lib/sourcepackage.cpp index 5c286dd..dabda21 100644 --- a/source/lib/sourcepackage.cpp +++ b/source/lib/sourcepackage.cpp @@ -65,6 +65,11 @@ FS::Path SourcePackage::get_output_directory() const return source_dir/arch.get_name(); } +FS::Path SourcePackage::get_staging_directory() const +{ + return get_temp_directory()/"staging"; +} + const Component &SourcePackage::get_component(const string &n) const { auto i = find_if(components, [&n](const Component *c){ return c->get_name()==n; }); @@ -97,8 +102,9 @@ void SourcePackage::do_prepare() final_build_info.update_from(build_info); build_info = final_build_info; - build_info.incpath.push_back((builder.get_prefix()/"include").str()); - build_info.libpath.push_back((builder.get_prefix()/"lib").str()); + build_info.incpath.push_back(get_staging_directory()/"include"); + build_info.incpath.push_back(builder.get_prefix()/"include"); + build_info.libpath.push_back(builder.get_prefix()/"lib"); for(const Feature &f: features) { diff --git a/source/lib/sourcepackage.h b/source/lib/sourcepackage.h index c6e308a..c311c21 100644 --- a/source/lib/sourcepackage.h +++ b/source/lib/sourcepackage.h @@ -94,6 +94,7 @@ public: const Msp::FS::Path &get_source_directory() const { return source_dir; } Msp::FS::Path get_temp_directory() const; Msp::FS::Path get_output_directory() const; + Msp::FS::Path get_staging_directory() const; const Toolchain &get_toolchain() const { return local_tools; } const Component &get_component(const std::string &) const;