X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbuildercli.cpp;h=7482aced39c9923a51083eb3d71b6cd2483956b4;hb=c75c89d2425ab0c69e94d45a5d956286838bbc67;hp=bcd439e854c6fc9afb05df7832c0e192c3f87845;hpb=1dad660f7bbda5ef3239fd6374e0f8a77e19eaaa;p=builder.git diff --git a/source/buildercli.cpp b/source/buildercli.cpp index bcd439e..7482ace 100644 --- a/source/buildercli.cpp +++ b/source/buildercli.cpp @@ -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; @@ -63,10 +65,17 @@ BuilderCLI::BuilderCLI(int argc, char **argv): getopt.add_option( "max-depth", max_depth, GetOpt::REQUIRED_ARG).set_help("Show up to NUM levels in analysis.", "NUM"); getopt.add_option( "prefix", prefix, GetOpt::REQUIRED_ARG).set_help("Install things to DIR.", "DIR"); getopt.add_option( "tempdir", tempdir, GetOpt::REQUIRED_ARG).set_help("Store temporary files in DIR.", "DIR"); - usagemsg = getopt.generate_usage(argv[0])+" [ ...]"; - helpmsg = getopt.generate_help(); + getopt.add_argument("target", cmdline_targets, GetOpt::OPTIONAL_ARG).set_help("Target(s) to build"); getopt(argc, argv); + if(help) + { + helpmsg = "Usage:\n "; + helpmsg += getopt.generate_usage(argv[0], true); + helpmsg += "\n\n"; + helpmsg += getopt.generate_help(); + } + if(silent) --verbose; if(verbose>=1) @@ -114,14 +123,16 @@ BuilderCLI::BuilderCLI(int argc, char **argv): else if(!clean && !create_makefile) build = true; - const vector &args = getopt.get_args(); - for(vector::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()) @@ -133,7 +144,7 @@ BuilderCLI::BuilderCLI(int argc, char **argv): package_manager.append_package_path(cwd); package_manager.append_package_path(cwd/".."); - package_manager.append_binary_package_path(FS::get_sys_data_dir(argv[0], "builder")); + package_manager.append_binary_package_path(FS::get_sys_data_dir(argv[0], "builder")/"packages"); package_manager.set_no_externals(no_externals); @@ -156,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() @@ -166,26 +189,20 @@ BuilderCLI::~BuilderCLI() int BuilderCLI::main() { FS::Path main_file = cwd/build_file; - if(!FS::exists(main_file)) + if(FS::exists(main_file)) + builder.load_build_file(main_file, &cmdline_options, conf_all); + else if(!help) { - if(help) - { - usage(0, "builder", false); - return 0; - } - else - { - IO::print(IO::cerr, "The file %s does not exist.\n", main_file); - return 1; - } + IO::print(IO::cerr, "The file %s does not exist.\n", main_file); + return 1; } - builder.load_build_file(main_file, &cmdline_options, conf_all); - if(help) { - usage(0, "builder", false); - IO::print("\n"); + IO::print("Builder 1.0\n" + "Copyright © 2006-2013 Mikkosoft Productions, Mikko Rasa\n" + "Licensed under the GPL\n\n" + "%s", helpmsg); package_help(); return 0; } @@ -252,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 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::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; @@ -278,18 +295,13 @@ bool BuilderCLI::prepare_build() during preparation. */ BuildGraph &build_graph = builder.get_build_graph(); PackageManager &package_manager = builder.get_package_manager(); - VirtualFileSystem &vfs = builder.get_vfs(); package_manager.get_main_package().prepare(); // Add targets from command line as goals for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i) { - Target *tgt = build_graph.get_target(*i); - if(!tgt) - tgt = vfs.get_target(*i); - if(!tgt) - tgt = vfs.get_target(cwd/ *i); + Target *tgt = resolve_target(*i); if(!tgt) { IO::print("I don't know anything about %s\n", *i); @@ -304,7 +316,7 @@ bool BuilderCLI::prepare_build() // Apply what-ifs for(NameList::iterator i=what_if.begin(); i!=what_if.end(); ++i) { - FileTarget *tgt = vfs.get_target(cwd/ *i); + FileTarget *tgt = dynamic_cast(resolve_target(*i)); if(!tgt) { IO::print(IO::cerr, "Unknown what-if target %s\n", *i); @@ -317,39 +329,30 @@ 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; } -void BuilderCLI::usage(const char *reason, const char *argv0, bool brief) +Target *BuilderCLI::resolve_target(const string &name) { - if(reason) - IO::print(IO::cerr, "%s\n", reason); - - if(brief) - IO::print(IO::cerr, "Usage: %s\n", usagemsg); - else - { - IO::print(IO::cerr, "Builder 1.0\n\n"); - IO::print(IO::cerr, "Usage: %s [options] [ ...]\n\n", argv0); - IO::print(IO::cerr, "Options:\n"); - IO::print(IO::cerr, helpmsg); - } + Target *tgt = builder.get_build_graph().get_target(name); + if(!tgt) + tgt = builder.get_vfs().get_target(cwd/name); + return tgt; } void BuilderCLI::package_help() { PackageManager &package_manager = builder.get_package_manager(); + if(package_manager.get_packages().empty()) + return; + SourcePackage &main_pkg = dynamic_cast(package_manager.get_main_package()); const Config &config = main_pkg.get_config(); const Config::OptionMap &options = config.get_options(); - IO::print("Required packages:\n "); + IO::print("\nRequired packages:\n "); const Package::Requirements &requires = main_pkg.get_required_packages(); for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i) { @@ -357,16 +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::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); + } } } - -string BuilderCLI::usagemsg; -string BuilderCLI::helpmsg;