diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-04-16 10:48:00 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-04-16 14:37:46 +0200 |
commit | 0c2f80c405a15d63293ae0b7ae89bdbf9f04e771 (patch) | |
tree | 50e5b423f54f742936603d03ef9b48d33cffd3f2 /src/buildtool/main/main.cpp | |
parent | c1f93f066b1d131c08b2f4bb6cdeae8ca69acd90 (diff) | |
download | justbuild-0c2f80c405a15d63293ae0b7ae89bdbf9f04e771.tar.gz |
just: support writing the error blobs from serve into a json file
... so that they are available in machine-readable form. In this
way, all logs can automatically be collected without the need of
parsing human-targeted error messages.
Diffstat (limited to 'src/buildtool/main/main.cpp')
-rw-r--r-- | src/buildtool/main/main.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 21f08618..59225fc7 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -17,6 +17,7 @@ #include <filesystem> #include <fstream> #include <iostream> +#include <mutex> #include <optional> #include <string> #include <unordered_map> @@ -1017,14 +1018,36 @@ auto main(int argc, char* argv[]) -> int { arguments.common.jobs}; auto id = ReadConfiguredTarget( main_repo, main_ws_root, &repo_config, arguments.analysis); - auto result = - AnalyseTarget(id, - &result_map, - &repo_config, - Storage::Instance().TargetCache(), - &stats, - arguments.common.jobs, - arguments.analysis.request_action_input); + auto serve_errors = nlohmann::json::array(); + std::mutex serve_errors_access{}; + BuildMaps::Target::ServeFailureLogReporter collect_serve_errors = + [&serve_errors, &serve_errors_access](auto target, auto blob) { + std::unique_lock lock(serve_errors_access); + auto target_desc = nlohmann::json::array(); + target_desc.push_back(target.target.ToJson()); + target_desc.push_back(target.config.ToJson()); + auto entry = nlohmann::json::array(); + entry.push_back(target_desc); + entry.push_back(blob); + serve_errors.push_back(entry); + }; + auto result = AnalyseTarget(id, + &result_map, + &repo_config, + Storage::Instance().TargetCache(), + &stats, + arguments.common.jobs, + arguments.analysis.request_action_input, + /*logger=*/nullptr, + &collect_serve_errors); + if (arguments.analysis.serve_errors_file) { + Logger::Log( + serve_errors.empty() ? LogLevel::Debug : LogLevel::Info, + "Dumping serve-error information to {}", + arguments.analysis.serve_errors_file->string()); + std::ofstream os(*arguments.analysis.serve_errors_file); + os << serve_errors.dump() << std::endl; + } if (result) { if (arguments.analysis.graph_file) { result_map.ToFile( |