From: Mikko Rasa Date: Tue, 30 Apr 2013 12:19:45 +0000 (+0300) Subject: Pass the option map through load_build_file and to Loader X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a876c04c49ba89497be5d2e80d6e97543dba4f07;p=builder.git Pass the option map through load_build_file and to Loader This allows passing in options from outside Builder, which is necessary for a planned split of the CLI part into its own class. --- diff --git a/source/builder.cpp b/source/builder.cpp index 07007f6..ea96534 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -52,7 +52,8 @@ Builder::Builder(int argc, char **argv): conf_only(false), build_all(false), create_makefile(false), - tempdir("temp") + tempdir("temp"), + top_loader(0) { string analyze_mode; string work_dir; @@ -229,7 +230,7 @@ int Builder::main() } } - load_build_file(main_file); + load_build_file(main_file, &cmdline_options, conf_all); if(help) { @@ -335,14 +336,14 @@ void Builder::usage(const char *reason, const char *argv0, bool brief) } } -void Builder::load_build_file(const FS::Path &fn) +void Builder::load_build_file(const FS::Path &fn, const Config::InputOptions *opts, bool all) { IO::BufferedFile in(fn.str()); logger.log("files", format("Reading %s", fn)); DataFile::Parser parser(in, fn.str()); - Loader loader(*this); + Loader loader(*this, opts, all); loader.load(parser); } @@ -552,14 +553,27 @@ string Builder::usagemsg; string Builder::helpmsg; -Builder::Loader::Loader(Builder &b): - DataFile::ObjectLoader(b) +Builder::Loader::Loader(Builder &b, const Config::InputOptions *o, bool a): + DataFile::ObjectLoader(b), + options(o), + conf_all(a) { add("architecture", &Loader::architecture); add("binary_package", &Loader::binpkg); add("build_type", &Loader::build_type); add("profile", &Loader::profile); add("package", &Loader::package); + + if(!obj.top_loader) + obj.top_loader = this; + else if(!options && obj.top_loader!=this && obj.top_loader->conf_all) + options = obj.top_loader->options; +} + +Builder::Loader::~Loader() +{ + if(obj.top_loader==this) + obj.top_loader = 0; } void Builder::Loader::architecture(const string &n) @@ -592,8 +606,8 @@ void Builder::Loader::package(const string &n) { SourcePackage *pkg = new SourcePackage(obj, n, get_source()); - if(obj.conf_all || pkg==&obj.package_manager.get_main_package()) - load_sub(*pkg, obj.cmdline_options); + if(options) + load_sub(*pkg, *options); else load_sub(*pkg); diff --git a/source/builder.h b/source/builder.h index 66194a2..3d70968 100644 --- a/source/builder.h +++ b/source/builder.h @@ -32,8 +32,14 @@ class Builder: public Msp::RegisteredApplication private: class Loader: public Msp::DataFile::ObjectLoader { + private: + const Config::InputOptions *options; + bool conf_all; + public: - Loader(Builder &); + Loader(Builder &, const Config::InputOptions * = 0, bool = false); + ~Loader(); + private: void architecture(const std::string &); void binpkg(const std::string &); @@ -79,6 +85,8 @@ private: Msp::FS::Path prefix; Msp::FS::Path tempdir; + Loader *top_loader; + static std::string usagemsg; static std::string helpmsg; @@ -104,9 +112,10 @@ public: static void usage(const char *, const char *, bool); - /** Loads a build file. Returns 0 on success or -1 if the file could not be - opened. */ - void load_build_file(const Msp::FS::Path &); + /** Loads a build file. If opts is not null, it is used to configure any + packages loaded from this file. If all is true, external packages are also + configured. */ + void load_build_file(const Msp::FS::Path &, const Config::InputOptions *opts = 0, bool all = false); private: /** Prepares packages and targets for building. Returns true if everything