diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-11-24 11:31:42 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-11-27 15:03:20 +0100 |
commit | cf04253130030bc28866d10aa1f8fe1353643d42 (patch) | |
tree | ef7049624771866455105a8dab7b001840139701 /src/buildtool/execution_engine/executor | |
parent | bc09302c2772c979c45ecc716c36e4a70bb484ac (diff) | |
download | justbuild-cf04253130030bc28866d10aa1f8fe1353643d42.tar.gz |
Refactoring RepositoryConfig
With the introduction of 'just serve', export targets can now be
built also independently from one another based on their
corresponding minimal repository configuration, as stored in the
target cache key.
In this context, this commit changes the RepositoryConfig usage
from one global (static) instance to pointers passed as necessary
throughout the code.
Diffstat (limited to 'src/buildtool/execution_engine/executor')
-rw-r--r-- | src/buildtool/execution_engine/executor/executor.hpp | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index 7d38d91c..986d17f8 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -196,6 +196,7 @@ class ExecutorImpl { [[nodiscard]] static auto VerifyOrUploadArtifact( Logger const& logger, gsl::not_null<DependencyGraph::ArtifactNode const*> const& artifact, + gsl::not_null<RepositoryConfig*> const& repo_config, gsl::not_null<IExecutionApi*> const& remote_api, gsl::not_null<IExecutionApi*> const& local_api) noexcept -> bool { auto const object_info_opt = artifact->Content().Info(); @@ -230,6 +231,7 @@ class ExecutorImpl { if (not VerifyOrUploadKnownArtifact( remote_api, artifact->Content().Repository(), + repo_config, *object_info_opt)) { Logger::Log( LogLevel::Error, @@ -254,7 +256,8 @@ class ExecutorImpl { return oss.str(); }); auto repo = artifact->Content().Repository(); - auto new_info = UploadFile(remote_api, repo, *file_path_opt); + auto new_info = + UploadFile(remote_api, repo, repo_config, *file_path_opt); if (not new_info) { Logger::Log(LogLevel::Error, "artifact in {} could not be uploaded to CAS.", @@ -356,13 +359,14 @@ class ExecutorImpl { [[nodiscard]] static auto VerifyOrUploadGitArtifact( gsl::not_null<IExecutionApi*> const& api, std::string const& repo, + gsl::not_null<RepositoryConfig*> const& repo_config, Artifact::ObjectInfo const& info, std::string const& hash) noexcept -> bool { std::optional<std::string> content; if (NativeSupport::IsTree( static_cast<bazel_re::Digest>(info.digest).hash())) { // if known tree is not available, recursively upload its content - auto tree = ReadGitTree(repo, hash); + auto tree = ReadGitTree(repo, repo_config, hash); if (not tree) { return false; } @@ -373,7 +377,7 @@ class ExecutorImpl { } else { // if known blob is not available, read and upload it - content = ReadGitBlob(repo, hash); + content = ReadGitBlob(repo, repo_config, hash); } if (not content) { return false; @@ -385,34 +389,34 @@ class ExecutorImpl { return api->Upload(container, /*skip_find_missing=*/true); } - [[nodiscard]] static auto ReadGitBlob(std::string const& repo, - std::string const& hash) noexcept - -> std::optional<std::string> { - auto const& repo_config = RepositoryConfig::Instance(); + [[nodiscard]] static auto ReadGitBlob( + std::string const& repo, + gsl::not_null<RepositoryConfig*> const& repo_config, + std::string const& hash) noexcept -> std::optional<std::string> { std::optional<std::string> blob{}; - if (auto const* ws_root = repo_config.WorkspaceRoot(repo)) { + if (auto const* ws_root = repo_config->WorkspaceRoot(repo)) { // try to obtain blob from local workspace's Git CAS, if any blob = ws_root->ReadBlob(hash); } if (not blob) { // try to obtain blob from global Git CAS, if any - blob = repo_config.ReadBlobFromGitCAS(hash); + blob = repo_config->ReadBlobFromGitCAS(hash); } return blob; } - [[nodiscard]] static auto ReadGitTree(std::string const& repo, - std::string const& hash) noexcept - -> std::optional<GitTree> { - auto const& repo_config = RepositoryConfig::Instance(); + [[nodiscard]] static auto ReadGitTree( + std::string const& repo, + gsl::not_null<RepositoryConfig*> const& repo_config, + std::string const& hash) noexcept -> std::optional<GitTree> { std::optional<GitTree> tree{}; - if (auto const* ws_root = repo_config.WorkspaceRoot(repo)) { + if (auto const* ws_root = repo_config->WorkspaceRoot(repo)) { // try to obtain tree from local workspace's Git CAS, if any tree = ws_root->ReadTree(hash); } if (not tree) { // try to obtain tree from global Git CAS, if any - tree = repo_config.ReadTreeFromGitCAS(hash); + tree = repo_config->ReadTreeFromGitCAS(hash); } return tree; } @@ -420,35 +424,40 @@ class ExecutorImpl { /// \brief Lookup blob via digest in local git repositories and upload. /// \param api The endpoint used for uploading /// \param repo The global repository name, the artifact belongs to + /// \param repo_config Configuration specifying the workspace root /// \param info The info of the object /// \returns true on success [[nodiscard]] static auto VerifyOrUploadKnownArtifact( gsl::not_null<IExecutionApi*> const& api, std::string const& repo, + gsl::not_null<RepositoryConfig*> const& repo_config, Artifact::ObjectInfo const& info) noexcept -> bool { if (Compatibility::IsCompatible()) { auto opt = Compatibility::GetGitEntry(info.digest.hash()); if (opt) { auto const& [git_sha1_hash, comp_repo] = *opt; return VerifyOrUploadGitArtifact( - api, comp_repo, info, git_sha1_hash); + api, comp_repo, repo_config, info, git_sha1_hash); } return false; } - return VerifyOrUploadGitArtifact(api, repo, info, info.digest.hash()); + return VerifyOrUploadGitArtifact( + api, repo, repo_config, info, info.digest.hash()); } /// \brief Lookup file via path in local workspace root and upload. /// \param api The endpoint used for uploading /// \param repo The global repository name, the artifact belongs to + /// \param repo_config Configuration specifying the workspace root /// \param file_path The path of the file to be read /// \returns The computed object info on success [[nodiscard]] static auto UploadFile( gsl::not_null<IExecutionApi*> const& api, std::string const& repo, + gsl::not_null<RepositoryConfig*> const& repo_config, std::filesystem::path const& file_path) noexcept -> std::optional<Artifact::ObjectInfo> { - auto const* ws_root = RepositoryConfig::Instance().WorkspaceRoot(repo); + auto const* ws_root = repo_config->WorkspaceRoot(repo); if (ws_root == nullptr) { return std::nullopt; } @@ -633,11 +642,13 @@ class Executor { public: explicit Executor( + gsl::not_null<RepositoryConfig*> repo_config, IExecutionApi* local_api, IExecutionApi* remote_api, std::map<std::string, std::string> properties, std::chrono::milliseconds timeout = IExecutionAction::kDefaultTimeout) - : local_api_{local_api}, + : repo_config_{repo_config}, + local_api_{local_api}, remote_api_{remote_api}, properties_{std::move(properties)}, timeout_{timeout} {} @@ -666,16 +677,18 @@ class Executor { /// \brief Check artifact is available to the CAS or upload it. /// \param[in] artifact The artifact to process. + /// \param[in] repo_config The repository configuration to use /// \returns True if artifact is available or uploaded, false otherwise [[nodiscard]] auto Process( gsl::not_null<DependencyGraph::ArtifactNode const*> const& artifact) const noexcept -> bool { Logger logger("artifact:" + ToHexString(artifact->Content().Id())); return Impl::VerifyOrUploadArtifact( - logger, artifact, remote_api_, local_api_); + logger, artifact, repo_config_, remote_api_, local_api_); } private: + gsl::not_null<RepositoryConfig*> repo_config_; gsl::not_null<IExecutionApi*> local_api_; gsl::not_null<IExecutionApi*> remote_api_; std::map<std::string, std::string> properties_; @@ -694,12 +707,14 @@ class Rebuilder { /// \param properties Platform properties for execution. /// \param timeout Timeout for action execution. Rebuilder( + gsl::not_null<RepositoryConfig*> repo_config, IExecutionApi* local_api, IExecutionApi* remote_api, IExecutionApi* api_cached, std::map<std::string, std::string> properties, std::chrono::milliseconds timeout = IExecutionAction::kDefaultTimeout) - : local_api_{local_api}, + : repo_config_{repo_config}, + local_api_{local_api}, remote_api_{remote_api}, api_cached_{api_cached}, properties_{std::move(properties)}, @@ -749,7 +764,7 @@ class Rebuilder { const noexcept -> bool { Logger logger("artifact:" + ToHexString(artifact->Content().Id())); return Impl::VerifyOrUploadArtifact( - logger, artifact, remote_api_, local_api_); + logger, artifact, repo_config_, remote_api_, local_api_); } [[nodiscard]] auto DumpFlakyActions() const noexcept -> nlohmann::json { @@ -765,6 +780,7 @@ class Rebuilder { } private: + gsl::not_null<RepositoryConfig*> repo_config_; gsl::not_null<IExecutionApi*> local_api_; gsl::not_null<IExecutionApi*> remote_api_; gsl::not_null<IExecutionApi*> api_cached_; |