From: Mikko Rasa Date: Tue, 7 Mar 2023 23:53:36 +0000 (+0200) Subject: Rearrange generated source paths X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6ce67e1469bf62156ddf64e33644851f9064c6ed;p=builder.git Rearrange generated source paths --- diff --git a/source/lib/component.cpp b/source/lib/component.cpp index c12a5a8..1ba258b 100644 --- a/source/lib/component.cpp +++ b/source/lib/component.cpp @@ -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) diff --git a/source/lib/component.h b/source/lib/component.h index 543ba33..2901f1b 100644 --- a/source/lib/component.h +++ b/source/lib/component.h @@ -37,6 +37,7 @@ protected: SourcePackage &package; std::string name; std::vector sources; + Msp::FS::Path source_base_path; std::vector overlays; bool install = false; BuildInfo build_info; diff --git a/source/lib/sourcegenerator.cpp b/source/lib/sourcegenerator.cpp index d30a2bc..1056775 100644 --- a/source/lib/sourcegenerator.cpp +++ b/source/lib/sourcegenerator.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "builder.h" #include "executable.h" #include "sourcegenerator.h" @@ -30,21 +31,20 @@ Target *SourceGenerator::create_target(const vector &sources, const st TemplateFile &tmpl = dynamic_cast(*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 &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)