From 3c2877dd63698f6ef424538ed91ffa66144bf115 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 8 Jan 2025 18:05:48 +0100 Subject: just build: add new option -p ... allowing to print the unique artifact built (if any). This allows convenient inspection of the build result of targets that define precisely one artifact. --- src/buildtool/graph_traverser/graph_traverser.hpp | 52 +++++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) (limited to 'src/buildtool/graph_traverser/graph_traverser.hpp') diff --git a/src/buildtool/graph_traverser/graph_traverser.hpp b/src/buildtool/graph_traverser/graph_traverser.hpp index 51069c0b..3203f9c7 100644 --- a/src/buildtool/graph_traverser/graph_traverser.hpp +++ b/src/buildtool/graph_traverser/graph_traverser.hpp @@ -158,7 +158,13 @@ class GraphTraverser { rel_paths, artifact_nodes, runfile_descriptions); - MaybePrintToStdout(rel_paths, artifact_nodes); + MaybePrintToStdout( + rel_paths, + artifact_nodes, + artifact_descriptions.size() == 1 + ? std::optional{artifact_descriptions.begin() + ->first} + : std::nullopt); return BuildResult{.output_paths = std::move(rel_paths), .extra_infos = std::move(infos), .failed_artifacts = failed_artifacts}; @@ -182,7 +188,13 @@ class GraphTraverser { artifact_nodes, runfile_descriptions); - MaybePrintToStdout(rel_paths, artifact_nodes); + MaybePrintToStdout( + rel_paths, + artifact_nodes, + artifact_descriptions.size() == 1 + ? std::optional{artifact_descriptions.begin() + ->first} + : std::nullopt); return BuildResult{.output_paths = *output_paths, .extra_infos = std::move(infos), @@ -671,8 +683,8 @@ class GraphTraverser { void MaybePrintToStdout( std::vector const& paths, - std::vector const& artifacts) - const { + std::vector const& artifacts, + std::optional const& unique_artifact) const { if (clargs_.build.print_to_stdout) { auto const& remote = *context_.apis->remote; for (std::size_t i = 0; i < paths.size(); i++) { @@ -751,6 +763,38 @@ class GraphTraverser { "{} not a logical path of the specified target", *(clargs_.build.print_to_stdout)); } + else if (clargs_.build.print_unique) { + if (unique_artifact) { + auto const& remote = *context_.apis->remote; + std::optional info = std::nullopt; + for (std::size_t i = 0; i < paths.size(); i++) { + if (paths[i] == unique_artifact) { + info = artifacts[i]->Content().Info(); + } + } + if (info) { + if (not remote.RetrieveToFds({*info}, + {dup(fileno(stdout))}, + /*raw_tree=*/false, + &*context_.apis->local)) { + Logger::Log(logger_, + LogLevel::Error, + "Failed to retrieve {}", + *unique_artifact); + } + } + else { + Logger::Log(logger_, + LogLevel::Error, + "Failed to obtain object information for {}", + *unique_artifact); + } + return; + } + Logger::Log(logger_, + LogLevel::Info, + "Target does not have precisely one artifact."); + } } }; -- cgit v1.2.3