summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/remote/bazel
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-06-19 12:42:21 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-06-26 17:57:29 +0200
commit5e3cc5a7a38e93159a81b940b19ced879a2d280c (patch)
tree7c2d51f424961f14ee7de758c68b2d59a5947930 /src/buildtool/execution_api/remote/bazel
parent3865c8556bde5e614dc1e8c72f83fa1ed65abcd9 (diff)
downloadjustbuild-5e3cc5a7a38e93159a81b940b19ced879a2d280c.tar.gz
Execution response: Add output symlink paths
Diffstat (limited to 'src/buildtool/execution_api/remote/bazel')
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_response.cpp83
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_response.hpp10
2 files changed, 78 insertions, 15 deletions
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp
index 9889d8ed..05ff0c9a 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp
@@ -41,12 +41,36 @@ auto BazelResponse::ReadStringBlob(bazel_re::Digest const& id) noexcept
return blobs[0].data;
}
-auto BazelResponse::Artifacts() const noexcept -> ArtifactInfos {
+auto BazelResponse::Artifacts() noexcept -> ArtifactInfos {
+ return ArtifactsWithDirSymlinks().first;
+}
+
+auto BazelResponse::ArtifactsWithDirSymlinks() noexcept
+ -> std::pair<ArtifactInfos, DirSymlinks> {
+ // make sure to populate only once
+ populated_ = Populate();
+ if (not populated_) {
+ return {};
+ }
+ return std::pair(artifacts_, dir_symlinks_);
+}
+
+auto BazelResponse::Populate() noexcept -> bool {
+ if (populated_) {
+ return true;
+ }
ArtifactInfos artifacts{};
auto const& action_result = output_.action_result;
artifacts.reserve(
- static_cast<std::size_t>(action_result.output_files().size()) +
- static_cast<std::size_t>(action_result.output_directories().size()));
+ static_cast<std::size_t>(action_result.output_files_size()) +
+ static_cast<std::size_t>(action_result.output_file_symlinks_size()) +
+ static_cast<std::size_t>(
+ action_result.output_directory_symlinks_size()) +
+ static_cast<std::size_t>(action_result.output_directories_size()));
+
+ DirSymlinks dir_symlinks{};
+ dir_symlinks.reserve(static_cast<std::size_t>(
+ action_result.output_directory_symlinks_size()));
// collect files and store them
for (auto const& file : action_result.output_files()) {
@@ -58,7 +82,34 @@ auto BazelResponse::Artifacts() const noexcept -> ArtifactInfos {
? ObjectType::Executable
: ObjectType::File});
} catch (...) {
- return {};
+ return false;
+ }
+ }
+
+ // collect all symlinks and store them
+ for (auto const& link : action_result.output_file_symlinks()) {
+ try {
+ artifacts.emplace(
+ link.path(),
+ Artifact::ObjectInfo{
+ .digest =
+ ArtifactDigest::Create<ObjectType::File>(link.target()),
+ .type = ObjectType::Symlink});
+ } catch (...) {
+ return false;
+ }
+ }
+ for (auto const& link : action_result.output_directory_symlinks()) {
+ try {
+ artifacts.emplace(
+ link.path(),
+ Artifact::ObjectInfo{
+ .digest =
+ ArtifactDigest::Create<ObjectType::File>(link.target()),
+ .type = ObjectType::Symlink});
+ dir_symlinks.emplace(link.path()); // add it to set
+ } catch (...) {
+ return false;
}
}
@@ -73,10 +124,12 @@ auto BazelResponse::Artifacts() const noexcept -> ArtifactInfos {
.digest = ArtifactDigest{tree.tree_digest()},
.type = ObjectType::Tree});
} catch (...) {
- return {};
+ return false;
}
}
- return artifacts;
+ artifacts_ = std::move(artifacts);
+ dir_symlinks_ = std::move(dir_symlinks);
+ return true;
}
// obtain tree digests for output directories
@@ -98,29 +151,31 @@ auto BazelResponse::Artifacts() const noexcept -> ArtifactInfos {
auto tree = BazelMsgFactory::MessageFromString<bazel_re::Tree>(
tree_blob.data);
if (not tree) {
- return {};
+ return false;
}
- // The server does not store the Directory messages it just has
- // sent us as part of the Tree message. If we want to be able to
- // use the Directories as inputs for actions, we have to upload
- // them manually.
+ // The server does not store the Directory messages it just
+ // has sent us as part of the Tree message. If we want to be
+ // able to use the Directories as inputs for actions, we
+ // have to upload them manually.
auto root_digest = UploadTreeMessageDirectories(*tree);
if (not root_digest) {
- return {};
+ return false;
}
artifacts.emplace(
action_result.output_directories(pos).path(),
Artifact::ObjectInfo{.digest = *root_digest,
.type = ObjectType::Tree});
} catch (...) {
- return {};
+ return false;
}
++pos;
}
tree_blobs = blob_reader.Next();
}
- return artifacts;
+ artifacts_ = std::move(artifacts);
+ dir_symlinks_ = std::move(dir_symlinks);
+ return true;
}
auto BazelResponse::UploadTreeMessageDirectories(
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_response.hpp b/src/buildtool/execution_api/remote/bazel/bazel_response.hpp
index 048c6291..358c98c8 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_response.hpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_response.hpp
@@ -56,12 +56,18 @@ class BazelResponse final : public IExecutionResponse {
return action_id_;
}
- auto Artifacts() const noexcept -> ArtifactInfos final;
+ auto Artifacts() noexcept -> ArtifactInfos final;
+
+ auto ArtifactsWithDirSymlinks() noexcept
+ -> std::pair<ArtifactInfos, DirSymlinks> final;
private:
std::string action_id_{};
std::shared_ptr<BazelNetwork> const network_{};
BazelExecutionClient::ExecutionOutput output_{};
+ ArtifactInfos artifacts_{};
+ DirSymlinks dir_symlinks_{};
+ bool populated_{false};
BazelResponse(std::string action_id,
std::shared_ptr<BazelNetwork> network,
@@ -78,6 +84,8 @@ class BazelResponse final : public IExecutionResponse {
return id.size_bytes() != 0;
}
+ [[nodiscard]] auto Populate() noexcept -> bool;
+
[[nodiscard]] auto UploadTreeMessageDirectories(
bazel_re::Tree const& tree) const -> std::optional<ArtifactDigest>;
};