From: Mikko Rasa Date: Tue, 7 Mar 2023 23:30:22 +0000 (+0200) Subject: Move some path and filename manipulations into the Component class X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=fa77f807be7a92e655befa2c344128d2dadd788f Move some path and filename manipulations into the Component class --- diff --git a/source/lib/component.cpp b/source/lib/component.cpp index 61aa0db..637bc18 100644 --- a/source/lib/component.cpp +++ b/source/lib/component.cpp @@ -65,6 +65,28 @@ void Component::create_build_info() p = (package.get_source_directory()/p).str(); } +FS::Path Component::get_temp_directory() const +{ + return package.get_temp_directory()/name; +} + +string Component::flatten_source_path(const FS::Path &source) const +{ + FS::Path temp_dir = get_temp_directory(); + FS::Path rel_src; + 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()); + + string fn; + for(const string &c: rel_src) + if(c!=".") + append(fn, "_", c); + + return fn; +} + BuildInfo Component::get_build_info_for_path(const FS::Path &path) const { // XXX Cache these and check that the directories actually exist before adding them diff --git a/source/lib/component.h b/source/lib/component.h index 246bd44..543ba33 100644 --- a/source/lib/component.h +++ b/source/lib/component.h @@ -74,6 +74,9 @@ public: /** Prepares any required packages. */ void prepare(); + Msp::FS::Path get_temp_directory() const; + std::string flatten_source_path(const Msp::FS::Path &) const; + /** Prepares the build information for building. Pulls build info from the parent and dependency packages, and adds any component-specific flags. */ virtual void create_build_info(); diff --git a/source/lib/objectfile.cpp b/source/lib/objectfile.cpp index 65ad433..63a8e6b 100644 --- a/source/lib/objectfile.cpp +++ b/source/lib/objectfile.cpp @@ -19,23 +19,9 @@ 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(); - FS::Path rel_src; - if(FS::descendant_depth(src, temp_dir)>=0) - rel_src = FS::relative(src, temp_dir); - else - rel_src = FS::relative(src, pkg.get_source_directory()); - string fn; - for(const string &c: rel_src) - { - if(!fn.empty()) - fn += '_'; - if(c!=".") - fn += c; - } + string fn = comp.flatten_source_path(src); const Architecture &arch = comp.get_package().get_builder().get_current_arch(); - return temp_dir/comp.get_name()/arch.create_filename(FS::basepart(fn)); + return comp.get_temp_directory()/arch.create_filename(FS::basepart(fn)); } void ObjectFile::set_used_in_shared_library(bool u)