aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/parser.cxx
diff options
context:
space:
mode:
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_);