summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/local
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/local
parent3865c8556bde5e614dc1e8c72f83fa1ed65abcd9 (diff)
downloadjustbuild-5e3cc5a7a38e93159a81b940b19ced879a2d280c.tar.gz
Execution response: Add output symlink paths
Diffstat (limited to 'src/buildtool/execution_api/local')
-rw-r--r--src/buildtool/execution_api/local/local_response.hpp96
1 files changed, 76 insertions, 20 deletions
diff --git a/src/buildtool/execution_api/local/local_response.hpp b/src/buildtool/execution_api/local/local_response.hpp
index 7faa5619..135897d8 100644
--- a/src/buildtool/execution_api/local/local_response.hpp
+++ b/src/buildtool/execution_api/local/local_response.hpp
@@ -63,14 +63,55 @@ class LocalResponse final : public IExecutionResponse {
return action_id_;
}
- auto Artifacts() const noexcept -> ArtifactInfos final {
+ auto Artifacts() noexcept -> ArtifactInfos final {
+ return ArtifactsWithDirSymlinks().first;
+ }
+
+ auto ArtifactsWithDirSymlinks() noexcept
+ -> std::pair<ArtifactInfos, DirSymlinks> final {
+ // make sure to populate only once
+ populated_ = Populate();
+ if (not populated_) {
+ return {};
+ }
+ return std::pair(artifacts_, dir_symlinks_);
+ };
+
+ private:
+ std::string action_id_{};
+ LocalAction::Output output_{};
+ gsl::not_null<Storage const*> storage_;
+ ArtifactInfos artifacts_{};
+ DirSymlinks dir_symlinks_{};
+ bool populated_{false};
+
+ explicit LocalResponse(
+ std::string action_id,
+ LocalAction::Output output,
+ gsl::not_null<Storage const*> const& storage) noexcept
+ : action_id_{std::move(action_id)},
+ output_{std::move(output)},
+ storage_{storage} {}
+
+ [[nodiscard]] auto Populate() noexcept -> bool {
+ if (populated_) {
+ return true;
+ }
ArtifactInfos artifacts{};
auto const& action_result = output_.action;
artifacts.reserve(
- static_cast<std::size_t>(action_result.output_files().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()) {
try {
@@ -81,7 +122,34 @@ class LocalResponse final : public IExecutionResponse {
.type = file.is_executable() ? 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;
}
}
@@ -94,25 +162,13 @@ class LocalResponse final : public IExecutionResponse {
.digest = ArtifactDigest{dir.tree_digest()},
.type = ObjectType::Tree});
} catch (...) {
- return {};
+ return false;
}
}
-
- return artifacts;
- };
-
- private:
- std::string action_id_{};
- LocalAction::Output output_{};
- gsl::not_null<Storage const*> storage_;
-
- explicit LocalResponse(
- std::string action_id,
- LocalAction::Output output,
- gsl::not_null<Storage const*> const& storage) noexcept
- : action_id_{std::move(action_id)},
- output_{std::move(output)},
- storage_{storage} {}
+ artifacts_ = std::move(artifacts);
+ dir_symlinks_ = std::move(dir_symlinks);
+ return true;
+ }
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_LOCAL_RESPONSE_HPP