summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-04-25 12:12:14 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-04-25 15:26:53 +0200
commit32322ff28c151d8ec5510b7019365d573e44bddf (patch)
treeba1d961cb7414bed54fc8a617f51fcd15d620fcd /src
parent32981ac5493a7d9925130609ad123ae2ac9984ab (diff)
downloadjustbuild-32322ff28c151d8ec5510b7019365d573e44bddf.tar.gz
expression: add "msg" argument to "to_subdir"
... allowing to provide additional information in case of conflict during flat staging.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/build_engine/expression/evaluator.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/buildtool/build_engine/expression/evaluator.cpp b/src/buildtool/build_engine/expression/evaluator.cpp
index 25723627..479de3b8 100644
--- a/src/buildtool/build_engine/expression/evaluator.cpp
+++ b/src/buildtool/build_engine/expression/evaluator.cpp
@@ -560,11 +560,30 @@ auto ToSubdirExpr(SubExprEvaluator&& eval,
std::filesystem::path k{el.first};
auto new_path = subdir / k.filename();
if (result.contains(new_path) && !(result[new_path] == el.second)) {
- throw Evaluator::EvaluationError{fmt::format(
- "Flat staging of {} to subdir {} conflicts on path {}",
- d->ToString(),
- subdir.string(),
- new_path.string())};
+ // Check if the user specifed an error message for that case,
+ // otherwise just generate a generic error message.
+ auto msg_expr = expr->Map().Find("msg");
+ if (not msg_expr) {
+ throw Evaluator::EvaluationError{fmt::format(
+ "Flat staging of {} to subdir {} conflicts on path {}",
+ d->ToString(),
+ subdir.string(),
+ new_path.string())};
+ }
+ std::string msg;
+ try {
+ auto msg_val = eval(msg_expr->get(), env);
+ msg = msg_val->ToString();
+ } catch (std::exception const&) {
+ msg =
+ "[non evaluating term] " + msg_expr->get()->ToString();
+ }
+ std::stringstream ss{};
+ ss << msg << std::endl;
+ ss << "Reason: flat staging to subdir " << subdir.string()
+ << " conflicts on path " << new_path.string() << std::endl;
+ ss << "Map to flatly stage was " << d->ToString() << std::endl;
+ throw Evaluator::EvaluationError(ss.str(), false, true);
}
result[new_path] = el.second;
}