aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-05-23 14:40:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-05-23 14:40:07 +0200
commit0b672184ef920d2581a0be43d27c25690ee0569d (patch)
tree12fa12ca2899c3dddfb2c996dce76d4d2aa21867 /libbuild2
parent73a9ca5ad8925511354ce294e7b061e0262a1f98 (diff)
Cache build.host value in context
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/build/script/script.cxx2
-rw-r--r--libbuild2/context.cxx5
-rw-r--r--libbuild2/context.hxx4
-rw-r--r--libbuild2/install/rule.cxx4
-rw-r--r--libbuild2/test/init.cxx2
-rw-r--r--libbuild2/test/script/parser.test.cxx2
6 files changed, 12 insertions, 7 deletions
diff --git a/libbuild2/build/script/script.cxx b/libbuild2/build/script/script.cxx
index b230ca5..a557065 100644
--- a/libbuild2/build/script/script.cxx
+++ b/libbuild2/build/script/script.cxx
@@ -32,7 +32,7 @@ namespace build2
const optional<timestamp>& dl)
: build2::script::environment (
t.ctx,
- cast<target_triplet> (t.ctx.global_scope["build.host"]),
+ *t.ctx.build_host,
dir_name_view (&work, &wd_name),
temp_dir.path, false /* temp_dir_keep */,
redirect (redirect_type::none),
diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx
index 7b465b4..a7df959 100644
--- a/libbuild2/context.cxx
+++ b/libbuild2/context.cxx
@@ -134,11 +134,12 @@ namespace build2
// Any variable assigned on the global scope should natually have the
// global visibility.
//
- auto set = [&gs, &vp] (const char* var, auto val)
+ auto set = [&gs, &vp] (const char* var, auto val) -> const value&
{
using T = decltype (val);
value& v (gs.assign (vp.insert<T> (var, variable_visibility::global)));
v = move (val);
+ return v;
};
// Build system mode.
@@ -268,7 +269,7 @@ namespace build2
set ("build.host.version", t.version);
set ("build.host.class", t.class_);
- set ("build.host", move (t));
+ build_host = &set ("build.host", move (t)).as<target_triplet> ();
}
catch (const invalid_argument& e)
{
diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx
index 6eb85f7..ad7fdff 100644
--- a/libbuild2/context.hxx
+++ b/libbuild2/context.hxx
@@ -390,6 +390,10 @@ namespace build2
variable_override_cache& global_override_cache;
const strings& global_var_overrides;
+ // Cached values (from global scope).
+ //
+ const target_triplet* build_host; // build.host
+
// Cached variables.
//
diff --git a/libbuild2/install/rule.cxx b/libbuild2/install/rule.cxx
index 1411143..6458a54 100644
--- a/libbuild2/install/rule.cxx
+++ b/libbuild2/install/rule.cxx
@@ -811,7 +811,7 @@ namespace build2
cstrings args;
string reld (
- cast<string> (ctx.global_scope["build.host.class"]) == "windows"
+ ctx.build_host->class_ == "windows"
? msys_path (chd)
: relative (chd).string ());
@@ -857,7 +857,7 @@ namespace build2
dir_path chd (chroot_path (rs, base.dir));
string reld (
- cast<string> (ctx.global_scope["build.host.class"]) == "windows"
+ ctx.build_host->class_ == "windows"
? msys_path (chd)
: relative (chd).string ());
diff --git a/libbuild2/test/init.cxx b/libbuild2/test/init.cxx
index 539cdec..c2fc831 100644
--- a/libbuild2/test/init.cxx
+++ b/libbuild2/test/init.cxx
@@ -125,7 +125,7 @@ namespace build2
value& v (rs.assign (d.test_target));
if (!v || v.empty ())
- v = cast<target_triplet> (rs.ctx.global_scope["build.host"]);
+ v = *rs.ctx.build_host;
}
extra.set_module (new module (move (d)));
diff --git a/libbuild2/test/script/parser.test.cxx b/libbuild2/test/script/parser.test.cxx
index e0dd3d2..ccd4104 100644
--- a/libbuild2/test/script/parser.test.cxx
+++ b/libbuild2/test/script/parser.test.cxx
@@ -218,7 +218,7 @@ namespace build2
tt.assign (
ctx.var_pool.rw ().insert<target_triplet> ("test.target")));
- v = cast<target_triplet> (ctx.global_scope["build.host"]);
+ v = *ctx.build_host;
testscript& st (
ctx.targets.insert<testscript> (work,