From: Mikko Rasa Date: Thu, 7 May 2009 06:08:09 +0000 (+0000) Subject: Use mspio for all I/O operations X-Git-Tag: 1.0~15 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5622fc20f0be8bff0938d24f6f45d3ab384288ca;p=builder.git Use mspio for all I/O operations Use GetOpt to generate help messages for options Make --help work even if there's no package in cwd --- diff --git a/source/action.cpp b/source/action.cpp index 31b1390..72c14a7 100644 --- a/source/action.cpp +++ b/source/action.cpp @@ -5,19 +5,13 @@ Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include -#include -#include +#include #include "action.h" +using namespace Msp; using namespace std; void Action::announce(const string &pkg, const string &tool, const string &tgt) { - ostringstream line; - line< -#include -#include #include +#include #include "analyzer.h" #include "builder.h" #include "install.h" @@ -108,15 +106,14 @@ void Analyzer::print_table() const for(Table::const_iterator i=table.begin(); i!=table.end(); ++i) { - ostringstream ss; - ss<size(); ++j) { if(j>0) - ss<<" "; - ss< +#include #include #include "binarypackage.h" #include "builder.h" @@ -45,7 +45,7 @@ BinaryPackage *BinaryPackage::from_pkgconfig(Builder &builder, const string &nam argv.push_back("--libs"); argv.push_back(name); if(builder.get_verbose()>=4) - cout<<"Running "< #include #include #include @@ -17,6 +16,7 @@ Distributed under the LGPL #include #include #include +#include #include #include #include @@ -77,26 +77,27 @@ Builder::Builder(int argc, char **argv): 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])+" [ ...]"; + helpmsg=getopt.generate_help(); getopt(argc, argv); if(!analyze_mode.empty()) @@ -196,8 +197,16 @@ int Builder::main() { 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); @@ -205,7 +214,7 @@ int Builder::main() if(help) { usage(0, "builder", false); - cout<<'\n'; + IO::print("\n"); package_help(); return 0; } @@ -219,16 +228,16 @@ int Builder::main() return 0; if(verbose>=2) - cout<<"Building on "<get_name()<<", for "<get_name()<<'\n'; + IO::print("Building on %s, for %s\n", native_arch->get_name(), current_arch->get_name()); if(verbose>=1) - cout<=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(*i)) - cout<<'*'; + IO::print("*"); unsigned count=0; unsigned ood_count=0; for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j) @@ -240,12 +249,12 @@ int Builder::main() } if(count) { - cout<<" ("<package<<": "<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; } @@ -335,12 +344,12 @@ Target *Builder::get_header(const string &include, const FS::Path &from, const l cxx_ver.erase(dot); } if(verbose>=5) - cout<<"C++ version is "<=5) - cout<<"Looking for include "<is_native()) @@ -383,7 +392,7 @@ Target *Builder::get_library(const string &lib, const list &path, LibMod syspath.push_back("/usr/"+current_arch->get_prefix()+"/lib"); if(verbose>=5) - cout<<"Looking for library "< ...]\n"; + IO::print(IO::cerr, "Usage: %s\n", usagemsg); else { - cerr<< - "Usage: "< ...]\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] [ ...]\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 "< argv; @@ -477,7 +465,7 @@ FS::Path Builder::get_package_location(const string &name) argv.push_back("--variable=source"); argv.push_back(name); if(verbose>=4) - cout<<"Running "<=3) - cout<=3) - cout<<"Reading "<touch(); @@ -599,7 +587,7 @@ int Builder::create_targets() 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) @@ -697,11 +685,11 @@ int Builder::do_build() 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 "< actions; @@ -722,10 +710,7 @@ int Builder::do_build() actions.push_back(action); if(show_progress) - { - cout<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<<" "< Builder::reg; +string Builder::usagemsg; +string Builder::helpmsg; Builder::Loader::Loader(Builder &b, const FS::Path &s): diff --git a/source/builder.h b/source/builder.h index 0ebf2df..81f5f13 100644 --- a/source/builder.h +++ b/source/builder.h @@ -99,6 +99,8 @@ private: StringList warnings; static Msp::Application::RegApp reg; + static std::string usagemsg; + static std::string helpmsg; public: Builder(int, char **); diff --git a/source/component.cpp b/source/component.cpp index 338b44f..6bef636 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -5,11 +5,11 @@ Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include #include #include #include #include +#include #include #include "builder.h" #include "component.h" @@ -230,7 +230,7 @@ void Component::Loader::host(const string &n) void Component::Loader::install_headers(const string &p) { - cout< -#include #include #include #include #include +#include #include "builder.h" #include "copy.h" #include "package.h" @@ -25,7 +25,7 @@ Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d) { announce(pkg.get_name(), "COPY", dest[-1]); if(builder.get_verbose()>=2) - cout< "< %s\n", s, d); if(!builder.get_dry_run()) worker=new Worker(*this); @@ -51,7 +51,7 @@ void Copy::Worker::main() { if(e.get_error_code()!=ENOENT) { - cerr< -#include #include #include +#include #include +#include +#include #include "builder.h" #include "externalaction.h" @@ -19,15 +20,7 @@ using namespace Msp; void ExternalAction::launch() { if(builder.get_verbose()>=2) - { - for(StringList::const_iterator i=argv.begin(); i!=argv.end(); ++i) - { - if(i!=argv.begin()) - cout<<' '; - cout<<*i; - } - cout<<'\n'; - } + IO::print("%s\n", join(argv.begin(), argv.end())); if(builder.get_dry_run()) pid=-1; @@ -46,7 +39,7 @@ void ExternalAction::launch() if(!work_dir.empty()) FS::chdir(work_dir); execvp(argv_[0], argv_); - cout<<"Couldn't execute "< #include #include #include #include +#include #include "misc.h" using namespace std; @@ -43,7 +43,7 @@ string run_command(const StringList &argv) ::exit(1); } else if(pid==-1) - cerr<<"Failed to execute "< #include #include #include "builder.h" @@ -14,8 +15,6 @@ Distributed under the LGPL using namespace std; using namespace Msp; -#include - Package::Package(Builder &b, const string &n): builder(b), name(n), @@ -45,7 +44,7 @@ void Package::configure(const StringMap &opts, unsigned flag) return; if(builder.get_verbose()>=3) - cout<<"Configuring "< #include #include #include diff --git a/source/sourcefile.cpp b/source/sourcefile.cpp index a5cacce..0fc6d69 100644 --- a/source/sourcefile.cpp +++ b/source/sourcefile.cpp @@ -5,9 +5,9 @@ Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include #include #include +#include #include #include "builder.h" #include "component.h" @@ -49,7 +49,7 @@ void SourceFile::find_depends() IO::BufferedFile in(name); if(builder.get_verbose()>=4) - cout<<"Reading includes from "<]"); diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 432575f..3f38acf 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -5,7 +5,7 @@ Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include +#include #include #include #include "binarypackage.h" @@ -82,7 +82,7 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag) if(flag && config.update(opts)) { if(builder.get_verbose()>=2) - cout<<"Configuration of "< #include #include #include #include +#include #include "builder.h" #include "sourcepackage.h" #include "tar.h" @@ -25,7 +25,7 @@ Tar::Tar(Builder &b, const TarBall &t): string basename=FS::basename(tarball.get_path()); announce(tarball.get_package()->get_name(), "TAR ", basename); if(builder.get_verbose()>=2) - cout<<"Create "<get_path(), pkg_src)).str(); if(rel_path.size()>99) { - cout<<"Can't store "<