From e9f69e067da3e096e1e64be70ec2b6de30f71d2c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 7 Apr 2021 11:33:05 +0200 Subject: Register environment variables for hermetic build configurations --- libbuild2/file.cxx | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'libbuild2/file.cxx') diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx index e96142d..02ad71d 100644 --- a/libbuild2/file.cxx +++ b/libbuild2/file.cxx @@ -19,7 +19,7 @@ #include #include // config::module::version -#include // config::lookup_config() +#include // config::{lookup_*, save_*}() using namespace std; using namespace butl; @@ -2888,6 +2888,10 @@ namespace build2 target& t (pt->rw ()); // Load phase. + // Note that if metadata is requested via any of the import*() functions, + // then we will always end up here (see delegates to import_direct()), + // which is where we do the final verifications and processing. + // if (meta) { // The export.metadata value should start with the version followed by @@ -2924,14 +2928,30 @@ namespace build2 fail (loc) << "invalid metadata variable prefix in imported " << "target " << t; + const string& pfx (ns[1].value); + + auto& vp (ctx.var_pool.rw ()); // Load phase. + // See if we have the stable program name in the .name // variable. If its missing, set it to the metadata key (i.e., target // name as imported) by default. // - auto& vp (ctx.var_pool.rw ()); // Load phase. - value& nv (t.assign (vp.insert (ns[1].value + ".name"))); - if (!nv) - nv = *meta; + { + value& nv (t.assign (vp.insert (pfx + ".name"))); + if (!nv) + nv = *meta; + } + + // See if the program reported the use of environment variables and + // if so save them as affecting this project. + // + if (const auto* e = cast_null (t.vars[pfx + ".environment"])) + { + scope& rs (*base.root_scope ()); + + for (const string& v: *e) + config::save_environment (rs, v); + } } else fail (loc) << "no metadata for imported target " << t; -- cgit v1.1