From 0b672184ef920d2581a0be43d27c25690ee0569d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 23 May 2022 14:40:07 +0200 Subject: Cache build.host value in context --- libbuild2/build/script/script.cxx | 2 +- libbuild2/context.cxx | 5 +++-- libbuild2/context.hxx | 4 ++++ libbuild2/install/rule.cxx | 4 ++-- libbuild2/test/init.cxx | 2 +- libbuild2/test/script/parser.test.cxx | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) (limited to 'libbuild2') 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& dl) : build2::script::environment ( t.ctx, - cast (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 (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 (); } 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 (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 (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 (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 ("test.target"))); - v = cast (ctx.global_scope["build.host"]); + v = *ctx.build_host; testscript& st ( ctx.targets.insert (work, -- cgit v1.1