aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-04-12 17:09:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-04-12 17:09:35 +0200
commitce4848cfaaa569da3e11de51f4174eb21709b9b9 (patch)
treedd9918fd6b769591912c4e6dbbb05ac73364035b
parent33be784e4b991a95d3ef14a6ef555f1299ec7021 (diff)
Add -s|--timeout-success option to env script builtin
The semantics is equivalent to the --success option we already have in the timeout builtin.
-rw-r--r--doc/testscript.cli5
-rw-r--r--libbuild2/script/parser.cxx14
-rw-r--r--libbuild2/script/parser.hxx9
-rw-r--r--libbuild2/script/run.cxx2
-rw-r--r--libbuild2/script/script.cxx5
-rw-r--r--libbuild2/script/script.hxx10
6 files changed, 34 insertions, 11 deletions
diff --git a/doc/testscript.cli b/doc/testscript.cli
index 20d9c2d..c539903 100644
--- a/doc/testscript.cli
+++ b/doc/testscript.cli
@@ -2777,6 +2777,11 @@ env - --unset=FOO -- $*
Terminate the command if it fails to complete within the specified number
of seconds. See also the \l{#builtins-timeout \c{timeout}} builtin.|
+\li|\n\c{-s|--timeout-success}
+
+ Assume the command terminated due to the timeout specified with the
+ \c{-t|--timeout} option to have succeeded.|
+
\li|\n\c{-c|--cwd <dir>}
Change the command's working directory.|
diff --git a/libbuild2/script/parser.cxx b/libbuild2/script/parser.cxx
index ae6da76..84d2afc 100644
--- a/libbuild2/script/parser.cxx
+++ b/libbuild2/script/parser.cxx
@@ -1134,9 +1134,10 @@ namespace build2
if (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.cwd = move (r.cwd);
+ c.variables = move (r.variables);
+ c.timeout = r.timeout;
+ c.timeout_success = r.timeout_success;
env = true;
}
else if (t.value == "for")
@@ -1601,6 +1602,10 @@ namespace build2
{
r.timeout = chrono::seconds (*v);
}
+ else if (o == "-s" || o == "--timeout-success")
+ {
+ r.timeout_success = true;
+ }
else if (optional<dir_path> v = dir ("--cwd", "-c"))
{
r.cwd = move (*v);
@@ -1615,6 +1620,9 @@ namespace build2
break;
}
+ if (r.timeout_success && !r.timeout)
+ fail (l) << "env: -s|--timeout-success specified without -t|--timeout";
+
// Parse arguments (variable sets).
//
for (; i != e; ++i)
diff --git a/libbuild2/script/parser.hxx b/libbuild2/script/parser.hxx
index cadf909..795ce4e 100644
--- a/libbuild2/script/parser.hxx
+++ b/libbuild2/script/parser.hxx
@@ -163,14 +163,15 @@ namespace build2
pre_parse_line_start (token&, token_type&, lexer_mode);
// Parse the env pseudo-builtin arguments up to the program name. Return
- // the program execution timeout, CWD, the list of the variables that
- // should be unset ("name") and/or set ("name=value") in the command
- // environment, and the token/type that starts the program name. Note
- // that the variable unsets come first, if present.
+ // the program execution timeout and its success flag, CWD, the list of
+ // the variables that should be unset ("name") and/or set ("name=value")
+ // in the command environment, and the token/type that starts the
+ // program name. Note that the variable unsets come first, if present.
//
struct parsed_env
{
optional<duration> timeout;
+ bool timeout_success = false;
optional<dir_path> cwd;
environment_vars variables;
};
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx
index 6d73a7e..f8f98c1 100644
--- a/libbuild2/script/run.cxx
+++ b/libbuild2/script/run.cxx
@@ -2069,7 +2069,7 @@ namespace build2
if (c.timeout)
{
- deadline d (system_clock::now () + *c.timeout, false /* success */);
+ deadline d (system_clock::now () + *c.timeout, c.timeout_success);
if (!dl || d < *dl)
dl = d;
}
diff --git a/libbuild2/script/script.cxx b/libbuild2/script/script.cxx
index 4a6ca33..b53fc23 100644
--- a/libbuild2/script/script.cxx
+++ b/libbuild2/script/script.cxx
@@ -425,9 +425,14 @@ namespace build2
// Timeout.
//
if (c.timeout)
+ {
o << " -t "
<< chrono::duration_cast<chrono::seconds> (*c.timeout).count ();
+ if (c.timeout_success)
+ o << " -s";
+ }
+
// CWD.
//
if (c.cwd)
diff --git a/libbuild2/script/script.hxx b/libbuild2/script/script.hxx
index cccad98..c406165 100644
--- a/libbuild2/script/script.hxx
+++ b/libbuild2/script/script.hxx
@@ -331,9 +331,13 @@ namespace build2
process_path program;
strings arguments;
- optional<dir_path> cwd; // From env builtin.
- environment_vars variables; // From env builtin.
- optional<duration> timeout; // From env builtin.
+
+ // These come from the env builtin.
+ //
+ optional<dir_path> cwd;
+ environment_vars variables;
+ optional<duration> timeout;
+ bool timeout_success;
optional<redirect> in;
optional<redirect> out;