aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-10-10 17:22:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-11-06 19:32:09 +0300
commitf41599c8e9435f3dfec60b872c2b4ae31177efdd (patch)
tree088f8d9bf906e4a2ed734e034699163c9ccc7306 /libbuild2/build/script
parentac76a4fd2afff48a0d5db84592babe5cabef3a2c (diff)
Add support for test timeouts
Diffstat (limited to 'libbuild2/build/script')
-rw-r--r--libbuild2/build/script/script.cxx28
-rw-r--r--libbuild2/build/script/script.hxx26
2 files changed, 50 insertions, 4 deletions
diff --git a/libbuild2/build/script/script.cxx b/libbuild2/build/script/script.cxx
index 3485f54..c6b57c3 100644
--- a/libbuild2/build/script/script.cxx
+++ b/libbuild2/build/script/script.cxx
@@ -7,6 +7,8 @@
#include <libbuild2/target.hxx>
+#include <libbuild2/script/timeout.hxx>
+
#include <libbuild2/build/script/parser.hxx>
using namespace std;
@@ -17,12 +19,17 @@ namespace build2
{
namespace script
{
+ using build2::script::to_deadline;
+
// environment
//
static const optional<string> wd_name ("current directory");
environment::
- environment (action a, const target_type& t, bool temp)
+ environment (action a,
+ const target_type& t,
+ bool temp,
+ const optional<timestamp>& dl)
: build2::script::environment (
t.ctx,
cast<target_triplet> (t.ctx.global_scope["build.host"]),
@@ -32,7 +39,8 @@ namespace build2
redirect (redirect_type::merge, 2),
redirect (redirect_type::pass)),
target (t),
- vars (context, false /* global */)
+ vars (context, false /* global */),
+ script_deadline (to_deadline (dl, false /* success */))
{
// Set special variables.
//
@@ -58,8 +66,10 @@ namespace build2
//
names ns;
for (const target_type* pt: t.prerequisite_targets[a])
+ {
if (pt != nullptr)
pt->as_name (ns);
+ }
assign (var_pool.insert ("<")) = move (ns);
}
@@ -231,6 +241,20 @@ namespace build2
return r;
}
+
+ void environment::
+ set_timeout (const string& t, bool success, const location& l)
+ {
+ fragment_deadline =
+ to_deadline (parse_deadline (t, "buildscript timeout", l),
+ success);
+ }
+
+ optional<deadline> environment::
+ effective_deadline ()
+ {
+ return earlier (script_deadline, fragment_deadline);
+ }
}
}
}
diff --git a/libbuild2/build/script/script.hxx b/libbuild2/build/script/script.hxx
index f4d70ac..9284813 100644
--- a/libbuild2/build/script/script.hxx
+++ b/libbuild2/build/script/script.hxx
@@ -26,6 +26,8 @@ namespace build2
using build2::script::redirect_type;
using build2::script::expr_term;
using build2::script::command_expr;
+ using build2::script::deadline;
+ using build2::script::timeout;
// Notes:
//
@@ -83,7 +85,10 @@ namespace build2
public:
using target_type = build2::target;
- environment (action, const target_type&, bool temp_dir);
+ environment (action,
+ const target_type&,
+ bool temp_dir,
+ const optional<timestamp>& deadline = nullopt);
environment (environment&&) = delete;
environment (const environment&) = delete;
@@ -98,7 +103,7 @@ namespace build2
// Script-local variable pool and map.
//
// Note that it may be tempting to reuse the rule-specific variables
- // for this but they should no be modified during execution (i.e.,
+ // for this but they should not be modified during execution (i.e.,
// they are for intra-rule communication; perhaps we could have a
// special builtin that sets such variables during match).
//
@@ -125,12 +130,29 @@ namespace build2
//
auto_rmdir temp_dir;
+ // The whole script and the remaining script fragment execution
+ // deadlines (the latter is set by the timeout builtin).
+ //
+ optional<deadline> script_deadline;
+ optional<deadline> fragment_deadline;
+
virtual void
set_variable (string&& name,
names&&,
const string& attrs,
const location&) override;
+ // Parse the specified in seconds timeout and set the remaining script
+ // fragment execution deadline. Reset it to nullopt on zero.
+ //
+ virtual void
+ set_timeout (const string&, bool success, const location&) override;
+
+ // Return the nearest of the script and fragment execution deadlines.
+ //
+ virtual optional<deadline>
+ effective_deadline () override;
+
virtual void
create_temp_dir () override;