diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-01-04 16:04:39 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-01-04 16:04:39 +0200 |
commit | 759e714238438cccf74f035e1ba11c925b27cd55 (patch) | |
tree | 36683f9df793d0100f49189dad9cabf09be78d89 | |
parent | b1ef30736694f644e2e473429257a18b64a7615c (diff) |
Load config.build in init(), not boot()
We now make sure the config module is init'ed first.
-rw-r--r-- | build2/config/init.cxx | 73 | ||||
-rw-r--r-- | build2/config/init.hxx | 2 | ||||
-rw-r--r-- | build2/dist/init.cxx | 4 | ||||
-rw-r--r-- | build2/dist/init.hxx | 2 | ||||
-rw-r--r-- | build2/file.cxx | 16 | ||||
-rw-r--r-- | build2/install/init.cxx | 4 | ||||
-rw-r--r-- | build2/install/init.hxx | 2 | ||||
-rw-r--r-- | build2/module.cxx | 8 | ||||
-rw-r--r-- | build2/module.hxx | 8 | ||||
-rw-r--r-- | build2/test/init.cxx | 4 | ||||
-rw-r--r-- | build2/test/init.hxx | 2 | ||||
-rw-r--r-- | build2/version/init.cxx | 4 | ||||
-rw-r--r-- | build2/version/init.hxx | 2 |
13 files changed, 69 insertions, 62 deletions
diff --git a/build2/config/init.cxx b/build2/config/init.cxx index 7285671..2552e77 100644 --- a/build2/config/init.cxx +++ b/build2/config/init.cxx @@ -22,13 +22,12 @@ namespace build2 { namespace config { - void - boot (scope& rs, const location& loc, unique_ptr<module_base>& mod) + bool + boot (scope& rs, const location&, unique_ptr<module_base>& mod) { tracer trace ("config::boot"); - const dir_path& out_root (rs.out_path ()); - l5 ([&]{trace << "for " << out_root;}); + l5 ([&]{trace << "for " << rs.out_path ();}); const string& mname (*current_mname); const string& oname (*current_oname); @@ -56,26 +55,38 @@ namespace build2 rs.meta_operations.insert (configure_id, mo_configure); rs.meta_operations.insert (disfigure_id, mo_disfigure); - auto& vp (var_pool.rw (rs)); + return true; // Initialize first (load config.build). + } - // utility.cxx:unconfigured() (note: not overridable). - // - vp.insert_pattern<bool> ( - "config.*.configured", false, variable_visibility::normal); + bool + init (scope& rs, + scope&, + const location& l, + unique_ptr<module_base>&, + bool first, + bool, + const variable_map& config_hints) + { + tracer trace ("config::init"); - // Load config.build if one exists. - // - // Note that we have to do this during bootstrap since the order in - // which the modules will be initialized is unspecified. So it is - // possible that some module which needs the configuration will get - // called first. + if (!first) + { + warn (l) << "multiple config module initializations"; + return true; + } + + const dir_path& out_root (rs.out_path ()); + l5 ([&]{trace << "for " << out_root;}); + + assert (config_hints.empty ()); // We don't known any hints. + + auto& vp (var_pool.rw (rs)); + + // Load config.build if one exists (we don't need to worry about + // disfigure since we will never be init'ed). // const variable& c_v (vp.insert<uint64_t> ("config.version", false)); - // Don't load it if we are disfiguring. The same situation as with - // module loading above. - // - if (mname != "disfigure" && (!mname.empty () || oname != "disfigure")) { path f (out_root / config_file); @@ -96,7 +107,7 @@ namespace build2 uint64_t v (p.second ? cast<uint64_t> (p.first) : 0); if (v != module::version) - fail (loc) << "incompatible config file " << f << + fail (l) << "incompatible config file " << f << info << "config file version " << v << (p.second ? "" : " (missing)") << info << "config module version " << module::version << @@ -107,28 +118,6 @@ namespace build2 source (rs, rs, f); } } - } - - bool - init (scope& rs, - scope&, - const location& l, - unique_ptr<module_base>&, - bool first, - bool, - const variable_map& config_hints) - { - tracer trace ("config::init"); - - if (!first) - { - warn (l) << "multiple config module initializations"; - return true; - } - - l5 ([&]{trace << "for " << rs.out_path ();}); - - assert (config_hints.empty ()); // We don't known any hints. // Register alias and fallback rule for the configure meta-operation. // diff --git a/build2/config/init.hxx b/build2/config/init.hxx index 45c288b..a79ef02 100644 --- a/build2/config/init.hxx +++ b/build2/config/init.hxx @@ -14,7 +14,7 @@ namespace build2 { namespace config { - void + bool boot (scope&, const location&, unique_ptr<module_base>&); bool diff --git a/build2/dist/init.cxx b/build2/dist/init.cxx index 33ddcd7..818570a 100644 --- a/build2/dist/init.cxx +++ b/build2/dist/init.cxx @@ -23,7 +23,7 @@ namespace build2 { static const rule rule_; - void + bool boot (scope& rs, const location&, unique_ptr<module_base>& mod) { tracer trace ("dist::boot"); @@ -64,6 +64,8 @@ namespace build2 // Create the module. // mod.reset (new module (v_d_p)); + + return false; } bool diff --git a/build2/dist/init.hxx b/build2/dist/init.hxx index 45d47df..f1d2bc5 100644 --- a/build2/dist/init.hxx +++ b/build2/dist/init.hxx @@ -14,7 +14,7 @@ namespace build2 { namespace dist { - void + bool boot (scope&, const location&, unique_ptr<module_base>&); bool diff --git a/build2/file.cxx b/build2/file.cxx index edd3e28..e18ae5e 100644 --- a/build2/file.cxx +++ b/build2/file.cxx @@ -879,14 +879,18 @@ namespace build2 // for (auto& p: root.modules) { - const string& n (p.first); module_state& s (p.second); - if (s.boot) - { - load_module (root, root, n, s.loc); - assert (!s.boot); - } + if (s.boot && s.first) + load_module (root, root, p.first, s.loc); + } + + for (auto& p: root.modules) + { + module_state& s (p.second); + + if (s.boot && !s.first) + load_module (root, root, p.first, s.loc); } // Load root.build. diff --git a/build2/install/init.cxx b/build2/install/init.cxx index 3e4e1ff..0eb9521 100644 --- a/build2/install/init.cxx +++ b/build2/install/init.cxx @@ -128,7 +128,7 @@ namespace build2 void functions (); // functions.cxx - void + bool boot (scope& r, const location&, unique_ptr<module_base>&) { tracer trace ("install::boot"); @@ -144,6 +144,8 @@ namespace build2 // r.operations.insert (install_id, op_install); r.operations.insert (uninstall_id, op_uninstall); + + return false; } static const path cmd ("install"); diff --git a/build2/install/init.hxx b/build2/install/init.hxx index 98b4205..6239916 100644 --- a/build2/install/init.hxx +++ b/build2/install/init.hxx @@ -14,7 +14,7 @@ namespace build2 { namespace install { - void + bool boot (scope&, const location&, unique_ptr<module_base>&); bool diff --git a/build2/module.cxx b/build2/module.cxx index 7a35008..9994c9b 100644 --- a/build2/module.cxx +++ b/build2/module.cxx @@ -45,8 +45,9 @@ namespace build2 if (mf.boot == nullptr) fail (loc) << "module " << name << " shouldn't be loaded in bootstrap"; - i = lm.emplace (name, module_state {true, mf.init, nullptr, loc}).first; - mf.boot (rs, loc, i->second.module); + i = lm.emplace (name, + module_state {true, false, mf.init, nullptr, loc}).first; + i->second.first = mf.boot (rs, loc, i->second.module); } bool @@ -82,7 +83,8 @@ namespace build2 fail (loc) << "module " << name << " should be loaded in bootstrap"; i = lm.emplace ( - name, module_state {false, mf.init, nullptr, loc}).first; + name, + module_state {false, false, mf.init, nullptr, loc}).first; } } else diff --git a/build2/module.hxx b/build2/module.hxx index e3ab94f..fbaebd7 100644 --- a/build2/module.hxx +++ b/build2/module.hxx @@ -25,8 +25,11 @@ namespace build2 ~module_base () = default; }; + // Return true if the module should be initialized first (the order of + // initialization within each group is unspecified). + // using module_boot_function = - void (scope& root, + bool (scope& root, const location&, unique_ptr<module_base>&); @@ -62,7 +65,8 @@ namespace build2 // struct module_state { - bool boot; // True if the module boot'ed but not yet init'ed. + bool boot; // True if the module boot'ed but not yet init'ed. + bool first; // True if the boot'ed module must be init'ed first. module_init_function* init; unique_ptr<module_base> module; const location loc; // Boot location. diff --git a/build2/test/init.cxx b/build2/test/init.cxx index 1c7a2b4..6119ae0 100644 --- a/build2/test/init.cxx +++ b/build2/test/init.cxx @@ -22,7 +22,7 @@ namespace build2 { namespace test { - void + bool boot (scope& rs, const location&, unique_ptr<module_base>&) { tracer trace ("test::boot"); @@ -84,6 +84,8 @@ namespace build2 if (!v || v.empty ()) v = cast<target_triplet> ((*global_scope)["build.host"]); } + + return false; } bool diff --git a/build2/test/init.hxx b/build2/test/init.hxx index 2ba6ec6..8ca0d23 100644 --- a/build2/test/init.hxx +++ b/build2/test/init.hxx @@ -14,7 +14,7 @@ namespace build2 { namespace test { - void + bool boot (scope&, const location&, unique_ptr<module_base>&); bool diff --git a/build2/version/init.cxx b/build2/version/init.cxx index 69d7401..63e32ab 100644 --- a/build2/version/init.cxx +++ b/build2/version/init.cxx @@ -30,7 +30,7 @@ namespace build2 static const version_doc version_doc_; static const version_in version_in_; - void + bool boot (scope& rs, const location& l, unique_ptr<module_base>& mod) { tracer trace ("version::boot"); @@ -225,6 +225,8 @@ namespace build2 // Create the module. // mod.reset (new module (move (v), move (ds))); + + return true; // Init first (dist.package, etc). } static void diff --git a/build2/version/init.hxx b/build2/version/init.hxx index 54beae1..425e282 100644 --- a/build2/version/init.hxx +++ b/build2/version/init.hxx @@ -14,7 +14,7 @@ namespace build2 { namespace version { - void + bool boot (scope&, const location&, unique_ptr<module_base>&); bool |