]> git.tdb.fi Git - builder.git/blobdiff - source/buildercli.cpp
Allow overriding tool commands on the command line
[builder.git] / source / buildercli.cpp
index 35eba9c03512fe9024c68aad1fe5e986cb9357de..0ce2bdc4ababa4a259820e0097e1214789df250c 100644 (file)
@@ -8,6 +8,8 @@
 #include "buildercli.h"
 #include "filetarget.h"
 #include "sourcepackage.h"
+#include "tool.h"
+#include "toolchain.h"
 
 using namespace std;
 using namespace Msp;
@@ -121,14 +123,16 @@ BuilderCLI::BuilderCLI(int argc, char **argv):
        else if(!clean && !create_makefile)
                build = true;
 
-       const vector<string> &args = getopt.get_args();
-       for(vector<string>::const_iterator i=args.begin(); i!=args.end(); ++i)
+       for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); )
        {
                string::size_type equal = i->find('=');
                if(equal!=string::npos)
+               {
                        cmdline_options.insert(Config::InputOptions::value_type(i->substr(0, equal), i->substr(equal+1)));
+                       cmdline_targets.erase(i++);
+               }
                else
-                       cmdline_targets.push_back(*i);
+                       ++i;
        }
 
        if(!work_dir.empty())
@@ -163,6 +167,18 @@ BuilderCLI::BuilderCLI(int argc, char **argv):
                builder.set_build_type(build_type);
 
        builder.add_default_tools();
+
+       const Toolchain &toolchain = builder.get_toolchain();
+       for(Config::InputOptions::iterator i=cmdline_options.begin(); i!=cmdline_options.end(); )
+       {
+               if(toolchain.has_tool(i->first))
+               {
+                       toolchain.get_tool(i->first).set_command(i->second);
+                       cmdline_options.erase(i++);
+               }
+               else
+                       ++i;
+       }
 }
 
 BuilderCLI::~BuilderCLI()
@@ -253,12 +269,12 @@ int BuilderCLI::main()
        if(analyzer)
                analyzer->analyze();
 
-       const Builder::ProblemList &problems = builder.get_problems();
-       if(!problems.empty())
+       if(build_graph.get_goals().is_broken())
        {
+               list<string> problems = builder.collect_problems();
                IO::print(IO::cerr, "The following problems were detected:\n");
-               for(Builder::ProblemList::const_iterator i=problems.begin(); i!=problems.end(); ++i)
-                       IO::print(IO::cerr, "  %s: %s\n", i->package, i->descr);
+               for(list<string>::const_iterator i=problems.begin(); i!=problems.end(); ++i)
+                       IO::print(IO::cerr, "  %s\n", *i);
                if(!analyzer)
                        IO::print(IO::cerr, "Please fix them and try again.\n");
                return 1;
@@ -313,11 +329,7 @@ bool BuilderCLI::prepare_build()
                build_graph.force_full_rebuild();
 
        if(!dry_run)
-       {
-               const PackageManager::PackageMap &packages = package_manager.get_packages();
-               for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
-                       i->second->save_caches();
-       }
+               package_manager.save_all_caches();
 
        return true;
 }
@@ -348,13 +360,29 @@ void BuilderCLI::package_help()
                        IO::print(", ");
                IO::print((*i)->get_name());
        }
-       IO::print("\n\nPackage configuration:\n");
-       for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
+       IO::print("\n");
+
+       if(!options.empty())
        {
-               const Config::Option &opt = i->second;
-               IO::print("  %s: %s (%s)", opt.name, opt.description, opt.value);
-               if(opt.value!=opt.default_value)
-                       IO::print(" [%s]", opt.default_value);
-               IO::print("\n");
+               IO::print("\nPackage configuration:\n");
+               for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
+               {
+                       const Config::Option &opt = i->second;
+                       string line = format("  %s: %s (%s)", opt.name, opt.description, opt.value);
+                       if(!opt.choices.empty())
+                       {
+                               line += " {";
+                               for(list<string>::const_iterator j=opt.choices.begin(); j!=opt.choices.end(); ++j)
+                               {
+                                       if(j!=opt.choices.begin())
+                                               line += ' ';
+                                       line += *j;
+                               }
+                               line += '}';
+                       }
+                       else if(opt.value!=opt.default_value)
+                               line += format(" [%s]", opt.default_value);
+                       IO::print("%s\n", line);
+               }
        }
 }