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 | |
parent | ed25b0f77690abe1f04e4cdcb284b7e17208d169 (diff) | |
download | justbuild-e5010e47df602404d332d9686c04fa12358e3644.tar.gz |
FileRoot: Give git-based roots access to storage config
17 files changed, 354 insertions, 150 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, diff --git a/test/buildtool/build_engine/base_maps/TARGETS b/test/buildtool/build_engine/base_maps/TARGETS index 2bd0882a..ac75dd9e 100644 --- a/test/buildtool/build_engine/base_maps/TARGETS +++ b/test/buildtool/build_engine/base_maps/TARGETS @@ -33,7 +33,9 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } @@ -50,7 +52,9 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } @@ -72,8 +76,10 @@ , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] , ["utils", "test_hash_function_type"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } @@ -92,7 +98,9 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } @@ -112,7 +120,9 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } diff --git a/test/buildtool/build_engine/base_maps/directory_map.test.cpp b/test/buildtool/build_engine/base_maps/directory_map.test.cpp index 8f53454b..6538a371 100644 --- a/test/buildtool/build_engine/base_maps/directory_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/directory_map.test.cpp @@ -25,18 +25,23 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT -auto SetupConfig(bool use_git) -> RepositoryConfig { +auto SetupConfig(StorageConfig const* storage_config, + bool use_git) -> RepositoryConfig { auto root = FileRoot{kBasePath / "data_src"}; if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kSrcTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kSrcTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -47,8 +52,9 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadDirectory(ModuleName const& id, DirectoryEntriesMap::Consumer value_checker, + StorageConfig const* storage_config, bool use_git = false) -> bool { - auto repo_config = SetupConfig(use_git); + auto repo_config = SetupConfig(storage_config, use_git); auto data_direntries = CreateDirectoryEntriesMap(&repo_config); bool success{true}; { @@ -77,12 +83,14 @@ TEST_CASE("simple usage") { }; SECTION("via file") { - CHECK(ReadDirectory(name, consumer, /*use_git=*/false)); + CHECK(ReadDirectory(name, consumer, nullptr, /*use_git=*/false)); CHECK(as_expected); } SECTION("via git tree") { - CHECK(ReadDirectory(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadDirectory( + name, consumer, &storage_config.Get(), /*use_git=*/true)); CHECK(as_expected); } } @@ -97,12 +105,14 @@ TEST_CASE("missing directory") { }; SECTION("via file") { - CHECK(ReadDirectory(name, consumer, /*use_git=*/false)); + CHECK(ReadDirectory(name, consumer, nullptr, /*use_git=*/false)); CHECK(as_expected); } SECTION("via git tree") { - CHECK(ReadDirectory(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadDirectory( + name, consumer, &storage_config.Get(), /*use_git=*/true)); CHECK(as_expected); } } diff --git a/test/buildtool/build_engine/base_maps/expression_map.test.cpp b/test/buildtool/build_engine/base_maps/expression_map.test.cpp index 86e95a32..098c884b 100644 --- a/test/buildtool/build_engine/base_maps/expression_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/expression_map.test.cpp @@ -28,18 +28,23 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT -auto SetupConfig(bool use_git) -> RepositoryConfig { +auto SetupConfig(StorageConfig const* storage_config, + bool use_git) -> RepositoryConfig { auto root = FileRoot{kBasePath / "data_expr"}; if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kExprTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kExprTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -50,8 +55,9 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadExpressionFunction(EntityName const& id, ExpressionFunctionMap::Consumer value_checker, + StorageConfig const* storage_config = nullptr, bool use_git = false) -> bool { - auto repo_config = SetupConfig(use_git); + auto repo_config = SetupConfig(storage_config, use_git); auto expr_file_map = CreateExpressionFileMap(&repo_config, 0); auto expr_func_map = CreateExpressionMap(&expr_file_map, &repo_config); @@ -83,11 +89,14 @@ TEST_CASE("Simple expression object literal", "[expression_map]") { }; SECTION("via file") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -106,11 +115,14 @@ TEST_CASE("Simple read of variable", "[expression_map]") { }; SECTION("via file") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -129,11 +141,14 @@ TEST_CASE("Simple call of imported expression", "[expression_map]") { }; SECTION("via file") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -152,11 +167,14 @@ TEST_CASE("Overwrite import in nested expression", "[expression_map]") { }; SECTION("via file") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -167,11 +185,14 @@ TEST_CASE("Fail due to unkown ID", "[expression_map]") { }; SECTION("via file") { - CHECK_FALSE(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK_FALSE( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK_FALSE(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } diff --git a/test/buildtool/build_engine/base_maps/json_file_map.test.cpp b/test/buildtool/build_engine/base_maps/json_file_map.test.cpp index 65064927..ecdcbd9e 100644 --- a/test/buildtool/build_engine/base_maps/json_file_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/json_file_map.test.cpp @@ -25,19 +25,24 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT auto SetupConfig(std::string target_file_name, + StorageConfig const* storage_config, bool use_git) -> RepositoryConfig { auto root = FileRoot{kBasePath}; if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kJsonTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kJsonTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -52,10 +57,11 @@ template <bool kMandatory = true> auto ReadJsonFile(std::string const& target_file_name, ModuleName const& id, JsonFileMap::Consumer value_checker, + StorageConfig const* storage_config, bool use_git = false, std::optional<JsonFileMap::FailureFunction> fail_func = std::nullopt) -> bool { - auto repo_config = SetupConfig(target_file_name, use_git); + auto repo_config = SetupConfig(target_file_name, storage_config, use_git); auto json_files = CreateJsonFileMap<&RepositoryConfig::WorkspaceRoot, &RepositoryConfig::TargetFileName, kMandatory>(&repo_config, 0); @@ -86,12 +92,18 @@ TEST_CASE("simple usage") { }; SECTION("via file") { - CHECK(ReadJsonFile("foo.json", name, consumer, /*use_git=*/false)); + CHECK(ReadJsonFile( + "foo.json", name, consumer, nullptr, /*use_git=*/false)); CHECK(as_expected); } SECTION("via git tree") { - CHECK(ReadJsonFile("foo.json", name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadJsonFile("foo.json", + name, + consumer, + &storage_config.Get(), + /*use_git=*/true)); CHECK(as_expected); } } @@ -113,15 +125,24 @@ TEST_CASE("non existent") { auto name = ModuleName{"", "missing"}; SECTION("via file") { - CHECK(ReadJsonFile<false>( - "foo.json", name, consumer, /*use_git=*/false, fail_func)); + CHECK(ReadJsonFile<false>("foo.json", + name, + consumer, + nullptr, + /*use_git=*/false, + fail_func)); CHECK(as_expected); CHECK(failcont_counter == 0); } SECTION("via git tree") { - CHECK(ReadJsonFile<false>( - "foo.json", name, consumer, /*use_git=*/true, fail_func)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadJsonFile<false>("foo.json", + name, + consumer, + &storage_config.Get(), + /*use_git=*/true, + fail_func)); CHECK(as_expected); CHECK(failcont_counter == 0); } @@ -131,15 +152,24 @@ TEST_CASE("non existent") { auto name = ModuleName{"", "missing"}; SECTION("via file") { - CHECK_FALSE(ReadJsonFile<true>( - "foo.json", name, consumer, /*use_git=*/false, fail_func)); + CHECK_FALSE(ReadJsonFile<true>("foo.json", + name, + consumer, + nullptr, + /*use_git=*/false, + fail_func)); CHECK_FALSE(as_expected); CHECK(failcont_counter == 1); } SECTION("via git tree") { - CHECK_FALSE(ReadJsonFile<true>( - "foo.json", name, consumer, /*use_git=*/true, fail_func)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadJsonFile<true>("foo.json", + name, + consumer, + &storage_config.Get(), + /*use_git=*/true, + fail_func)); CHECK_FALSE(as_expected); CHECK(failcont_counter == 1); } @@ -153,6 +183,7 @@ TEST_CASE("Bad syntax") { "bad.json", {"", "data_json"}, [](auto const& /* unused */) {}, + nullptr, /*use_git=*/false, fail_func)); CHECK(failcont_counter == 1); diff --git a/test/buildtool/build_engine/base_maps/rule_map.test.cpp b/test/buildtool/build_engine/base_maps/rule_map.test.cpp index eb91aaf5..f3a64954 100644 --- a/test/buildtool/build_engine/base_maps/rule_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/rule_map.test.cpp @@ -29,18 +29,23 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT -auto SetupConfig(bool use_git) -> RepositoryConfig { +auto SetupConfig(StorageConfig const* storage_config, + bool use_git) -> RepositoryConfig { auto root = FileRoot{kBasePath / "data_rule"}; if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kRuleTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kRuleTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -51,8 +56,9 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadUserRule(EntityName const& id, UserRuleMap::Consumer value_checker, + StorageConfig const* storage_config = nullptr, bool use_git = false) -> bool { - auto repo_config = SetupConfig(use_git); + auto repo_config = SetupConfig(storage_config, use_git); auto expr_file_map = CreateExpressionFileMap(&repo_config, 0); auto expr_func_map = CreateExpressionMap(&expr_file_map, &repo_config); auto rule_file_map = CreateRuleFileMap(&repo_config, 0); @@ -80,11 +86,13 @@ TEST_CASE("Test empty rule", "[expression_map]") { auto consumer = [](auto values) { REQUIRE(values[0]); }; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -101,11 +109,13 @@ TEST_CASE("Test rule fields", "[rule_map]") { }; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -117,11 +127,13 @@ TEST_CASE("Test config_transitions target", "[rule_map]") { EntityName{"", ".", "test_config_transitions_target_via_field"}; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } SECTION("via implicit") { @@ -129,11 +141,13 @@ TEST_CASE("Test config_transitions target", "[rule_map]") { EntityName{"", ".", "test_config_transitions_target_via_implicit"}; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } } @@ -159,11 +173,13 @@ TEST_CASE("Test config_transitions canonicalness", "[rule_map]") { }; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -185,11 +201,13 @@ TEST_CASE("Test call of imported expression", "[rule_map]") { }; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -200,11 +218,13 @@ TEST_CASE("Fail due to unknown ID", "[rule_map]") { }; SECTION("via file") { - CHECK_FALSE(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK_FALSE(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK_FALSE(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } diff --git a/test/buildtool/build_engine/base_maps/source_map.test.cpp b/test/buildtool/build_engine/base_maps/source_map.test.cpp index 08f6149d..d63271b8 100644 --- a/test/buildtool/build_engine/base_maps/source_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/source_map.test.cpp @@ -31,14 +31,17 @@ #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" #include "test/utils/hermeticity/test_hash_function_type.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT -auto SetupConfig(bool use_git) -> RepositoryConfig { +auto SetupConfig(StorageConfig const* storage_config, + bool use_git) -> RepositoryConfig { // manually create locally a test symlink in data_src; should match the // git test_repo structure if (not use_git) { @@ -51,7 +54,9 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kSrcTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kSrcTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -63,10 +68,11 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadSourceTarget(EntityName const& id, SourceTargetMap::Consumer consumer, HashFunction::Type hash_type, + StorageConfig const* storage_config, bool use_git = false, std::optional<SourceTargetMap::FailureFunction> fail_func = std::nullopt) -> bool { - auto repo_config = SetupConfig(use_git); + auto repo_config = SetupConfig(storage_config, use_git); auto directory_entries = CreateDirectoryEntriesMap(&repo_config); auto source_artifacts = CreateSourceTargetMap(&directory_entries, &repo_config, hash_type); @@ -99,13 +105,19 @@ TEST_CASE("from file") { }; SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); + CHECK(ReadSourceTarget( + name, consumer, hash_type, nullptr, /*use_git=*/false)); CHECK(artifacts["file"]["type"] == "LOCAL"); CHECK(artifacts["file"]["data"]["path"] == "file"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true)); CHECK(artifacts["file"]["type"] == "KNOWN"); CHECK( artifacts["file"]["data"]["id"] == @@ -125,14 +137,19 @@ TEST_CASE("not present at all") { SECTION("via file") { CHECK_FALSE(ReadSourceTarget( - name, consumer, hash_type, /*use_git=*/false, fail_func)); + name, consumer, hash_type, nullptr, /*use_git=*/false, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } SECTION("via git tree") { - CHECK_FALSE(ReadSourceTarget( - name, consumer, hash_type, /*use_git=*/true, fail_func)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true, + fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } @@ -149,14 +166,19 @@ TEST_CASE("malformed entry") { SECTION("via git tree") { CHECK_FALSE(ReadSourceTarget( - name, consumer, hash_type, /*use_git=*/false, fail_func)); + name, consumer, hash_type, nullptr, /*use_git=*/false, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } SECTION("via git tree") { - CHECK_FALSE(ReadSourceTarget( - name, consumer, hash_type, /*use_git=*/true, fail_func)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true, + fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } @@ -172,13 +194,19 @@ TEST_CASE("subdir file") { }; SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); + CHECK(ReadSourceTarget( + name, consumer, hash_type, nullptr, /*use_git=*/false)); CHECK(artifacts["bar/file"]["type"] == "LOCAL"); CHECK(artifacts["bar/file"]["data"]["path"] == "foo/bar/file"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true)); CHECK(artifacts["bar/file"]["type"] == "KNOWN"); CHECK( artifacts["bar/file"]["data"]["id"] == @@ -197,13 +225,19 @@ TEST_CASE("subdir symlink") { }; SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); + CHECK(ReadSourceTarget( + name, consumer, hash_type, nullptr, /*use_git=*/false)); CHECK(artifacts["link"]["type"] == "LOCAL"); CHECK(artifacts["link"]["data"]["path"] == "foo/link"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true)); CHECK(artifacts["link"]["type"] == "KNOWN"); CHECK(artifacts["link"]["data"]["id"] == (ProtocolTraits::IsNative(hash_type) ? kSrcLinkIdSha1 diff --git a/test/buildtool/common/TARGETS b/test/buildtool/common/TARGETS index 6e69c7e5..4ad87f17 100644 --- a/test/buildtool/common/TARGETS +++ b/test/buildtool/common/TARGETS @@ -41,6 +41,7 @@ , ["@", "src", "src/buildtool/execution_api/local", "local_api"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] + , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["", "catch-main"] , ["utils", "test_storage_config"] diff --git a/test/buildtool/common/repository_config.test.cpp b/test/buildtool/common/repository_config.test.cpp index 8c1fd893..cc28a5e3 100644 --- a/test/buildtool/common/repository_config.test.cpp +++ b/test/buildtool/common/repository_config.test.cpp @@ -30,6 +30,7 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" #include "test/utils/hermeticity/test_storage_config.hpp" @@ -43,7 +44,7 @@ namespace { return FileSystemManager::GetCurrentDirectory() / "test/buildtool/common"; } -[[nodiscard]] auto GetGitRoot() -> FileRoot { +[[nodiscard]] auto GetGitRoot(StorageConfig const* storage_config) -> FileRoot { static std::atomic<int> counter{}; auto repo_path = GetTestDir() / "test_repo" / @@ -55,7 +56,8 @@ namespace { "commit --allow-empty -m'init'") == 0) { auto constexpr kEmptyTreeId = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; - if (auto root = FileRoot::FromGit(repo_path, kEmptyTreeId)) { + if (auto root = + FileRoot::FromGit(storage_config, repo_path, kEmptyTreeId)) { return std::move(*root); } } @@ -63,11 +65,12 @@ namespace { } [[nodiscard]] auto CreateFixedRepoInfo( + StorageConfig const* storage_config, std::map<std::string, std::string> const& bindings = {}, std::string const& tfn = "TARGETS", std::string const& rfn = "RULES", std::string const& efn = "EXPRESSIONS") { - static auto const kGitRoot = GetGitRoot(); + static auto const kGitRoot = GetGitRoot(storage_config); return RepositoryConfig::RepositoryInfo{ kGitRoot, kGitRoot, kGitRoot, kGitRoot, bindings, tfn, rfn, efn}; } @@ -134,7 +137,7 @@ TEST_CASE("Compute key of fixed repository", "[repository_config]") { RepositoryConfig config{}; SECTION("for single fixed repository") { - config.SetInfo("foo", CreateFixedRepoInfo()); + config.SetInfo("foo", CreateFixedRepoInfo(&storage_config.Get())); auto key = config.RepositoryKey(storage, "foo"); REQUIRE(key); @@ -144,15 +147,23 @@ TEST_CASE("Compute key of fixed repository", "[repository_config]") { } SECTION("for fixed repositories with same missing dependency") { - config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz"}})); - config.SetInfo("bar", CreateFixedRepoInfo({{"dep", "baz"}})); + config.SetInfo( + "foo", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz"}})); + config.SetInfo( + "bar", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz"}})); CHECK_FALSE(config.RepositoryKey(storage, "foo")); CHECK_FALSE(config.RepositoryKey(storage, "bar")); } SECTION("for fixed repositories with different missing dependency") { - config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz0"}})); - config.SetInfo("bar", CreateFixedRepoInfo({{"dep", "baz1"}})); + config.SetInfo( + "foo", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz0"}})); + config.SetInfo( + "bar", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz1"}})); CHECK_FALSE(config.RepositoryKey(storage, "foo")); CHECK_FALSE(config.RepositoryKey(storage, "bar")); } @@ -170,8 +181,12 @@ TEST_CASE("Compute key of file repository", "[repository_config]") { } SECTION("for graph with leaf dependency as file") { - config.SetInfo("foo", CreateFixedRepoInfo({{"bar", "bar"}})); - config.SetInfo("bar", CreateFixedRepoInfo({{"baz", "baz"}})); + config.SetInfo( + "foo", + CreateFixedRepoInfo(&storage_config.Get(), {{"bar", "bar"}})); + config.SetInfo( + "bar", + CreateFixedRepoInfo(&storage_config.Get(), {{"baz", "baz"}})); config.SetInfo("baz", CreateFileRepoInfo()); CHECK_FALSE(config.RepositoryKey(storage, "foo")); } @@ -184,12 +199,14 @@ TEST_CASE("Compare key of two repos with same content", "[repository_config]") { RepositoryConfig config{}; // create two different repo infos with same content (baz should be same) - config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz0"}})); - config.SetInfo("bar", CreateFixedRepoInfo({{"dep", "baz1"}})); + config.SetInfo( + "foo", CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz0"}})); + config.SetInfo( + "bar", CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz1"}})); SECTION("with leaf dependency") { // create duplicate leaf repo info with global name 'baz0' and 'baz1' - auto baz = CreateFixedRepoInfo(); + auto baz = CreateFixedRepoInfo(&storage_config.Get()); config.SetInfo("baz0", Copy(baz)); config.SetInfo("baz1", Copy(baz)); @@ -208,7 +225,8 @@ TEST_CASE("Compare key of two repos with same content", "[repository_config]") { SECTION("with cyclic dependency") { // create duplicate cyclic repo info with global name 'baz0' and 'baz1' - auto baz = CreateFixedRepoInfo({{"foo", "foo"}, {"bar", "bar"}}); + auto baz = CreateFixedRepoInfo(&storage_config.Get(), + {{"foo", "foo"}, {"bar", "bar"}}); config.SetInfo("baz0", Copy(baz)); config.SetInfo("baz1", Copy(baz)); @@ -227,8 +245,12 @@ TEST_CASE("Compare key of two repos with same content", "[repository_config]") { SECTION("with two separate cyclic graphs") { // create two cyclic repo infos producing two separate graphs - config.SetInfo("baz0", CreateFixedRepoInfo({{"dep", "foo"}})); - config.SetInfo("baz1", CreateFixedRepoInfo({{"dep", "bar"}})); + config.SetInfo( + "baz0", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "foo"}})); + config.SetInfo( + "baz1", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "bar"}})); // check if computed key is same auto foo_key = config.RepositoryKey(storage, "foo"); @@ -243,8 +265,12 @@ TEST_CASE("Compare key of two repos with same content", "[repository_config]") { } SECTION("for graph with leaf repos refering to themselfs") { - config.SetInfo("baz0", CreateFixedRepoInfo({{"dep", "baz0"}})); - config.SetInfo("baz1", CreateFixedRepoInfo({{"dep", "baz1"}})); + config.SetInfo( + "baz0", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz0"}})); + config.SetInfo( + "baz1", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz1"}})); // check if computed key is same auto foo_key = config.RepositoryKey(storage, "foo"); diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS index 5062ee29..7d760fc1 100644 --- a/test/buildtool/file_system/TARGETS +++ b/test/buildtool/file_system/TARGETS @@ -77,6 +77,7 @@ , ["", "catch-main"] , ["utils", "shell_quoting"] , ["utils", "test_hash_function_type"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "file_system"] } diff --git a/test/buildtool/file_system/file_root.test.cpp b/test/buildtool/file_system/file_root.test.cpp index db0fdf11..46b52e79 100644 --- a/test/buildtool/file_system/file_root.test.cpp +++ b/test/buildtool/file_system/file_root.test.cpp @@ -32,6 +32,7 @@ #include "src/buildtool/file_system/object_type.hpp" #include "src/utils/cpp/expected.hpp" #include "test/utils/hermeticity/test_hash_function_type.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" #include "test/utils/shell_quoting.hpp" namespace { @@ -195,11 +196,14 @@ TEST_CASE("Creating file root", "[file_root]") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); CHECK(root->Exists(".")); - CHECK_FALSE(FileRoot::FromGit("does_not_exist", kTreeSymId)); + CHECK_FALSE(FileRoot::FromGit( + &storage_config.Get(), "does_not_exist", kTreeSymId)); } SECTION("local root ignore-special") { @@ -216,13 +220,18 @@ TEST_CASE("Creating file root", "[file_root]") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); CHECK(root->Exists(".")); - CHECK_FALSE(FileRoot::FromGit( - "does_not_exist", kTreeSymId, /*ignore_special=*/true)); + CHECK_FALSE(FileRoot::FromGit(&storage_config.Get(), + "does_not_exist", + kTreeSymId, + /*ignore_special=*/true)); } } @@ -237,7 +246,9 @@ TEST_CASE("Reading files", "[file_root]") { SECTION("git root") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); TestFileRootReadFilesAndSymlinks(*root); @@ -254,8 +265,11 @@ TEST_CASE("Reading files", "[file_root]") { SECTION("git root ignore-special") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); TestFileRootReadFilesOnly(*root); @@ -273,7 +287,9 @@ TEST_CASE("Reading directories", "[file_root]") { SECTION("git root") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); TestFileRootReadDirectory(*root, /*with_symlinks=*/true); @@ -290,8 +306,11 @@ TEST_CASE("Reading directories", "[file_root]") { SECTION("git root ignore-special") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); TestFileRootReadDirectory(*root, /*with_symlinks=*/false); @@ -309,7 +328,9 @@ TEST_CASE("Reading blobs", "[file_root]") { SECTION("git root") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); auto foo = root->ReadBlob(kFooIdGitSha1); @@ -330,8 +351,11 @@ TEST_CASE("Reading blobs", "[file_root]") { SECTION("git root ignore-special") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); auto foo = root->ReadBlob(kFooIdGitSha1); @@ -353,7 +377,9 @@ TEST_CASE("Reading blob type", "[file_root]") { SECTION("git root") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); TestFileRootReadBlobType(*root); @@ -369,8 +395,11 @@ TEST_CASE("Reading blob type", "[file_root]") { SECTION("git root ignore-special") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); TestFileRootReadBlobType(*root); @@ -417,7 +446,9 @@ static void CheckGitRoot(HashFunction::Type hash_type, bool ignore_special) noexcept { auto const repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto const root = FileRoot::FromGit(*repo_path, kTreeSymId, ignore_special); + auto const storage_config = TestStorageConfig::Create(); + auto const root = FileRoot::FromGit( + &storage_config.Get(), *repo_path, kTreeSymId, ignore_special); REQUIRE(root); auto const foo = root->ToArtifactDescription(hash_type, "baz/foo", "repo"); |