]> git.tdb.fi Git - builder.git/commitdiff
Install headers of non-installed components in a staging directory
authorMikko Rasa <tdb@tdb.fi>
Tue, 7 Mar 2023 23:57:30 +0000 (01:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 7 Mar 2023 23:57:30 +0000 (01:57 +0200)
This allows components to include headers from other local components in
a controlled fashion.

source/lib/binarycomponent.cpp
source/lib/buildgraph.cpp
source/lib/buildgraph.h
source/lib/installedfile.cpp
source/lib/sourcepackage.cpp
source/lib/sourcepackage.h

index 0b5d3cf84d067c63b554af9c05f063415ca17074..c626536a2317622a1ebffdac3a3b6633921f7a0a 100644 (file)
@@ -95,7 +95,7 @@ void BinaryComponent::create_targets() const
                                if(tool->accepts_suffix(ext))
                                {
                                        t = &dynamic_cast<FileTarget &>(*tool->create_target(*t));
-                                       if(type==LIBRARY && install)
+                                       if(type==LIBRARY)
                                                create_install(*t);
                                }
                        }
@@ -106,7 +106,7 @@ void BinaryComponent::create_targets() const
                        vector<Target *> group = extract_group(pending, *tool);
                        FileTarget &tgt = dynamic_cast<FileTarget &>(*tool->create_target(group));
                        pending.push_back(&tgt);
-                       if(type==LIBRARY && install)
+                       if(type==LIBRARY)
                                create_install(tgt);
                }
        }
@@ -159,7 +159,7 @@ vector<FileTarget *> BinaryComponent::create_sources() const
                if(FileTarget *file = dynamic_cast<FileTarget *>(src))
                {
                        targets.push_back(file);
-                       if(type==LIBRARY && install)
+                       if(type==LIBRARY)
                                create_install(*file);
                }
        }
@@ -193,13 +193,14 @@ vector<Target *> BinaryComponent::extract_group(vector<FileTarget *> &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<FileTarget &>(*s).is_installable())
-                       build_graph.add_installed_target(*s);
+                       (build_graph.*add_func)(*s);
 }
 
 
index 070f934f6665edaa079885a1f8efa7b1f864e76b..e440cf8d8891e07c34ad0f67cc681089800b42db 100644 (file)
@@ -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);
index 9092532e158daa4c6018c54f012e92a4790e4283..8b7a0ca9d042f28d51ad8d6a5c59bf10a5cda59c 100644 (file)
@@ -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 &);
index ef7a7709e6335ba2f2682c5af6b71ed7e4524101..bf542b0082feafe7ad427c04180511f020e0964d 100644 (file)
@@ -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();
index 5c286dda9ba39e880cc371cd797a69d7b7cb1341..dabda21c99735ec0983171ccba76682848044c87 100644 (file)
@@ -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)
        {
index c6e308a44c95e72696f7fc8e2b51c2a7229b242d..c311c210e86431f06fffd6a2932ffa49604deaea 100644 (file)
@@ -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;