From daca274041e31636f08927b0cebc56fd33c7bbdf Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 7 Jul 2022 17:28:29 +0200 Subject: LocalExecution: Use Git tree format - LocalStorage Add tree CAS and support reading Git trees - LocalAction: Create Git tree for output directory - LocalApi: Support availability and upload of Git trees - LocalStorage: Support dumping tree to stream in native mode --- src/buildtool/execution_api/local/local_action.cpp | 71 ++++++++++++++++------ 1 file changed, 52 insertions(+), 19 deletions(-) (limited to 'src/buildtool/execution_api/local/local_action.cpp') diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp index 3ccc58eb..331aaaa5 100644 --- a/src/buildtool/execution_api/local/local_action.cpp +++ b/src/buildtool/execution_api/local/local_action.cpp @@ -235,26 +235,59 @@ auto LocalAction::CollectOutputDir(std::filesystem::path const& exec_path, Logger::Log(LogLevel::Error, "expected directory at {}", local_path); return std::nullopt; } - auto digest = BazelMsgFactory::CreateDirectoryDigestFromLocalTree( - dir_path, - [this](auto path, auto is_exec) { - return storage_->StoreBlob(path, is_exec); - }, - [this](auto bytes, auto dir) -> std::optional { - auto digest = storage_->StoreBlob(bytes); - if (digest and not tree_map_->HasTree(*digest)) { - auto tree = tree_map_->CreateTree(); - if (not BazelMsgFactory::ReadObjectInfosFromDirectory( - dir, - [&tree](auto path, auto info) { - return tree.AddInfo(path, info); - }) or - not tree_map_->AddTree(*digest, std::move(tree))) { - return std::nullopt; + std::optional digest{std::nullopt}; + if (Compatibility::IsCompatible()) { + digest = BazelMsgFactory::CreateDirectoryDigestFromLocalTree( + dir_path, + [this](auto path, auto is_exec) { + return storage_->StoreBlob(path, is_exec); + }, + [this](auto bytes, auto dir) -> std::optional { + auto digest = storage_->StoreBlob(bytes); + if (digest and not tree_map_->HasTree(*digest)) { + auto tree = tree_map_->CreateTree(); + if (not BazelMsgFactory::ReadObjectInfosFromDirectory( + dir, + [&tree](auto path, auto info) { + return tree.AddInfo(path, info); + }) or + not tree_map_->AddTree(*digest, std::move(tree))) { + return std::nullopt; + } } - } - return digest; - }); + return digest; + }); + } + else { + digest = BazelMsgFactory::CreateGitTreeDigestFromLocalTree( + dir_path, + [this](auto path, auto is_exec) { + return storage_->StoreBlob(path, is_exec); + }, + [this](auto bytes, + auto entries) -> std::optional { + auto digest = storage_->StoreTree(bytes); + if (digest and not tree_map_->HasTree(*digest)) { + auto tree = tree_map_->CreateTree(); + for (auto const& [raw_id, es] : entries) { + auto id = ToHexString(raw_id); + for (auto const& entry : es) { + auto info = Artifact::ObjectInfo{ + ArtifactDigest{ + id, 0, entry.type == ObjectType::Tree}, + entry.type}; + if (not tree.AddInfo(entry.name, info)) { + return std::nullopt; + } + } + } + if (not tree_map_->AddTree(*digest, std::move(tree))) { + return std::nullopt; + } + } + return digest; + }); + } if (digest) { auto out_dir = bazel_re::OutputDirectory{}; out_dir.set_path(local_path); -- cgit v1.2.3