From ca55c178784779e13245ae2e8760d5ff7c7a4a9f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 18 Aug 2016 15:03:42 +0200 Subject: Add global config.install.{cmd,options,sudo,mode,dir_mode} This way we can do: b install \ config.install.data_root=/tmp/data \ config.install.exec_root=/tmp/exec \ config.install.sudo=sudo --- build2/install/init.cxx | 38 ++++++++++++++++++++++++++++++-------- build2/install/rule.cxx | 25 +++++++++++++++++++------ 2 files changed, 49 insertions(+), 14 deletions(-) (limited to 'build2/install') diff --git a/build2/install/init.cxx b/build2/install/init.cxx index 1e092e8..6e1a2a2 100644 --- a/build2/install/init.cxx +++ b/build2/install/init.cxx @@ -33,6 +33,8 @@ namespace build2 // configurations. We have to do this for paths that contain the // package name. // + // For global values we only set config.install.* variables. + // template static void set_var (bool spec, @@ -45,10 +47,16 @@ namespace build2 string vn; const value* cv (nullptr); + bool global (*name == '\0'); + if (spec) { - vn = "config.install."; - vn += name; + vn = "config.install"; + if (!global) + { + vn += '.'; + vn += name; + } vn += var; const variable& vr (var_pool.insert (move (vn), true)); @@ -57,6 +65,9 @@ namespace build2 : &config::optional (r, vr); } + if (global) + return; + vn = "install."; vn += name; vn += var; @@ -89,16 +100,21 @@ namespace build2 { using build2::path; - set_var (s, r, n, "", p.empty () ? nullptr : &p, o); + bool global (*n == '\0'); + + if (!global) + set_var (s, r, n, "", p.empty () ? nullptr : &p, o); + + set_var (s, r, n, ".cmd", c.empty () ? nullptr : &c); + set_var (s, r, n, ".options", (strings*) (nullptr)); set_var (s, r, n, ".mode", fm.empty () ? nullptr : &fm); set_var (s, r, n, ".dir_mode", dm.empty () ? nullptr : &dm); set_var (s, r, n, ".sudo", (string*) (nullptr)); - set_var (s, r, n, ".cmd", c.empty () ? nullptr : &c); - set_var (s, r, n, ".options", (strings*) (nullptr)); // This one doesn't have config.* value (only set in a buildfile). // - var_pool.insert (string ("install.") + n + ".subdirs"); + if (!global) + var_pool.insert (string ("install.") + n + ".subdirs"); } static alias_rule alias_; @@ -116,6 +132,8 @@ namespace build2 r.operations.insert (install_id, install); } + static const path cmd ("install"); + static const dir_path dir_root ("root"); static const dir_path dir_sbin (dir_path ("exec_root") /= "sbin"); @@ -189,9 +207,13 @@ namespace build2 const string& n (cast (r["project"])); - set_dir (s, r, "root", abs_dir_path (), false, "", "755", path ("install")); + // Global config.install.* values. + // + set_dir (s, r, "", abs_dir_path (), false, "644", "755", cmd); + + set_dir (s, r, "root", abs_dir_path ()); - set_dir (s, r, "data_root", dir_root, false, "644"); + set_dir (s, r, "data_root", dir_root); set_dir (s, r, "exec_root", dir_root, false, "755"); set_dir (s, r, "sbin", dir_sbin); diff --git a/build2/install/rule.cxx b/build2/install/rule.cxx index 39741bd..ac2fc8f 100644 --- a/build2/install/rule.cxx +++ b/build2/install/rule.cxx @@ -395,12 +395,12 @@ namespace build2 info << "did you forget to specify config." << var << "?"; } + scope& s (t.base_scope ()); + // Override components in install_dir if we have our own. // if (var != nullptr) { - scope& s (t.base_scope ()); - if (auto l = s[*var + ".sudo"]) r.sudo = cast (l); if (auto l = s[*var + ".cmd"]) r.cmd = cast (l); if (auto l = s[*var + ".mode"]) r.mode = cast (l); @@ -429,11 +429,24 @@ namespace build2 } } - // Set defaults for unspecified components. + // Set globals for unspecified components. // - if (r.cmd.empty ()) r.cmd = path ("install"); - if (r.mode.empty ()) r.mode = "644"; - if (r.dir_mode.empty ()) r.dir_mode = "755"; + if (r.sudo.empty ()) + if (auto l = s["config.install.sudo"]) + r.sudo = cast (l); + + if (r.cmd.empty ()) + r.cmd = cast (s["config.install.cmd"]); + + if (r.options.empty ()) + if (auto l = s["config.install.options"]) + r.options = cast (l); + + if (r.mode.empty ()) + r.mode = cast (s["config.install.mode"]); + + if (r.dir_mode.empty ()) + r.dir_mode = cast (s["config.install.dir_mode"]); // If the directory still doesn't exist, then this means it was // specified as absolute (it will normally be install.root with -- cgit v1.1