summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--share/man/just.1.md5
-rw-r--r--src/buildtool/common/cli.hpp5
-rw-r--r--src/buildtool/main/diagnose.cpp20
-rwxr-xr-xtest/end-to-end/cli/analyse.sh6
5 files changed, 38 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0b5f18e8..15a54239 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,8 @@ A feature release on top of `1.2.0`, backwards compatible.
- The expression language has been extended and, in particular,
allows indexed access to an arry (basically using it as a tuple)
and a generic form of assertion (to report user errors).
+- The `analyse` subcommand supports a new flag `--dump-result` to dump
+ the analysis result to a file or stdout (if `-` is given).
### Fixes
diff --git a/share/man/just.1.md b/share/man/just.1.md
index 504386ce..f4d613bf 100644
--- a/share/man/just.1.md
+++ b/share/man/just.1.md
@@ -712,6 +712,11 @@ by a JSON object with their intensional description. Therefore, the
dumped JSON is not uniquely readable, but requires an out-of-band
understanding where artifacts are to be expected.
+**`--dump-result`** *`PATH`*
+Dump the result of the analysis for the requested target to
+file. *`-`* is treated as stdout. The output is a JSON object with the
+keys *`"artifacts"`*, *`"provides"`*, and *`"runfiles"`*.
+
**`rebuild`** specific options
------------------------------
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);
}
diff --git a/test/end-to-end/cli/analyse.sh b/test/end-to-end/cli/analyse.sh
index 69ffd4b8..b09a3ac8 100755
--- a/test/end-to-end/cli/analyse.sh
+++ b/test/end-to-end/cli/analyse.sh
@@ -49,6 +49,12 @@ cat > TARGETS <<'EOF'
{"provides": {"type": "provides"}}
EOF
+"${TOOL}" analyse --local-build-root "${BUILDROOT}" \
+ --dump-result "${OUT}/result.json" 2>&1
+cat "${OUT}/result.json"
+[ "$(jq 'has("artifacts")' "${OUT}/result.json")" = true ]
+[ "$(jq 'has("provides")' "${OUT}/result.json")" = true ]
+[ "$(jq 'has("runfiles")' "${OUT}/result.json")" = true ]
"${TOOL}" analyse --local-build-root "${BUILDROOT}" \
--dump-provides "${OUT}/plain.json" 2>&1