Distributed under the LGPL
*/
-#include <iostream>
#include <set>
#include <sys/utsname.h>
#include <msp/core/except.h>
#include <msp/io/buffered.h>
#include <msp/io/except.h>
#include <msp/io/file.h>
+#include <msp/io/print.h>
#include <msp/strings/formatter.h>
#include <msp/strings/regex.h>
#include <msp/strings/utils.h>
string arch;
GetOpt getopt;
- getopt.add_option('a', "analyze", analyze_mode, GetOpt::REQUIRED_ARG);
- getopt.add_option('b', "build", build, GetOpt::NO_ARG);
- getopt.add_option('c', "clean", clean, GetOpt::NO_ARG);
- getopt.add_option('f', "file", build_file, GetOpt::REQUIRED_ARG);
- getopt.add_option('h', "help", help, GetOpt::NO_ARG);
- getopt.add_option('j', "jobs", jobs, GetOpt::REQUIRED_ARG);
- getopt.add_option('n', "dry-run", dry_run, GetOpt::NO_ARG);
- getopt.add_option('v', "verbose", verbose, GetOpt::NO_ARG);
- getopt.add_option('A', "conf-all", conf_all, GetOpt::NO_ARG);
- getopt.add_option('B', "build-all", build_all, GetOpt::NO_ARG);
- getopt.add_option('C', "chdir", work_dir, GetOpt::REQUIRED_ARG);
- getopt.add_option('P', "progress", show_progress, GetOpt::NO_ARG);
- getopt.add_option('W', "what-if", what_if, GetOpt::REQUIRED_ARG);
- getopt.add_option( "arch", arch, GetOpt::REQUIRED_ARG);
- getopt.add_option( "conf-only", conf_only, GetOpt::NO_ARG);
- getopt.add_option( "full-paths", full_paths, GetOpt::NO_ARG);
- //getopt.add_option( "makefile", create_makefile, GetOpt::NO_ARG);
- getopt.add_option( "max-depth", max_depth, GetOpt::REQUIRED_ARG);
- getopt.add_option( "prefix", prfx, GetOpt::REQUIRED_ARG);
- getopt.add_option( "warnings", cmdline_warn, GetOpt::REQUIRED_ARG);
+ getopt.add_option('a', "analyze", analyze_mode, GetOpt::REQUIRED_ARG).set_help("Perform analysis. MODE can be deps, alldeps or rebuild.", "MODE");
+ getopt.add_option('b', "build", build, GetOpt::NO_ARG).set_help("Perform build even if doing analysis.");
+ getopt.add_option('c', "clean", clean, GetOpt::NO_ARG).set_help("Clean buildable targets.");
+ getopt.add_option('f', "file", build_file, GetOpt::REQUIRED_ARG).set_help("Read info from FILE instead of Build.", "FILE");
+ getopt.add_option('h', "help", help, GetOpt::NO_ARG).set_help("Print this message.");
+ getopt.add_option('j', "jobs", jobs, GetOpt::REQUIRED_ARG).set_help("Run NUM commands at once, whenever possible.", "NUM");
+ getopt.add_option('n', "dry-run", dry_run, GetOpt::NO_ARG).set_help("Don't actually do anything, only show what would be done.");
+ getopt.add_option('v', "verbose", verbose, GetOpt::NO_ARG).set_help("Print more information about what's going on.");
+ getopt.add_option('A', "conf-all", conf_all, GetOpt::NO_ARG).set_help("Apply configuration to all packages.");
+ getopt.add_option('B', "build-all", build_all, GetOpt::NO_ARG).set_help("Build all targets unconditionally.");
+ getopt.add_option('C', "chdir", work_dir, GetOpt::REQUIRED_ARG).set_help("Change to DIR before doing anything else.", "DIR");
+ getopt.add_option('P', "progress", show_progress, GetOpt::NO_ARG).set_help("Display progress while building.");
+ getopt.add_option('W', "what-if", what_if, GetOpt::REQUIRED_ARG).set_help("Pretend that FILE has changed.", "FILE");
+ getopt.add_option( "arch", arch, GetOpt::REQUIRED_ARG).set_help("Architecture to build for.", "ARCH");
+ getopt.add_option( "conf-only", conf_only, GetOpt::NO_ARG).set_help("Stop after configuring packages.");
+ getopt.add_option( "full-paths", full_paths, GetOpt::NO_ARG).set_help("Output full paths in analysis.");
+ getopt.add_option( "max-depth", max_depth, GetOpt::REQUIRED_ARG).set_help("Maximum depth to show in analysis.", "NUM");
+ getopt.add_option( "prefix", prfx, GetOpt::REQUIRED_ARG).set_help("Directory to install things to.", "DIR");
+ getopt.add_option( "warnings", cmdline_warn, GetOpt::REQUIRED_ARG).set_help("Compiler warnings to use.", "LIST");
+ usagemsg=getopt.generate_usage(argv[0])+" [<target> ...]";
+ helpmsg=getopt.generate_help();
getopt(argc, argv);
if(!analyze_mode.empty())
{
if(load_build_file(cwd/build_file))
{
- cerr<<"No build info here.\n";
- return 1;
+ if(help)
+ {
+ usage(0, "builder", false);
+ return 0;
+ }
+ else
+ {
+ IO::print(IO::cerr, "No build info here.\n");
+ return 1;
+ }
}
main_pkg->configure(cmdline_options, conf_all?2:1);
if(help)
{
usage(0, "builder", false);
- cout<<'\n';
+ IO::print("\n");
package_help();
return 0;
}
return 0;
if(verbose>=2)
- cout<<"Building on "<<native_arch->get_name()<<", for "<<current_arch->get_name()<<'\n';
+ IO::print("Building on %s, for %s\n", native_arch->get_name(), current_arch->get_name());
if(verbose>=1)
- cout<<all_reqs.size()<<" active packages, "<<targets.size()<<" targets\n";
+ IO::print("%d active packages, %d targets\n", all_reqs.size(), targets.size());
if(verbose>=2)
{
for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
{
- cout<<' '<<(*i)->get_name();
+ IO::print(" %s", (*i)->get_name());
if(dynamic_cast<SourcePackage *>(*i))
- cout<<'*';
+ IO::print("*");
unsigned count=0;
unsigned ood_count=0;
for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
}
if(count)
{
- cout<<" ("<<count<<" targets";
+ IO::print(" (%d targets", count);
if(ood_count)
- cout<<", "<<ood_count<<" out-of-date";
- cout<<')';
+ IO::print(", %d out-of-date", ood_count);
+ IO::print(")");
}
- cout<<'\n';
+ IO::print("\n");
}
}
if(!problems.empty())
{
- cerr<<"The following problems were detected:\n";
+ IO::print(IO::cerr, "The following problems were detected:\n");
for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i)
- cerr<<" "<<i->package<<": "<<i->descr<<'\n';
- cerr<<"Please fix them and try again.\n";
+ IO::print(IO::cerr, " %s: %s\n", i->package, i->descr);
+ IO::print(IO::cerr, "Please fix them and try again.\n");
return 1;
}
cxx_ver.erase(dot);
}
if(verbose>=5)
- cout<<"C++ version is "<<cxx_ver<<'\n';
+ IO::print("C++ version is %s\n", cxx_ver);
}
string fn=include.substr(1);
if(verbose>=5)
- cout<<"Looking for include "<<fn<<" from "<<from<<" with path "<<join(path.begin(), path.end())<<'\n';
+ IO::print("Looking for include %s from %s with path %s\n", fn, from, join(path.begin(), path.end()));
StringList syspath;
if(current_arch->is_native())
syspath.push_back("/usr/"+current_arch->get_prefix()+"/lib");
if(verbose>=5)
- cout<<"Looking for library "<<lib<<" with path "<<join(path.begin(), path.end())<<'\n';
+ IO::print("Looking for library %s with path %s\n", lib, join(path.begin(), path.end()));
Target *tgt=0;
for(StringList::const_iterator j=path.begin(); (!tgt && j!=path.end()); ++j)
void Builder::usage(const char *reason, const char *argv0, bool brief)
{
if(reason)
- cerr<<reason<<'\n';
+ IO::print(IO::cerr, "%s\n", reason);
if(brief)
- cerr<<"Usage: "<<argv0<<" [-a|--analyze MODE] [-b|--build] [-c|--clean] [-f|--file FILE] [-h|--help] [-j|--jobs NUM] [-n||--dry-run] [-v|--verbose] [-A|--conf-all] [-B|--build-all] [-C|--chdir DIRECTORY] [-W|--what-if FILE] [--chrome] [--conf-only] [--full-paths] [--max-depth NUM] [<target> ...]\n";
+ IO::print(IO::cerr, "Usage: %s\n", usagemsg);
else
{
- cerr<<
- "Usage: "<<argv0<<" [options] [<target> ...]\n"
- "\n"
- "Options:\n"
- " -a, --analyze MODE Perform analysis. MODE can be deps, alldeps or rebuild.\n"
- " -b, --build Perform build even if doing analysis.\n"
- " -c, --clean Clean buildable targets.\n"
- " -f, --file FILE Read info from FILE instead of Build.\n"
- " -h, --help Print this message.\n"
- " -j, --jobs NUM Run NUM commands at once, whenever possible.\n"
- " -n, --dry-run Don't actually do anything, only show what would be done.\n"
- " -v, --verbose Print more information about what's going on.\n"
- " -A, --conf-all Apply configuration to all packages.\n"
- " -B, --build-all Build all targets unconditionally.\n"
- " -C, --chdir DIR Change to DIR before doing anything else.\n"
- " -P, --progress Display progress while building.\n"
- " -W, --what-if FILE Pretend that FILE has changed.\n"
- " --arch ARCH Architecture to build for.\n"
- " --conf-only Stop after configuring packages.\n"
- " --full-paths Output full paths in analysis.\n"
- //" --makefile Create a makefile for this package.\n"
- " --max-depth NUM Maximum depth to show in analysis.\n"
- " --prefix DIR Directory to install things to.\n"
- " --warnings LIST Compiler warnings to use.\n";
+ IO::print(IO::cerr, "Usage: %s [options] [<target> ...]\n\n", argv0);
+ IO::print(IO::cerr, "Options:\n");
+ IO::print(IO::cerr, helpmsg);
}
}
FS::Path Builder::get_package_location(const string &name)
{
if(verbose>=3)
- cout<<"Looking for package "<<name<<'\n';
+ IO::print("Looking for package %s\n", name);
// Try to get source directory with pkgconfig
list<string> argv;
argv.push_back("--variable=source");
argv.push_back(name);
if(verbose>=4)
- cout<<"Running "<<join(argv.begin(), argv.end())<<'\n';
+ IO::print("Running %s\n", join(argv.begin(), argv.end()));
string srcdir=strip(run_command(argv));
if(!srcdir.empty())
return srcdir;
}
}
if(verbose>=3)
- cout<<pkg_dirs.size()<<" packages found in path\n";
+ IO::print("%d packages found in path\n", pkg_dirs.size());
}
bool msp=!name.compare(0, 3, "msp");
IO::BufferedFile in(fn.str());
if(verbose>=3)
- cout<<"Reading "<<fn<<'\n';
+ IO::print("Reading %s\n", fn);
DataFile::Parser parser(in, fn.str());
Loader loader(*this, fn.subpath(0, fn.size()-1));
Target *tgt=get_target((cwd/ *i).str());
if(!tgt)
{
- cerr<<"Unknown what-if target "<<*i<<'\n';
+ IO::print(IO::cerr, "Unknown what-if target %s\n", *i);
return -1;
}
tgt->touch();
tgt=get_target((cwd/ *i).str());
if(!tgt)
{
- cerr<<"I don't know anything about "<<*i<<'\n';
+ IO::print("I don't know anything about %s\n", *i);
return -1;
}
if(tgt==world)
unsigned total=cmdline->count_rebuild();
if(!total)
{
- cout<<"Already up to date\n";
+ IO::print("Already up to date\n");
return 0;
}
if(verbose>=1)
- cout<<"Will build "<<total<<" target(s)\n";
+ IO::print("Will build %d target%s\n", total, (total!=1 ? "s" : ""));
vector<Action *> actions;
actions.push_back(action);
if(show_progress)
- {
- cout<<count<<" of "<<total<<" targets built\033[1G";
- cout.flush();
- }
+ IO::print("%d of %d target%s built\033[1G", count, total, (total!=1 ? "s" : ""));
}
else if(actions.empty())
finish=true;
}
if(show_progress)
- cout<<"\033[K";
+ IO::print("\033[K");
if(fail)
- cout<<"Build failed\n";
+ IO::print("Build failed\n");
else if(show_progress)
- cout<<"Build complete\n";
+ IO::print("Build complete\n");
- return fail?1:0;
+ return fail;
}
int Builder::do_clean()
const Config &config=main_pkg->get_config();
const Config::OptionMap &options=config.get_options();
- cout<<"Required packages:\n ";
+ IO::print("Required packages:\n ");
const PackageList &requires=main_pkg->get_requires();
for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i)
{
if(i!=requires.begin())
- cout<<", ";
- cout<<(*i)->get_name();
+ IO::print(", ");
+ IO::print((*i)->get_name());
}
- cout<<"\n\n";
- cout<<"Package configuration:\n";
+ IO::print("\n\nPackage configuration:\n");
for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
{
const Config::Option &opt=i->second;
- cout<<" "<<opt.name<<": "<<opt.descr<<" ("<<opt.value<<") ["<<opt.defv<<"]\n";
+ IO::print(" %s: %s (%s)", opt.name, opt.descr, opt.value);
+ if(opt.value!=opt.defv)
+ IO::print(" [%s]", opt.defv);
+ IO::print("\n");
}
}
Application::RegApp<Builder> Builder::reg;
+string Builder::usagemsg;
+string Builder::helpmsg;
Builder::Loader::Loader(Builder &b, const FS::Path &s):