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/parser.cxx | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libbuild2/parser.cxx') diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 90c865b..9022d5b 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -494,6 +494,10 @@ namespace build2 { f = &parser::parse_config; } + else if (n == "config.environment") + { + f = &parser::parse_config_environment; + } if (f != nullptr) { @@ -2486,6 +2490,48 @@ namespace build2 } void parser:: + parse_config_environment (token& t, type& tt) + { + // config.environment ... + // + + // While we could allow this directive during bootstrap, it would have to + // be after loading the config module, which can be error prone. So we + // disallow it for now (it's also not clear "configuring" bootstrap with + // environment variables is a good idea; think of info, etc). + // + if (stage_ == stage::boot) + fail (t) << "config.environment during bootstrap"; + + // Parse the rest as names in the value mode to get variable expansion, + // etc. + // + mode (lexer_mode::value); + next (t, tt); + const location l (get_location (t)); + + strings ns; + try + { + ns = convert ( + tt != type::newline && tt != type::eos + ? parse_names (t, tt, + pattern_mode::ignore, + "environment variable name", + nullptr) + : names ()); + } + catch (const invalid_argument& e) + { + fail (l) << "invalid environment variable name: " << e.what (); + } + + config::save_environment (*root_, ns); + + next_after_newline (t, tt); + } + + void parser:: parse_import (token& t, type& tt) { tracer trace ("parser::parse_import", &path_); -- cgit v1.1