summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-05-25 14:48:25 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-05-31 14:14:25 +0200
commit6e6516f741771076f9210531a37ffcd30e6ec636 (patch)
treea8518f677ca8506baa084bb80831ba6c467b1955
parenteb6c1fab20327379f318b5f81b940a88627cec8e (diff)
downloadjustbuild-6e6516f741771076f9210531a37ffcd30e6ec636.tar.gz
ACTION constructor: accept "timeout scaling"
Allow rules to set the timeout-scaling factor for their actions to indicate that some actions are expected to take longer than others, e.g., because they call a foreign build tool or are a very complex end-to-end test.
-rw-r--r--src/buildtool/build_engine/expression/expression.hpp1
-rw-r--r--src/buildtool/build_engine/target_map/target_map.cpp28
2 files changed, 20 insertions, 9 deletions
diff --git a/src/buildtool/build_engine/expression/expression.hpp b/src/buildtool/build_engine/expression/expression.hpp
index 5d84e131..86b6cc38 100644
--- a/src/buildtool/build_engine/expression/expression.hpp
+++ b/src/buildtool/build_engine/expression/expression.hpp
@@ -242,6 +242,7 @@ class Expression {
Expression::FromJson("[]"_json);
inline static ExpressionPtr const kEmptyMapExpr =
Expression::FromJson(R"({"type": "empty_map"})"_json);
+ inline static ExpressionPtr const kOne = Expression::FromJson("1.0"_json);
private:
std::variant<none_t,
diff --git a/src/buildtool/build_engine/target_map/target_map.cpp b/src/buildtool/build_engine/target_map/target_map.cpp
index 13825148..c61e3670 100644
--- a/src/buildtool/build_engine/target_map/target_map.cpp
+++ b/src/buildtool/build_engine/target_map/target_map.cpp
@@ -551,15 +551,25 @@ void withDependencies(
}
}
bool no_cache = not no_cache_exp->List().empty();
- auto action =
- BuildMaps::Target::Utils::createAction(outputs,
- output_dirs,
- std::move(cmd),
- env_exp,
- may_fail,
- no_cache,
- 1.0,
- inputs_exp);
+ auto timeout_scale_exp =
+ eval(expr->Get("timeout scaling", Expression::kOne), env);
+ if (not(timeout_scale_exp->IsNumber() or
+ timeout_scale_exp->IsNone())) {
+ throw Evaluator::EvaluationError{
+ fmt::format("timeout scaling has to be number (or null "
+ "for default), but found {}",
+ timeout_scale_exp->ToString())};
+ }
+ auto action = BuildMaps::Target::Utils::createAction(
+ outputs,
+ output_dirs,
+ std::move(cmd),
+ env_exp,
+ may_fail,
+ no_cache,
+ timeout_scale_exp->IsNumber() ? timeout_scale_exp->Number()
+ : 1.0,
+ inputs_exp);
auto action_id = action->Id();
actions.emplace_back(std::move(action));
for (auto const& out : outputs) {