summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlberto Sartori <alberto.sartori@huawei.com>2024-02-26 16:31:00 +0100
committerAlberto Sartori <alberto.sartori@huawei.com>2024-04-24 12:58:10 +0200
commitf7f2f0dc41b75b5f2a094d33e6325fdf9e8438a8 (patch)
tree80d23e32f6634279ea6f516f1592da9952cdf650 /src
parent4ea9f8f7f3367bed309c6e3f84bed541d73929e8 (diff)
downloadjustbuild-f7f2f0dc41b75b5f2a094d33e6325fdf9e8438a8.tar.gz
just analyse: add --dump-result command line option
The result of the analysis is a JSON object containing the keys `"artifacts"`, `"runfiles"`, and `"provides"`. This JSON object, by default, is logged. However, it might be useful to process the data contained in it, while, for example, developing new rules. This patch adds a new command line option (`--dump-result`), reserved to the subcommand `analyse`, to dump the analysis result to the given file or stdout (if `-` is given).
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/cli.hpp5
-rw-r--r--src/buildtool/main/diagnose.cpp20
2 files changed, 25 insertions, 0 deletions
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp
index eded8112..57567cf7 100644
--- a/src/buildtool/common/cli.hpp
+++ b/src/buildtool/common/cli.hpp
@@ -91,6 +91,7 @@ struct DiagnosticArguments {
std::optional<std::string> dump_targets_graph{std::nullopt};
std::optional<std::string> dump_anonymous{std::nullopt};
std::optional<std::string> dump_nodes{std::nullopt};
+ std::optional<std::string> dump_result{std::nullopt};
};
/// \brief Arguments required for specifying build endpoint.
@@ -398,6 +399,10 @@ static inline auto SetupDiagnosticArguments(
clargs->dump_nodes,
"Dump nodes of target to file (use - for stdout).")
->type_name("PATH");
+ app->add_option("--dump-result",
+ clargs->dump_result,
+ "Dump the result of analyse to file (use - for stdout).")
+ ->type_name("PATH");
}
static inline auto SetupCacheArguments(
diff --git a/src/buildtool/main/diagnose.cpp b/src/buildtool/main/diagnose.cpp
index 2da1c89a..49aefc86 100644
--- a/src/buildtool/main/diagnose.cpp
+++ b/src/buildtool/main/diagnose.cpp
@@ -290,6 +290,23 @@ void DumpNodes(std::string const& file_path, AnalysisResult const& result) {
os << dump_string << std::endl;
}
}
+
+void DumpResult(std::string const& file_path, AnalysisResult const& result) {
+ auto const dump_string = ResultToJson(result.target->Result()).dump();
+ if (file_path == "-") {
+ Logger::Log(
+ LogLevel::Info, "Result of target {}:", result.id.ToString());
+ std::cout << dump_string << std::endl;
+ }
+ else {
+ Logger::Log(LogLevel::Info,
+ "Dumping result of target {} to file '{}'.",
+ result.id.ToString(),
+ file_path);
+ std::ofstream os{file_path};
+ os << dump_string << std::endl;
+ }
+}
} // namespace
void DiagnoseResults(AnalysisResult const& result,
@@ -307,6 +324,9 @@ void DiagnoseResults(AnalysisResult const& result,
2,
2,
std::unordered_map<std::string, std::size_t>{{"/provides", 3}}));
+ if (clargs.dump_result) {
+ DumpResult(*clargs.dump_result, result);
+ }
if (clargs.dump_actions) {
DumpActions(*clargs.dump_actions, result);
}