]> git.tdb.fi Git - builder.git/commitdiff
Move some path and filename manipulations into the Component class
authorMikko Rasa <tdb@tdb.fi>
Tue, 7 Mar 2023 23:30:22 +0000 (01:30 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 7 Mar 2023 23:30:22 +0000 (01:30 +0200)
source/lib/component.cpp
source/lib/component.h
source/lib/objectfile.cpp

index 61aa0db855867ed91863ec1e2d99b336c849f4a6..637bc187c8dc26fae0fa45600d7721a8dbe1387b 100644 (file)
@@ -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
index 246bd44edd2e07c7fa1fedfb7cc8d7dcce1c1c3d..543ba33af457bedc8266c0296b76594b149f572a 100644 (file)
@@ -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();
index 65ad4330cb740b6ecc57e7f9fd4f8b3783e93399..63a8e6b2b7c44a61c6699b71eb7f5d94e5ac2862 100644 (file)
@@ -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<ObjectFile>(FS::basepart(fn));
+       return comp.get_temp_directory()/arch.create_filename<ObjectFile>(FS::basepart(fn));
 }
 
 void ObjectFile::set_used_in_shared_library(bool u)