diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-05-03 13:20:24 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-05-03 16:00:11 +0200 |
commit | aa3f72ba653c1444f4238ecb6e596aac6c20d1cb (patch) | |
tree | a5d572f36a1301a782edd06347cf0aed029da39e /src | |
parent | 573f9070257aa9161ac58d85386e3bca46ed0cc2 (diff) | |
download | justbuild-aa3f72ba653c1444f4238ecb6e596aac6c20d1cb.tar.gz |
Include environment in action reporting on the command line
Compared to the command line, the environment usually is quite
short. So including it in messages reporting about commands does
not introduce a lot of additional noise. However, knowing the
environment can help understanding an error message. Therefore, it
seems a good trade off to include it. Do so.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/execution_engine/executor/executor.hpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index ca174c84..f7afb077 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -524,7 +524,7 @@ class ExecutorImpl { } progress->TaskTracker().Stop(action->Content().Id()); - PrintInfo(logger, action->Command(), response); + PrintInfo(logger, action, response); bool should_fail_outputs = false; for (auto const& [local_path, node] : action->Dependencies()) { should_fail_outputs |= node->Content().Info()->failed; @@ -573,34 +573,36 @@ class ExecutorImpl { /// \brief Write out if response is empty and otherwise, write out /// standard error/output if they are present - void static PrintInfo(Logger const& logger, - std::vector<std::string> const& command, - IExecutionResponse::Ptr const& response) noexcept { + void static PrintInfo( + Logger const& logger, + gsl::not_null<DependencyGraph::ActionNode const*> const& action, + IExecutionResponse::Ptr const& response) noexcept { if (!response) { logger.Emit(LogLevel::Error, "response is empty"); return; } auto const has_err = response->HasStdErr(); auto const has_out = response->HasStdOut(); - auto build_message = - [has_err, has_out, &logger, &command, &response]() { - using namespace std::string_literals; - auto message = ""s; - if (has_err or has_out) { - message += (has_err and has_out ? "Stdout and stderr"s - : has_out ? "Stdout"s - : "Stderr"s) + - " of command: "; - } - message += nlohmann::json(command).dump() + "\n"; - if (response->HasStdOut()) { - message += response->StdOut(); - } - if (response->HasStdErr()) { - message += response->StdErr(); - } - return message; - }; + auto build_message = [has_err, has_out, &logger, &action, &response]() { + using namespace std::string_literals; + auto message = ""s; + if (has_err or has_out) { + message += (has_err and has_out ? "Stdout and stderr"s + : has_out ? "Stdout"s + : "Stderr"s) + + " of command "; + } + message += nlohmann::json(action->Command()).dump() + + " in environment " + + nlohmann::json(action->Env()).dump() + "\n"; + if (response->HasStdOut()) { + message += response->StdOut(); + } + if (response->HasStdErr()) { + message += response->StdErr(); + } + return message; + }; logger.Emit((has_err or has_out) ? LogLevel::Info : LogLevel::Debug, std::move(build_message)); } @@ -612,6 +614,8 @@ class ExecutorImpl { std::ostringstream msg{}; msg << "Failed to execute command "; msg << nlohmann::json(action->Command()).dump(); + msg << " in evenironment "; + msg << nlohmann::json(action->Env()).dump(); auto const& origin_map = progress->OriginMap(); auto origins = origin_map.find(action->Content().Id()); if (origins != origin_map.end() and !origins->second.empty()) { |