]> git.tdb.fi Git - builder.git/blobdiff - source/builder.cpp
Avoid a memory leak if Builder::set_architecture is called again
[builder.git] / source / builder.cpp
index 239258196632ca82d8928c0aeceb9d64700b2af0..6f90c9d417598747e74daedac3bb7e7e30301631 100644 (file)
@@ -1,5 +1,6 @@
 #include <deque>
 #include <set>
+#include <msp/core/algorithm.h>
 #include <msp/core/except.h>
 #include <msp/core/maputils.h>
 #include <msp/datafile/parser.h>
@@ -32,13 +33,9 @@ using namespace Msp;
 Builder::Builder():
        package_manager(*this),
        native_arch(*this, string()),
-       current_arch(0),
-       build_type(0),
        vfs(*this),
        build_graph(*this),
-       logger(&default_logger),
-       tempdir("temp"),
-       top_loader(0)
+       logger(&default_logger)
 {
        set_architecture(string());
 }
@@ -51,6 +48,9 @@ Builder::~Builder()
 
 void Builder::set_architecture(const string &name)
 {
+       if(current_arch!=&native_arch)
+               delete current_arch;
+
        if(name.empty())
        {
                current_arch = &native_arch;
@@ -96,17 +96,18 @@ void Builder::set_temp_directory(const FS::Path &p)
 
 void Builder::add_default_tools()
 {
-       const string &arch_tc = current_arch->get_toolchain();
+       toolchain.add_toolchain(new GnuTools(*this, *current_arch));
+       toolchain.add_toolchain(new ClangTools(*this, *current_arch));
        if(current_arch->get_system()=="android")
                toolchain.add_toolchain(new AndroidTools(*this, *current_arch));
-       else if(arch_tc=="msvc")
+       if(current_arch->get_system()=="windows")
                toolchain.add_toolchain(new MicrosoftTools(*this, *current_arch));
-       else if(arch_tc=="clang")
-               toolchain.add_toolchain(new ClangTools(*this, *current_arch));
-       else if(arch_tc=="gnu")
-               toolchain.add_toolchain(new GnuTools(*this, *current_arch));
        toolchain.add_toolchain(new BuiltinTools(*this));
        toolchain.add_tool(new DataTool(*this));
+
+       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());
 }
 
 void Builder::set_logger(const Logger *l)
@@ -200,7 +201,11 @@ int Builder::build(unsigned jobs, bool dry_run, bool show_progress)
                        if(tgt)
                        {
                                if(tgt->get_tool())
+                               {
+                                       if(show_progress)
+                                               IO::print("\033[K");
                                        get_logger().log("tasks", "%-4s  %s", tgt->get_tool()->get_tag(), tgt->get_name());
+                               }
                                Task *task = tgt->build();
                                if(task)
                                {