aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-18 15:03:42 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-18 15:03:42 +0200
commitca55c178784779e13245ae2e8760d5ff7c7a4a9f (patch)
tree6ea0eccc472dfe80a771c073a89ca88830d2fce8
parent10af8b3e73ef64c4065acb0f016ce77f55815bc1 (diff)
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
-rw-r--r--build2/install/init.cxx38
-rw-r--r--build2/install/rule.cxx25
2 files changed, 49 insertions, 14 deletions
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 <typename T, typename CT>
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<CT> (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<dir_path> (s, r, n, "", p.empty () ? nullptr : &p, o);
+ bool global (*n == '\0');
+
+ if (!global)
+ set_var<dir_path> (s, r, n, "", p.empty () ? nullptr : &p, o);
+
+ set_var<path> (s, r, n, ".cmd", c.empty () ? nullptr : &c);
+ set_var<strings> (s, r, n, ".options", (strings*) (nullptr));
set_var<string> (s, r, n, ".mode", fm.empty () ? nullptr : &fm);
set_var<string> (s, r, n, ".dir_mode", dm.empty () ? nullptr : &dm);
set_var<string> (s, r, n, ".sudo", (string*) (nullptr));
- set_var<path> (s, r, n, ".cmd", c.empty () ? nullptr : &c);
- set_var<strings> (s, r, n, ".options", (strings*) (nullptr));
// This one doesn't have config.* value (only set in a buildfile).
//
- var_pool.insert<bool> (string ("install.") + n + ".subdirs");
+ if (!global)
+ var_pool.insert<bool> (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<string> (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<string> (l);
if (auto l = s[*var + ".cmd"]) r.cmd = cast<path> (l);
if (auto l = s[*var + ".mode"]) r.mode = cast<string> (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<string> (l);
+
+ if (r.cmd.empty ())
+ r.cmd = cast<path> (s["config.install.cmd"]);
+
+ if (r.options.empty ())
+ if (auto l = s["config.install.options"])
+ r.options = cast<strings> (l);
+
+ if (r.mode.empty ())
+ r.mode = cast<string> (s["config.install.mode"]);
+
+ if (r.dir_mode.empty ())
+ r.dir_mode = cast<string> (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