diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-12-01 09:43:29 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-12-01 09:43:29 +0200 |
commit | f355a4379f035df61a7702f5ff805eefb004fb20 (patch) | |
tree | c0c50209492b81f8a88a25c059c39e5fef816a88 | |
parent | cb625e2715b4a7e90120e72b323adcb1264e006a (diff) |
Override outer configuration install paths that contain package name
-rw-r--r-- | build/config/utility | 24 | ||||
-rw-r--r-- | build/config/utility.txx | 14 | ||||
-rw-r--r-- | build/install/module.cxx | 49 |
3 files changed, 55 insertions, 32 deletions
diff --git a/build/config/utility b/build/config/utility index 406c271..9a5dc5e 100644 --- a/build/config/utility +++ b/build/config/utility @@ -21,24 +21,38 @@ namespace build { // Set, if necessary, a required config.* variable. // + // If override is true and the variable doesn't come from this root + // scope or from the command line, then its value is "overridden" + // for this root scope. + // // Return the reference to the value as well as the indication of // whether the variable has actually been set. // template <typename T> std::pair<std::reference_wrapper<const value>, bool> - required (scope& root, const variable&, const T& default_value); + required (scope& root, + const variable&, + const T& default_value, + bool override = false); template <typename T> inline std::pair<std::reference_wrapper<const value>, bool> - required (scope& root, const std::string& name, const T& default_value) + required (scope& root, + const std::string& name, + const T& default_value, + bool override = false) { - return required (root, variable_pool.find (name), default_value); + return required ( + root, variable_pool.find (name), default_value, override); } inline std::pair<std::reference_wrapper<const value>, bool> - required (scope& root, const std::string& name, const char* default_value) + required (scope& root, + const std::string& name, + const char* default_value, + bool override = false) { - return required (root, name, std::string (default_value)); + return required (root, name, std::string (default_value), override); } // Set, if necessary, an optional config.* variable. In particular, diff --git a/build/config/utility.txx b/build/config/utility.txx index 943d308..06cb2eb 100644 --- a/build/config/utility.txx +++ b/build/config/utility.txx @@ -10,18 +10,20 @@ namespace build { template <typename T> std::pair<std::reference_wrapper<const value>, bool> - required (scope& root, const variable& var, const T& def_value) + required (scope& root, const variable& var, const T& def_value, bool ovr) { using result = std::pair<std::reference_wrapper<const value>, bool>; if (auto l = root[var]) { - return l.belongs (*global_scope) - ? result (root.assign (var) = *l, true) - : result (*l, false); + if (l.belongs (*global_scope)) + return result (root.assign (var) = *l, true); + + if (!ovr || l.belongs (root)) + return result (*l, false); } - else - return result (root.assign (var) = def_value, true); + + return result (root.assign (var) = def_value, true); } template <typename T> diff --git a/build/install/module.cxx b/build/install/module.cxx index 042bee9..a0eed61 100644 --- a/build/install/module.cxx +++ b/build/install/module.cxx @@ -29,13 +29,18 @@ namespace build // to set all the install.* values to defaults, as if we had the // default configuration. // + // If override is true, then override values that came from outer + // configurations. We have to do this for paths that contain the + // package name. + // template <typename T> static void set_var (bool spec, scope& r, const char* name, const char* var, - const T* dv) + const T* dv, + bool override = false) { string vn; const value* cv (nullptr); @@ -49,7 +54,7 @@ namespace build variable_pool.find (move (vn), &value_traits<T>::value_type)); cv = dv != nullptr - ? &config::required (r, vr, *dv).first.get () + ? &config::required (r, vr, *dv, override).first.get () : &config::optional (r, vr); } @@ -77,20 +82,22 @@ namespace build set_dir (bool s, scope& r, const char* name, - const dir_path& path, + const string& path, const string& fmode = string (), const string& dmode = string (), - const string& cmd = string ()) + const string& cmd = string (), + bool ovr = false) { - set_var (s, r, name, "", path.empty () ? nullptr : &path); + dir_path dpath (path); + set_var (s, r, name, "", dpath.empty () ? nullptr : &dpath, ovr); set_var (s, r, name, ".mode", fmode.empty () ? nullptr : &fmode); set_var (s, r, name, ".dir_mode", dmode.empty () ? nullptr : &dmode); set_var (s, r, name, ".cmd", cmd.empty () ? nullptr : &cmd); set_var<strings> (s, r, name, ".options", nullptr); } - static alias_rule alias_rule_; - static file_rule file_rule_; + static alias_rule alias_; + static file_rule file_; extern "C" void install_init (scope& r, @@ -119,8 +126,8 @@ namespace build // Register our alias and file installer rule. // - b.rules.insert<alias> (perform_id, install_id, "install", alias_rule_); - b.rules.insert<file> (perform_id, install_id, "install", file_rule_); + b.rules.insert<alias> (perform_id, install_id, "install.alias", alias_); + b.rules.insert<file> (perform_id, install_id, "install.file", file_); // Enter module variables. // @@ -142,22 +149,22 @@ namespace build bool s (config::specified (r, "config.install")); const string& n (as<string> (*r["project"])); - set_dir (s, r, "root", dir_path (), "", "755", "install"); - set_dir (s, r, "data_root", dir_path ("root"), "644"); - set_dir (s, r, "exec_root", dir_path ("root"), "755"); + set_dir (s, r, "root", "", "", "755", "install"); + set_dir (s, r, "data_root", "root", "644"); + set_dir (s, r, "exec_root", "root", "755"); - set_dir (s, r, "sbin", dir_path ("exec_root/sbin")); - set_dir (s, r, "bin", dir_path ("exec_root/bin")); - set_dir (s, r, "lib", dir_path ("exec_root/lib")); - set_dir (s, r, "libexec", dir_path ("exec_root/libexec/" + n)); + set_dir (s, r, "sbin", "exec_root/sbin"); + set_dir (s, r, "bin", "exec_root/bin"); + set_dir (s, r, "lib", "exec_root/lib"); + set_dir (s, r, "libexec", "exec_root/libexec/" + n, "", "", "", true); - set_dir (s, r, "data", dir_path ("data_root/share/" + n)); - set_dir (s, r, "include", dir_path ("data_root/include")); + set_dir (s, r, "data", "data_root/share/" + n, "", "", "", true); + set_dir (s, r, "include", "data_root/include"); - set_dir (s, r, "doc", dir_path ("data_root/share/doc/" + n)); - set_dir (s, r, "man", dir_path ("data_root/share/man")); + set_dir (s, r, "doc", "data_root/share/doc/" + n, "", "", "", true); + set_dir (s, r, "man", "data_root/share/man"); - set_dir (s, r, "man1", dir_path ("man/man1")); + set_dir (s, r, "man1", "man/man1"); } // Configure "installability" for built-in target types. |