diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-07-18 09:53:46 +0200 |
---|---|---|
committer | Sascha Roloff <sascha.roloff@huawei.com> | 2022-08-05 14:41:31 +0200 |
commit | a23aa232645364b2403f380c9e2bb50edf617cb0 (patch) | |
tree | 7b917f4fc085236b3f6fdc90a7737fd02b6bfca6 | |
parent | c0422f390f9f30b7cc470a814e209bedc7e87f1a (diff) | |
download | justbuild-a23aa232645364b2403f380c9e2bb50edf617cb0.tar.gz |
CLI: Add flag for dumping raw tree objects
-rw-r--r-- | src/buildtool/common/cli.hpp | 5 | ||||
-rw-r--r-- | src/buildtool/execution_api/common/execution_api.hpp | 9 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_api.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_api.cpp | 3 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_api.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/graph_traverser/graph_traverser.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 3 | ||||
-rwxr-xr-x | test/buildtool/execution_engine/executor/executor.test.cpp | 4 |
8 files changed, 23 insertions, 10 deletions
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index 3966f888..46af6598 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -97,6 +97,7 @@ struct RebuildArguments { struct FetchArguments { std::string object_id{}; std::optional<std::filesystem::path> output_path{}; + bool raw_tree{}; }; /// \brief Arguments required for running from graph file. @@ -377,6 +378,10 @@ static inline auto SetupFetchArguments( }, "Install path for the artifact. (omit to dump to stdout)") ->type_name("PATH"); + + app->add_flag("--raw-tree", + clargs->raw_tree, + "Dump raw tree object (omit pretty printting)"); } static inline auto SetupGraphArguments( diff --git a/src/buildtool/execution_api/common/execution_api.hpp b/src/buildtool/execution_api/common/execution_api.hpp index 816b5031..661ecbf3 100644 --- a/src/buildtool/execution_api/common/execution_api.hpp +++ b/src/buildtool/execution_api/common/execution_api.hpp @@ -52,11 +52,14 @@ class IExecutionApi { -> bool = 0; /// \brief Retrieve artifacts from CAS and write to file descriptors. - /// Tree artifacts are not resolved and instead the raw protobuf message - /// will be written to fd. + /// Tree artifacts are not resolved and instead the tree object will be + /// pretty-printed before writing to fd. If `raw_tree` is set, pretty + /// printing will be omitted and the raw tree object will be written + /// instead. [[nodiscard]] virtual auto RetrieveToFds( std::vector<Artifact::ObjectInfo> const& artifacts_info, - std::vector<int> const& fds) noexcept -> bool = 0; + std::vector<int> const& fds, + bool raw_tree) noexcept -> bool = 0; /// \brief Upload blobs to CAS. Uploads only the blobs that are not yet /// available in CAS, unless `skip_find_missing` is specified. diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index 72b7e28c..c1cb1c57 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -74,7 +74,8 @@ class LocalApi final : public IExecutionApi { [[nodiscard]] auto RetrieveToFds( std::vector<Artifact::ObjectInfo> const& artifacts_info, - std::vector<int> const& fds) noexcept -> bool final { + std::vector<int> const& fds, + bool /*raw_tree*/) noexcept -> bool final { if (artifacts_info.size() != fds.size()) { Logger::Log(LogLevel::Error, "different number of digests and file descriptors."); diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index 51e85176..c2893917 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -115,7 +115,8 @@ auto BazelApi::CreateAction( [[nodiscard]] auto BazelApi::RetrieveToFds( std::vector<Artifact::ObjectInfo> const& artifacts_info, - std::vector<int> const& fds) noexcept -> bool { + std::vector<int> const& fds, + bool /*raw_tree*/) noexcept -> bool { if (artifacts_info.size() != fds.size()) { Logger::Log(LogLevel::Error, "different number of digests and file descriptors."); diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp index f953618e..d9619d82 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp @@ -45,7 +45,8 @@ class BazelApi final : public IExecutionApi { [[nodiscard]] auto RetrieveToFds( std::vector<Artifact::ObjectInfo> const& artifacts_info, - std::vector<int> const& fds) noexcept -> bool final; + std::vector<int> const& fds, + bool raw_tree) noexcept -> bool final; [[nodiscard]] auto Upload(BlobContainer const& blobs, bool skip_find_missing) noexcept -> bool final; diff --git a/src/buildtool/graph_traverser/graph_traverser.hpp b/src/buildtool/graph_traverser/graph_traverser.hpp index e61a7280..18a055a8 100644 --- a/src/buildtool/graph_traverser/graph_traverser.hpp +++ b/src/buildtool/graph_traverser/graph_traverser.hpp @@ -610,7 +610,8 @@ class GraphTraverser { auto info = artifacts[i]->Content().Info(); if (info) { if (not api_->RetrieveToFds({*info}, - {dup(fileno(stdout))})) { + {dup(fileno(stdout))}, + /*raw_tree=*/false)) { Logger::Log(LogLevel::Error, "Failed to retrieve {}", *(clargs_.build.print_to_stdout)); diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index b0d17bbd..953504ca 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -1189,7 +1189,8 @@ void ReportTaintedness(const AnalysisResult& result) { output_path.string()); } else { // dump to stdout - if (not api->RetrieveToFds({object_info}, {dup(fileno(stdout))})) { + if (not api->RetrieveToFds( + {object_info}, {dup(fileno(stdout))}, clargs.raw_tree)) { Logger::Log(LogLevel::Error, "failed to dump artifact."); return false; } diff --git a/test/buildtool/execution_engine/executor/executor.test.cpp b/test/buildtool/execution_engine/executor/executor.test.cpp index 0ffe5e4d..1a9b90b2 100755 --- a/test/buildtool/execution_engine/executor/executor.test.cpp +++ b/test/buildtool/execution_engine/executor/executor.test.cpp @@ -126,8 +126,8 @@ class TestApi : public IExecutionApi { return false; // not needed by Executor } auto RetrieveToFds(std::vector<Artifact::ObjectInfo> const& /*unused*/, - std::vector<int> const& /*unused*/) noexcept - -> bool final { + std::vector<int> const& /*unused*/, + bool /*unused*/) noexcept -> bool final { return false; // not needed by Executor } auto Upload(BlobContainer const& blobs, bool /*unused*/) noexcept |