From 6ce67e1469bf62156ddf64e33644851f9064c6ed Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 8 Mar 2023 01:53:36 +0200 Subject: [PATCH] Rearrange generated source paths --- source/lib/component.cpp | 17 ++++++++++++++++- source/lib/component.h | 1 + source/lib/sourcegenerator.cpp | 16 ++++++++-------- 3 files changed, 25 insertions(+), 9 deletions(-) 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) -- 2.43.0