]> git.tdb.fi Git - builder.git/commitdiff
Rearrange generated source paths
authorMikko Rasa <tdb@tdb.fi>
Tue, 7 Mar 2023 23:53:36 +0000 (01:53 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 7 Mar 2023 23:53:36 +0000 (01:53 +0200)
source/lib/component.cpp
source/lib/component.h
source/lib/sourcegenerator.cpp

index c12a5a8c604916a3777d8a783afe976b4e90177a..1ba258bd70a00f4011587bd3617ccff24796a7ce 100644 (file)
@@ -20,6 +20,21 @@ void Component::prepare()
                broken |= r->is_broken();
        }
 
+       if(!sources.empty())
+       {
+               for(auto i=sources.begin(); i!=sources.end(); ++i)
+               {
+                       FS::Path s = *i;
+                       if(!FS::is_dir(s))
+                               s = FS::dirname(s);
+
+                       if(i==sources.begin())
+                               source_base_path = s;
+                       else
+                               source_base_path = FS::common_ancestor(source_base_path, s);
+               }
+       }
+
        if(!problems.empty())
                broken = true;
 }
@@ -77,7 +92,7 @@ string Component::flatten_source_path(const FS::Path &source) const
        if(FS::descendant_depth(source, temp_dir)>=0)
                rel_src = FS::relative(source, temp_dir);
        else
-               rel_src = FS::relative(source, package.get_source_directory());
+               rel_src = FS::relative(source, source_base_path);
 
        string fn;
        for(const string &c: rel_src)
index 543ba33af457bedc8266c0296b76594b149f572a..2901f1b1fc53f3ba2c0e6deddbcca98f8143637b 100644 (file)
@@ -37,6 +37,7 @@ protected:
        SourcePackage &package;
        std::string name;
        std::vector<Msp::FS::Path> sources;
+       Msp::FS::Path source_base_path;
        std::vector<std::string> overlays;
        bool install = false;
        BuildInfo build_info;
index d30a2bc67fdefa3687e6c18193b0c9eaae504c7c..10567758681876da038a447be8e9eb9f77a4c743 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #include "builder.h"
 #include "executable.h"
 #include "sourcegenerator.h"
@@ -30,21 +31,20 @@ Target *SourceGenerator::create_target(const vector<Target *> &sources, const st
 
        TemplateFile &tmpl = dynamic_cast<TemplateFile &>(*sources.front());
        const Component *comp = tmpl.get_component();
-       const SourcePackage *pkg = tmpl.get_package();
-       FS::Path subdir;
+       string subdir = "generated";
        string base;
        if(processing_unit==COMPONENT)
                base = comp->get_name();
        else
        {
-               subdir = FS::dirname(FS::relative(tmpl.get_path(), pkg->get_source_directory()));
+               string flat_dir = comp->flatten_source_path(FS::dirname(tmpl.get_path()));
                if(processing_unit==ONE_FILE)
-                       base = FS::basepart(FS::basename(tmpl.get_path()));
-               else if(processing_unit==DIRECTORY)
                {
-                       base = FS::basename(subdir);
-                       subdir = FS::dirname(subdir);
+                       append(subdir, "_", flat_dir);
+                       base = FS::basepart(FS::basename(tmpl.get_path()));
                }
+               else if(processing_unit==DIRECTORY)
+                       base = flat_dir;
        }
 
        Target *primary = 0;
@@ -53,7 +53,7 @@ Target *SourceGenerator::create_target(const vector<Target *> &sources, const st
                Tool *tool = builder.get_toolchain().get_tool_for_suffix(s, true);
                if(tool)
                {
-                       FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+s);
+                       FS::Path fn = comp->get_temp_directory()/subdir/(base+s);
                        Target *target = tool->create_source(*comp, fn);
                        target->set_tool(*this);
                        for(Target *t: sources)