diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-21 15:18:58 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-03-24 09:25:05 +0100 |
commit | f192705cb4834252507d228e7d6e0a38095976e3 (patch) | |
tree | 83040a418bc8c700cd5234d8d60f0497e2b7631f /src | |
parent | fc0c842eb2e938c7de405e365ff320eb28e04bc7 (diff) | |
download | justbuild-f192705cb4834252507d228e7d6e0a38095976e3.tar.gz |
ExecutionApi: Return TmpDir
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/execution_api/common/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/execution_api/common/api_bundle.cpp | 6 | ||||
-rw-r--r-- | src/buildtool/execution_api/common/execution_api.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_api.cpp | 4 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_api.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_api.cpp | 9 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_api.hpp | 6 | ||||
-rw-r--r-- | src/buildtool/execution_api/serve/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/execution_api/serve/mr_local_api.cpp | 4 | ||||
-rw-r--r-- | src/buildtool/execution_api/serve/mr_local_api.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/execution_engine/executor/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/execution_engine/executor/executor.hpp | 13 | ||||
-rw-r--r-- | src/other_tools/just_mr/fetch.cpp | 3 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup.cpp | 3 |
15 files changed, 50 insertions, 11 deletions
diff --git a/src/buildtool/execution_api/common/TARGETS b/src/buildtool/execution_api/common/TARGETS index 3ffd508f..b13ac8b5 100644 --- a/src/buildtool/execution_api/common/TARGETS +++ b/src/buildtool/execution_api/common/TARGETS @@ -23,6 +23,7 @@ , ["src/buildtool/file_system", "object_type"] , ["src/buildtool/logging", "logging"] , ["src/utils/cpp", "expected"] + , ["src/utils/cpp", "tmp_dir"] ] , "private-deps": [ ["@", "json", "", "json"] diff --git a/src/buildtool/execution_api/common/api_bundle.cpp b/src/buildtool/execution_api/common/api_bundle.cpp index 7ab06e81..391e1343 100644 --- a/src/buildtool/execution_api/common/api_bundle.cpp +++ b/src/buildtool/execution_api/common/api_bundle.cpp @@ -43,7 +43,8 @@ auto ApiBundle::Create( remote_context->auth, remote_context->retry_config, config, - local_context->storage_config->hash_function); + local_context->storage_config->hash_function, + local_api->GetTempSpace()); } return ApiBundle{.local = std::move(local_api), .remote = std::move(remote_api)}; @@ -63,7 +64,8 @@ auto ApiBundle::MakeRemote( authentication, retry_config, config, - HashFunction{local->GetHashType()}); + HashFunction{local->GetHashType()}, + local->GetTempSpace()); } return local; } diff --git a/src/buildtool/execution_api/common/execution_api.hpp b/src/buildtool/execution_api/common/execution_api.hpp index 43a7e581..001c9189 100644 --- a/src/buildtool/execution_api/common/execution_api.hpp +++ b/src/buildtool/execution_api/common/execution_api.hpp @@ -30,6 +30,7 @@ #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/execution_action.hpp" #include "src/buildtool/execution_engine/dag/dag.hpp" +#include "src/utils/cpp/tmp_dir.hpp" /// \brief Abstract remote execution API /// Can be used to create actions. @@ -156,6 +157,8 @@ class IExecutionApi { [[nodiscard]] virtual auto GetHashType() const noexcept -> HashFunction::Type = 0; + + [[nodiscard]] virtual auto GetTempSpace() const noexcept -> TmpDir::Ptr = 0; }; #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_EXECUTION_APIHPP diff --git a/src/buildtool/execution_api/local/local_api.cpp b/src/buildtool/execution_api/local/local_api.cpp index 81fb4bed..eef05021 100644 --- a/src/buildtool/execution_api/local/local_api.cpp +++ b/src/buildtool/execution_api/local/local_api.cpp @@ -333,3 +333,7 @@ auto LocalApi::SpliceBlob(ArtifactDigest const& blob_digest, auto LocalApi::GetHashType() const noexcept -> HashFunction::Type { return local_context_.storage_config->hash_function.GetType(); } + +auto LocalApi::GetTempSpace() const noexcept -> TmpDir::Ptr { + return local_context_.storage_config->CreateTypedTmpDir("api_space"); +} diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index 142da6fb..e2374258 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -33,6 +33,7 @@ #include "src/buildtool/execution_api/git/git_api.hpp" #include "src/buildtool/execution_api/local/context.hpp" #include "src/buildtool/execution_engine/dag/dag.hpp" +#include "src/utils/cpp/tmp_dir.hpp" class LocalApi final : public IExecutionApi { public: @@ -105,6 +106,8 @@ class LocalApi final : public IExecutionApi { [[nodiscard]] auto GetHashType() const noexcept -> HashFunction::Type final; + [[nodiscard]] auto GetTempSpace() const noexcept -> TmpDir::Ptr final; + private: LocalContext const& local_context_; std::optional<GitApi> const git_api_; diff --git a/src/buildtool/execution_api/remote/TARGETS b/src/buildtool/execution_api/remote/TARGETS index c6a8c4c4..7fccc2c6 100644 --- a/src/buildtool/execution_api/remote/TARGETS +++ b/src/buildtool/execution_api/remote/TARGETS @@ -85,6 +85,7 @@ , ["src/buildtool/execution_api/bazel_msg", "execution_config"] , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/execution_engine/dag", "dag"] + , ["src/utils/cpp", "tmp_dir"] ] , "stage": ["src", "buildtool", "execution_api", "remote"] , "private-deps": diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index b2f145b0..08fc8e99 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -144,7 +144,8 @@ BazelApi::BazelApi(std::string const& instance_name, gsl::not_null<Auth const*> const& auth, gsl::not_null<RetryConfig const*> const& retry_config, ExecutionConfiguration const& exec_config, - HashFunction hash_function) noexcept { + HashFunction hash_function, + TmpDir::Ptr temp_space) noexcept { network_ = std::make_shared<BazelNetwork>(instance_name, host, port, @@ -152,7 +153,7 @@ BazelApi::BazelApi(std::string const& instance_name, retry_config, exec_config, hash_function, - /*temp_space=*/nullptr); + std::move(temp_space)); } // implement move constructor in cpp, where all members are complete types @@ -605,3 +606,7 @@ auto BazelApi::CreateAction( -> HashFunction::Type { return network_->GetHashFunction().GetType(); } + +[[nodiscard]] auto BazelApi::GetTempSpace() const noexcept -> TmpDir::Ptr { + return network_->GetTempSpace(); +} diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp index 633d9d85..df60204f 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp @@ -36,6 +36,7 @@ #include "src/buildtool/execution_api/common/execution_action.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_engine/dag/dag.hpp" +#include "src/utils/cpp/tmp_dir.hpp" // forward declaration for actual implementations class BazelNetwork; @@ -49,7 +50,8 @@ class BazelApi final : public IExecutionApi { gsl::not_null<Auth const*> const& auth, gsl::not_null<RetryConfig const*> const& retry_config, ExecutionConfiguration const& exec_config, - HashFunction hash_function) noexcept; + HashFunction hash_function, + TmpDir::Ptr temp_space) noexcept; BazelApi(BazelApi const&) = delete; BazelApi(BazelApi&& other) noexcept; auto operator=(BazelApi const&) -> BazelApi& = delete; @@ -124,6 +126,8 @@ class BazelApi final : public IExecutionApi { [[nodiscard]] auto GetHashType() const noexcept -> HashFunction::Type final; + [[nodiscard]] auto GetTempSpace() const noexcept -> TmpDir::Ptr final; + private: std::shared_ptr<BazelNetwork> network_; diff --git a/src/buildtool/execution_api/serve/TARGETS b/src/buildtool/execution_api/serve/TARGETS index eadea902..5f562fac 100644 --- a/src/buildtool/execution_api/serve/TARGETS +++ b/src/buildtool/execution_api/serve/TARGETS @@ -32,6 +32,7 @@ , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/execution_api/local", "context"] , ["src/buildtool/execution_engine/dag", "dag"] + , ["src/utils/cpp", "tmp_dir"] ] , "stage": ["src", "buildtool", "execution_api", "serve"] , "private-deps": diff --git a/src/buildtool/execution_api/serve/mr_local_api.cpp b/src/buildtool/execution_api/serve/mr_local_api.cpp index 3394c270..9c58d73c 100644 --- a/src/buildtool/execution_api/serve/mr_local_api.cpp +++ b/src/buildtool/execution_api/serve/mr_local_api.cpp @@ -152,3 +152,7 @@ auto MRLocalApi::GetHashType() const noexcept -> HashFunction::Type { return compat_local_api_ == nullptr ? native_local_api_->GetHashType() : compat_local_api_->GetHashType(); } + +auto MRLocalApi::GetTempSpace() const noexcept -> TmpDir::Ptr { + return native_local_api_->GetTempSpace(); +} diff --git a/src/buildtool/execution_api/serve/mr_local_api.hpp b/src/buildtool/execution_api/serve/mr_local_api.hpp index 3ad19475..d9f323cf 100644 --- a/src/buildtool/execution_api/serve/mr_local_api.hpp +++ b/src/buildtool/execution_api/serve/mr_local_api.hpp @@ -31,6 +31,7 @@ #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_api/local/context.hpp" #include "src/buildtool/execution_engine/dag/dag.hpp" +#include "src/utils/cpp/tmp_dir.hpp" /// \brief Multi-repo-specific implementation of the abstract Execution API. /// Handles interaction between a native storage and a remote, irrespective of @@ -133,6 +134,8 @@ class MRLocalApi final : public IExecutionApi { [[nodiscard]] auto GetHashType() const noexcept -> HashFunction::Type final; + [[nodiscard]] auto GetTempSpace() const noexcept -> TmpDir::Ptr final; + private: // retain local context references to have direct access to storages gsl::not_null<LocalContext const*> native_context_; diff --git a/src/buildtool/execution_engine/executor/TARGETS b/src/buildtool/execution_engine/executor/TARGETS index 049efe44..2ac64635 100644 --- a/src/buildtool/execution_engine/executor/TARGETS +++ b/src/buildtool/execution_engine/executor/TARGETS @@ -38,6 +38,7 @@ , ["src/utils/cpp", "hex_string"] , ["src/utils/cpp", "path_rebase"] , ["src/utils/cpp", "prefix"] + , ["src/utils/cpp", "tmp_dir"] ] , "stage": ["src", "buildtool", "execution_engine", "executor"] } diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index e030d2d6..12721b01 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -72,6 +72,7 @@ #include "src/utils/cpp/hex_string.hpp" #include "src/utils/cpp/path_rebase.hpp" #include "src/utils/cpp/prefix.hpp" +#include "src/utils/cpp/tmp_dir.hpp" /// \brief Implementations for executing actions and uploading artifacts. class ExecutorImpl { @@ -133,8 +134,10 @@ class ExecutorImpl { } // get the alternative endpoint - auto alternative_api = GetAlternativeEndpoint( - merged_properties, remote_context, api.GetHashType()); + auto alternative_api = GetAlternativeEndpoint(merged_properties, + remote_context, + api.GetHashType(), + api.GetTempSpace()); if (alternative_api) { if (not api.ParallelRetrieveToCas( std::vector<Artifact::ObjectInfo>{Artifact::ObjectInfo{ @@ -758,7 +761,8 @@ class ExecutorImpl { [[nodiscard]] static auto GetAlternativeEndpoint( const ExecutionProperties& properties, const gsl::not_null<RemoteContext const*>& remote_context, - HashFunction::Type hash_type) -> std::unique_ptr<BazelApi> { + HashFunction::Type hash_type, + TmpDir::Ptr temp_space) -> std::unique_ptr<BazelApi> { for (auto const& [pred, endpoint] : remote_context->exec_config->dispatch) { bool match = true; @@ -781,7 +785,8 @@ class ExecutorImpl { remote_context->auth, remote_context->retry_config, config, - HashFunction{hash_type}); + HashFunction{hash_type}, + std::move(temp_space)); } } return nullptr; diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp index 7fafada8..0dd3a155 100644 --- a/src/other_tools/just_mr/fetch.cpp +++ b/src/other_tools/just_mr/fetch.cpp @@ -426,7 +426,8 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, &*auth_config, &*retry_config, config, - hash_fct); + hash_fct, + mr_local_api->GetTempSpace()); } bool const has_remote_api = remote_api != nullptr; diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp index 57ed0fd9..ee9781c9 100644 --- a/src/other_tools/just_mr/setup.cpp +++ b/src/other_tools/just_mr/setup.cpp @@ -234,7 +234,8 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, &*auth_config, &*retry_config, config, - hash_fct); + hash_fct, + mr_local_api->GetTempSpace()); } bool const has_remote_api = remote_api != nullptr; |