]> git.tdb.fi Git - builder.git/commitdiff
Improve prefix management
authorMikko Rasa <tdb@tdb.fi>
Tue, 27 Dec 2022 01:23:31 +0000 (03:23 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 27 Dec 2022 01:23:31 +0000 (03:23 +0200)
An automatically set prefix is now updated when the default toolchain
is selected.  Setting the architecture won't override prefix if it was
already explicitly set.

source/builder.cpp
source/builder.h

index 6f90c9d417598747e74daedac3bb7e7e30301631..3fc60bec2afc5b22f61175bf6dab10ed6f23e7dd 100644 (file)
@@ -52,15 +52,12 @@ void Builder::set_architecture(const string &name)
                delete current_arch;
 
        if(name.empty())
-       {
                current_arch = &native_arch;
-               prefix = FS::get_home_dir()/"local";
-       }
        else
-       {
                current_arch = new Architecture(*this, name);
-               prefix = FS::get_home_dir()/"local"/current_arch->get_name();
-       }
+
+       if(auto_prefix)
+               update_auto_prefix();
 }
 
 vector<string> Builder::get_build_types() const
@@ -86,6 +83,7 @@ void Builder::set_build_type(const string &name)
 
 void Builder::set_prefix(const FS::Path &p)
 {
+       auto_prefix = false;
        prefix = p;
 }
 
@@ -94,6 +92,14 @@ void Builder::set_temp_directory(const FS::Path &p)
        tempdir = p;
 }
 
+void Builder::update_auto_prefix()
+{
+       if(current_arch->is_native())
+               prefix = FS::get_home_dir()/"local";
+       else
+               prefix = FS::get_home_dir()/"local"/current_arch->get_name();
+}
+
 void Builder::add_default_tools()
 {
        toolchain.add_toolchain(new GnuTools(*this, *current_arch));
@@ -107,7 +113,11 @@ void Builder::add_default_tools()
 
        auto i = find_if(toolchain.get_toolchains(), [](const Toolchain *tc){ return (tc->has_tool("CC") || tc->has_tool("CXX")); });
        if(i!=toolchain.get_toolchains().end())
+       {
                current_arch->refine((*i)->get_name());
+               if(auto_prefix)
+                       update_auto_prefix();
+       }
 }
 
 void Builder::set_logger(const Logger *l)
index 331c50ab9a57be2c92fb2ed91a4fab98c598d2b0..e06cec34e73c6efbea21f1dee7a5839d15ef7e96 100644 (file)
@@ -56,6 +56,7 @@ private:
        Logger default_logger;
        const Logger *logger;
 
+       bool auto_prefix = true;
        Msp::FS::Path prefix;
        Msp::FS::Path tempdir = "temp";
 
@@ -79,6 +80,10 @@ public:
        const Msp::FS::Path &get_prefix() const { return prefix; }
        const Msp::FS::Path &get_temp_directory() const { return tempdir; }
 
+private:
+       void update_auto_prefix();
+
+public:
        void add_default_tools();
        const Toolchain &get_toolchain() const { return toolchain; }
        VirtualFileSystem &get_vfs() { return vfs; }