aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script/parser.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/script/parser.cxx')
-rw-r--r--libbuild2/script/parser.cxx40
1 files changed, 36 insertions, 4 deletions
diff --git a/libbuild2/script/parser.cxx b/libbuild2/script/parser.cxx
index ebfd5fc..f234d58 100644
--- a/libbuild2/script/parser.cxx
+++ b/libbuild2/script/parser.cxx
@@ -1028,8 +1028,9 @@ namespace build2
if (prog && tt == type::word && t.value == "env")
{
parsed_env r (parse_env_builtin (t, tt));
+ c.cwd = move (r.cwd);
c.variables = move (r.variables);
- c.timeout = r.timeout;
+ c.timeout = r.timeout;
env = true;
}
@@ -1411,10 +1412,16 @@ namespace build2
return r;
};
+ auto bad = [&i, &o, this] (const string& v)
+ {
+ fail (i->second) << "env: invalid value '" << v << "' for option '"
+ << o << "'";
+ };
+
// As above but convert the option value to a number and fail on
// error.
//
- auto num = [&i, &o, &str, this] (const char* ln, const char* sn)
+ auto num = [&str, &bad] (const char* ln, const char* sn)
{
optional<uint64_t> r;
if (optional<string> s = str (ln, sn))
@@ -1422,8 +1429,29 @@ namespace build2
r = parse_number (*s);
if (!r)
- fail (i->second) << "env: invalid value '" << *s
- << "' for option '" << o << "'";
+ bad (*s);
+ }
+
+ return r;
+ };
+
+ // As above but convert the option value to a directory path and fail
+ // on error.
+ //
+ auto dir = [&str, &bad] (const char* ln, const char* sn)
+ {
+ optional<dir_path> r;
+ if (optional<string> s = str (ln, sn))
+ try
+ {
+ // Note that we don't need to check that the path is not empty,
+ // since str() fails for empty values.
+ //
+ r = dir_path (move (*s));
+ }
+ catch (const invalid_path& e)
+ {
+ bad (e.path);
}
return r;
@@ -1435,6 +1463,10 @@ namespace build2
{
r.timeout = chrono::seconds (*v);
}
+ else if (optional<dir_path> v = dir ("--cwd", "-c"))
+ {
+ r.cwd = move (*v);
+ }
else if (optional<string> v = str ("--unset", "-u"))
{
verify_environment_var_name (*v, "env: ", i->second, o.c_str ());