diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-05-23 11:43:07 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-06-04 14:34:44 +0200 |
commit | e5010e47df602404d332d9686c04fa12358e3644 (patch) | |
tree | 7a4e92afd9186f0206a726a3c45d8d0be9cd1cce /src/buildtool | |
parent | ed25b0f77690abe1f04e4cdcb284b7e17208d169 (diff) | |
download | justbuild-e5010e47df602404d332d9686c04fa12358e3644.tar.gz |
FileRoot: Give git-based roots access to storage config
Diffstat (limited to 'src/buildtool')
-rw-r--r-- | src/buildtool/computed_roots/evaluate.cpp | 10 | ||||
-rw-r--r-- | src/buildtool/file_system/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 36 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 50 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/target.cpp | 2 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/target_utils.cpp | 16 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/target_utils.hpp | 2 |
7 files changed, 68 insertions, 49 deletions
diff --git a/src/buildtool/computed_roots/evaluate.cpp b/src/buildtool/computed_roots/evaluate.cpp index a5155593..d4995baa 100644 --- a/src/buildtool/computed_roots/evaluate.cpp +++ b/src/buildtool/computed_roots/evaluate.cpp @@ -241,8 +241,8 @@ void ComputeAndFill( "Root {} taken from cache to be {}", target.ToString(), root); - auto root_result = - FileRoot::FromGit(storage_config->GitRoot(), root); + auto root_result = FileRoot::FromGit( + storage_config, storage_config->GitRoot(), root); if (not root_result) { (*logger)(fmt::format("Failed to create git root for {}", root), /*fatal=*/true); @@ -345,7 +345,8 @@ void ComputeAndFill( target.ToString(), *result, log_desc); - auto root_result = FileRoot::FromGit(storage_config->GitRoot(), *result); + auto root_result = + FileRoot::FromGit(storage_config, storage_config->GitRoot(), *result); if (not root_result) { (*logger)(fmt::format("Failed to create git root for {}", *result), /*fatal=*/true); @@ -609,7 +610,8 @@ void ComputeAndFill( } if (local_tree_structure.has_value()) { - auto resolved_root = FileRoot::FromGit(native_storage_config.GitRoot(), + auto resolved_root = FileRoot::FromGit(storage_config, + native_storage_config.GitRoot(), local_tree_structure->hash()); if (not resolved_root) { return unexpected{ diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS index 13efeba3..2978397b 100644 --- a/src/buildtool/file_system/TARGETS +++ b/src/buildtool/file_system/TARGETS @@ -190,6 +190,7 @@ , ["src/buildtool/crypto", "hash_function"] , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] + , ["src/buildtool/storage", "config"] , ["src/utils/cpp", "concepts"] , ["src/utils/cpp", "expected"] , ["src/utils/cpp", "json"] diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index 45f74b3c..c625c586 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -44,6 +44,7 @@ #include "src/buildtool/file_system/precomputed_root.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/utils/cpp/concepts.hpp" #include "src/utils/cpp/expected.hpp" // Keep it to ensure fmt::format works on JSON objects @@ -337,15 +338,19 @@ class FileRoot { : root_{fs_root_t{std::move(root)}}, ignore_special_{ignore_special} {} FileRoot(gsl::not_null<GitCASPtr> const& cas, gsl::not_null<GitTreePtr> const& tree, + gsl::not_null<StorageConfig const*> const& storage_config, bool ignore_special = false) noexcept - : root_{RootGit{cas, tree}}, ignore_special_{ignore_special} {} + : root_{RootGit{cas, tree}}, + storage_config_{storage_config}, + ignore_special_{ignore_special} {} explicit FileRoot(PrecomputedRoot precomputed) : root_{std::move(precomputed)} {} - [[nodiscard]] static auto FromGit(std::filesystem::path const& repo_path, - std::string const& git_tree_id, - bool ignore_special = false) noexcept - -> std::optional<FileRoot> { + [[nodiscard]] static auto FromGit( + gsl::not_null<StorageConfig const*> const& storage_config, + std::filesystem::path const& repo_path, + std::string const& git_tree_id, + bool ignore_special = false) noexcept -> std::optional<FileRoot> { auto cas = GitCAS::Open(repo_path); if (not cas) { return std::nullopt; @@ -357,6 +362,7 @@ class FileRoot { try { return FileRoot{cas, std::make_shared<GitTree const>(std::move(*tree)), + storage_config, ignore_special}; } catch (...) { return std::nullopt; @@ -680,9 +686,11 @@ class FileRoot { /// \brief Parses a FileRoot from string. On errors, populates error_msg. /// \returns the FileRoot and optional local path (if the root is local), /// nullopt on errors. - [[nodiscard]] static auto ParseRoot(std::string const& repo, - std::string const& keyword, - nlohmann::json const& root) + [[nodiscard]] static auto ParseRoot( + gsl::not_null<StorageConfig const*> storage_config, + std::string const& repo, + std::string const& keyword, + nlohmann::json const& root) -> expected<std::pair<FileRoot, std::optional<std::filesystem::path>>, std::string> { using ResultType = @@ -721,7 +729,8 @@ class FileRoot { repo)}; } if (root.size() == 3) { - if (auto git_root = FileRoot::FromGit(root[2], root[1])) { + if (auto git_root = + FileRoot::FromGit(storage_config, root[2], root[1])) { return ResultType{std::move(*git_root), std::nullopt}; } return unexpected{fmt::format( @@ -762,8 +771,11 @@ class FileRoot { repo)}; } if (root.size() == 3) { - if (auto git_root = FileRoot::FromGit( - root[2], root[1], /*ignore_special=*/true)) { + if (auto git_root = + FileRoot::FromGit(storage_config, + root[2], + root[1], + /*ignore_special=*/true)) { return ResultType{std::move(*git_root), std::nullopt}; } return unexpected{fmt::format( @@ -800,6 +812,8 @@ class FileRoot { private: root_t root_; + // For Git-based roots, keep a pointer to the + StorageConfig const* storage_config_ = nullptr; // If set, forces lookups to ignore entries which are neither file nor // directories instead of erroring out. This means implicitly also that // there are no more fast tree lookups, i.e., tree traversal is a must. diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 2487a37f..8c122e6b 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -480,7 +480,8 @@ void SetupFileChunker() { // Set all roots and name mappings from the command-line arguments and // return the name of the main repository and main workspace path if local. -auto DetermineRoots(gsl::not_null<RepositoryConfig*> const& repository_config, +auto DetermineRoots(gsl::not_null<StorageConfig const*> const& storage_config, + gsl::not_null<RepositoryConfig*> const& repository_config, CommonArguments const& cargs, AnalysisArguments const& aargs) -> std::pair<std::string, std::optional<std::filesystem::path>> { @@ -546,8 +547,8 @@ auto DetermineRoots(gsl::not_null<RepositoryConfig*> const& repository_config, bool const is_main_repo{repo == main_repo}; auto it_ws = desc.find("workspace_root"); if (it_ws != desc.end()) { - if (auto parsed_root = - FileRoot::ParseRoot(repo, "workspace_root", *it_ws)) { + if (auto parsed_root = FileRoot::ParseRoot( + storage_config, repo, "workspace_root", *it_ws)) { auto result = *std::move(parsed_root); ws_root = std::move(result.first); if (is_main_repo and result.second.has_value()) { @@ -579,26 +580,27 @@ auto DetermineRoots(gsl::not_null<RepositoryConfig*> const& repository_config, std::exit(kExitFailure); } auto info = RepositoryConfig::RepositoryInfo{std::move(*ws_root)}; - auto parse_keyword_root = [&desc = desc, &repo = repo, is_main_repo]( - FileRoot* keyword_root, - std::string const& keyword, - auto const& keyword_carg) { - auto it = desc.find(keyword); - if (it != desc.end()) { - if (auto parsed_root = - FileRoot::ParseRoot(repo, keyword, *it)) { - (*keyword_root) = std::move(parsed_root)->first; + auto parse_keyword_root = + [&desc = desc, &repo = repo, is_main_repo, storage_config]( + FileRoot* keyword_root, + std::string const& keyword, + auto const& keyword_carg) { + auto it = desc.find(keyword); + if (it != desc.end()) { + if (auto parsed_root = FileRoot::ParseRoot( + storage_config, repo, keyword, *it)) { + (*keyword_root) = std::move(parsed_root)->first; + } + else { + Logger::Log(LogLevel::Error, parsed_root.error()); + std::exit(kExitFailure); + } } - else { - Logger::Log(LogLevel::Error, parsed_root.error()); - std::exit(kExitFailure); - } - } - if (is_main_repo and keyword_carg) { - *keyword_root = FileRoot{*keyword_carg}; - } - }; + if (is_main_repo and keyword_carg) { + *keyword_root = FileRoot{*keyword_carg}; + } + }; info.target_root = info.workspace_root; parse_keyword_root(&info.target_root, "target_root", aargs.target_root); @@ -1038,8 +1040,10 @@ auto main(int argc, char* argv[]) -> int { } #endif // BOOTSTRAP_BUILD_TOOL - auto [main_repo, main_ws_root] = - DetermineRoots(&repo_config, arguments.common, arguments.analysis); + auto [main_repo, main_ws_root] = DetermineRoots(&*storage_config, + &repo_config, + arguments.common, + arguments.analysis); std::size_t eval_root_jobs = std::lround(std::ceil(std::sqrt(arguments.common.jobs))); diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp index 49825a6e..6df2382e 100644 --- a/src/buildtool/serve_api/serve_service/target.cpp +++ b/src/buildtool/serve_api/serve_service/target.cpp @@ -416,7 +416,7 @@ auto TargetService::ServeTarget( RepositoryConfig repository_config{}; std::string const main_repo{"0"}; // known predefined main repository name if (auto msg = DetermineRoots(serve_config_, - *local_context_.storage_config, + local_context_.storage_config, main_repo, *repo_config_path, &repository_config, diff --git a/src/buildtool/serve_api/serve_service/target_utils.cpp b/src/buildtool/serve_api/serve_service/target_utils.cpp index 433c2961..3fd98242 100644 --- a/src/buildtool/serve_api/serve_service/target_utils.cpp +++ b/src/buildtool/serve_api/serve_service/target_utils.cpp @@ -66,7 +66,7 @@ auto GetServingRepository(RemoteServeConfig const& serve_config, } auto DetermineRoots(RemoteServeConfig const& serve_config, - StorageConfig const& storage_config, + gsl::not_null<StorageConfig const*> storage_config, std::string const& main_repo, std::filesystem::path const& repo_config_path, gsl::not_null<RepositoryConfig*> const& repository_config, @@ -97,15 +97,12 @@ auto DetermineRoots(RemoteServeConfig const& serve_config, for (auto const& [repo, desc] : repos.items()) { // root parser auto parse_keyword_root = - [&serve_config, - &storage_config, - &desc = desc, - &repo = repo, - logger]( + [&serve_config, storage_config, &desc = desc, &repo = repo, logger]( std::string const& keyword) -> expected<FileRoot, std::string> { auto it = desc.find(keyword); if (it != desc.end()) { - auto parsed_root = FileRoot::ParseRoot(repo, keyword, *it); + auto parsed_root = + FileRoot::ParseRoot(storage_config, repo, keyword, *it); if (not parsed_root) { return unexpected{std::move(parsed_root).error()}; } @@ -120,14 +117,15 @@ auto DetermineRoots(RemoteServeConfig const& serve_config, // find the serving repository for the root tree auto tree_id = *parsed_root->first.GetAbsentTreeId(); auto repo_path = GetServingRepository( - serve_config, storage_config, tree_id, logger); + serve_config, *storage_config, tree_id, logger); if (not repo_path) { return unexpected{fmt::format( "{} tree {} is not known", keyword, tree_id)}; } // set the root as present if (auto root = - FileRoot::FromGit(*repo_path, + FileRoot::FromGit(storage_config, + *repo_path, tree_id, parsed_root->first.IgnoreSpecial())) { return *std::move(root); diff --git a/src/buildtool/serve_api/serve_service/target_utils.hpp b/src/buildtool/serve_api/serve_service/target_utils.hpp index 731b67f5..8ec32782 100644 --- a/src/buildtool/serve_api/serve_service/target_utils.hpp +++ b/src/buildtool/serve_api/serve_service/target_utils.hpp @@ -46,7 +46,7 @@ /// \returns nullopt on success, error message as a string otherwise. [[nodiscard]] auto DetermineRoots( RemoteServeConfig const& serve_config, - StorageConfig const& storage_config, + gsl::not_null<StorageConfig const*> storage_config, std::string const& main_repo, std::filesystem::path const& repo_config_path, gsl::not_null<RepositoryConfig*> const& repository_config, |