From 84b614a344280bb5cd2aa87bfb8c874d131c4c85 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 17 Dec 2022 02:15:36 +0200 Subject: [PATCH] Create a directory structure for generated source files --- source/objectfile.cpp | 4 ++-- source/sourcegenerator.cpp | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 1e6cb23..8196ef7 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -21,7 +21,7 @@ ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s): FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path &src) { const SourcePackage &pkg = comp.get_package(); - FS::Path temp_dir = pkg.get_temp_directory()/comp.get_name(); + FS::Path temp_dir = pkg.get_temp_directory(); FS::Path rel_src; if(FS::descendant_depth(src, temp_dir)>=0) rel_src = FS::relative(src, temp_dir); @@ -36,7 +36,7 @@ FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path fn += *i; } const Architecture &arch = comp.get_package().get_builder().get_current_arch(); - return temp_dir/arch.create_filename(FS::basepart(fn)); + return temp_dir/comp.get_name()/arch.create_filename(FS::basepart(fn)); } void ObjectFile::set_used_in_shared_library(bool u) diff --git a/source/sourcegenerator.cpp b/source/sourcegenerator.cpp index 5123f09..584822a 100644 --- a/source/sourcegenerator.cpp +++ b/source/sourcegenerator.cpp @@ -30,13 +30,21 @@ Target *SourceGenerator::create_target(const list &sources, const stri TemplateFile &tmpl = dynamic_cast(*sources.front()); const Component *comp = tmpl.get_component(); const SourcePackage *pkg = tmpl.get_package(); + FS::Path subdir; string base; - if(processing_unit==ONE_FILE) - base = FS::basepart(FS::basename(tmpl.get_path())); - else if(processing_unit==DIRECTORY) - base = FS::basename(FS::dirname(tmpl.get_path())); - else + if(processing_unit==COMPONENT) base = comp->get_name(); + else + { + subdir = FS::dirname(FS::relative(tmpl.get_path(), pkg->get_source_directory())); + 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); + } + } Target *primary = 0; for(list::const_iterator i=out_suffixes.begin(); i!=out_suffixes.end(); ++i) @@ -44,7 +52,7 @@ Target *SourceGenerator::create_target(const list &sources, const stri Tool *tool = builder.get_toolchain().get_tool_for_suffix(*i, true); if(tool) { - FS::Path fn = pkg->get_temp_directory()/comp->get_name()/(base+*i); + FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+*i); Target *target = tool->create_source(*comp, fn); target->set_tool(*this); for(list::const_iterator j=sources.begin(); j!=sources.end(); ++j) -- 2.43.0