aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/parser.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-04-07 11:33:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-04-07 11:43:04 +0200
commite9f69e067da3e096e1e64be70ec2b6de30f71d2c (patch)
tree478c9f0ec86a225398424bcc9305270ca6800339 /libbuild2/parser.cxx
parent5e51d523e71231cb190e9ed981962df527f4ee7e (diff)
Register environment variables for hermetic build configurations
Diffstat (limited to 'libbuild2/parser.cxx')
-rw-r--r--libbuild2/parser.cxx46
1 files changed, 46 insertions, 0 deletions
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 <name>...
+ //
+
+ // 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<strings> (
+ 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_);