diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-05-06 12:10:20 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-05-09 14:55:40 +0200 |
commit | 0e22c2c2261683a86619b1d715e497339f98a362 (patch) | |
tree | 2be0a8c45f667eb94e85b6c8e43986a550f4c1d4 /src/buildtool/build_engine/expression/evaluator.cpp | |
parent | 5d89525367527b659fe9732c4ed90b4e9c2f3658 (diff) | |
download | justbuild-0e22c2c2261683a86619b1d715e497339f98a362.tar.gz |
Built-in "to_subdir": interpret input keys as path
... and detect conflicts araising this way. Also normalize
the paths after staging them to the specified subdir.
Diffstat (limited to 'src/buildtool/build_engine/expression/evaluator.cpp')
-rw-r--r-- | src/buildtool/build_engine/expression/evaluator.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/buildtool/build_engine/expression/evaluator.cpp b/src/buildtool/build_engine/expression/evaluator.cpp index 479de3b8..cfd0be31 100644 --- a/src/buildtool/build_engine/expression/evaluator.cpp +++ b/src/buildtool/build_engine/expression/evaluator.cpp @@ -10,6 +10,7 @@ #include "fmt/core.h" #include "src/buildtool/build_engine/expression/configuration.hpp" #include "src/buildtool/build_engine/expression/function_map.hpp" +#include "src/utils/cpp/path.hpp" namespace { @@ -558,8 +559,8 @@ auto ToSubdirExpr(SubExprEvaluator&& eval, if (flat) { for (auto const& el : d->Map()) { std::filesystem::path k{el.first}; - auto new_path = subdir / k.filename(); - if (result.contains(new_path) && !(result[new_path] == el.second)) { + auto new_key = ToNormalPath(subdir / k.filename()).string(); + if (result.contains(new_key) && !(result[new_key] == el.second)) { // 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"); @@ -568,7 +569,7 @@ auto ToSubdirExpr(SubExprEvaluator&& eval, "Flat staging of {} to subdir {} conflicts on path {}", d->ToString(), subdir.string(), - new_path.string())}; + new_key)}; } std::string msg; try { @@ -581,16 +582,42 @@ auto ToSubdirExpr(SubExprEvaluator&& eval, std::stringstream ss{}; ss << msg << std::endl; ss << "Reason: flat staging to subdir " << subdir.string() - << " conflicts on path " << new_path.string() << std::endl; + << " conflicts on path " << new_key << std::endl; ss << "Map to flatly stage was " << d->ToString() << std::endl; throw Evaluator::EvaluationError(ss.str(), false, true); } - result[new_path] = el.second; + result[new_key] = el.second; } } else { for (auto const& el : d->Map()) { - result[(subdir / el.first).string()] = el.second; + auto new_key = ToNormalPath(subdir / el.first).string(); + if (auto it = result.find(new_key); + it != result.end() && !(it->second == el.second)) { + auto msg_expr = expr->Map().Find("msg"); + if (not msg_expr) { + throw Evaluator::EvaluationError{fmt::format( + "Staging of {} to subdir {} conflicts on path {}", + d->ToString(), + subdir.string(), + new_key)}; + } + 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: staging to subdir " << subdir.string() + << " conflicts on new path " << new_key << std::endl; + ss << "Map to stage was " << d->ToString() << std::endl; + throw Evaluator::EvaluationError(ss.str(), false, true); + } + result.emplace(std::move(new_key), el.second); } } return ExpressionPtr{Expression::map_t{result}}; |