diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-06-15 14:51:03 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-06-20 17:40:44 +0200 |
commit | 9d5047bb2b6d1756385fc4fabf2a3d54d9e9ac93 (patch) | |
tree | 7963d227ddc056f65c544e0e086d4a1f34985687 | |
parent | 17f2cab4490f075a5cb9e975e4b92c06572270ca (diff) | |
download | justbuild-9d5047bb2b6d1756385fc4fabf2a3d54d9e9ac93.tar.gz |
Repository representation: also use string as name in bindings
In this way, we keep the repsitory description more close to a normal
multi-repository configuration. The only difference remaining is
the absence of repository locations for git-tree roots.
-rw-r--r-- | src/buildtool/common/repository_config.cpp | 13 | ||||
-rw-r--r-- | src/buildtool/common/repository_config.hpp | 5 | ||||
-rw-r--r-- | test/buildtool/common/repository_config.test.cpp | 10 |
3 files changed, 15 insertions, 13 deletions
diff --git a/src/buildtool/common/repository_config.cpp b/src/buildtool/common/repository_config.cpp index eb72b1c6..ba45052a 100644 --- a/src/buildtool/common/repository_config.cpp +++ b/src/buildtool/common/repository_config.cpp @@ -83,7 +83,7 @@ auto RepositoryConfig::BuildGraphForRepository(std::string const& repo) const -> std::optional<nlohmann::json> { auto graph = nlohmann::json::object(); int id_counter{}; - std::unordered_map<std::string, int> repo_ids{}; + std::unordered_map<std::string, std::string> repo_ids{}; if (AddToGraphAndGetId(&graph, &id_counter, &repo_ids, repo)) { return graph; } @@ -98,8 +98,9 @@ auto RepositoryConfig::BuildGraphForRepository(std::string const& repo) const auto RepositoryConfig::AddToGraphAndGetId( gsl::not_null<nlohmann::json*> const& graph, gsl::not_null<int*> const& id_counter, - gsl::not_null<std::unordered_map<std::string, int>*> const& repo_ids, - std::string const& repo) const -> std::optional<int> { + gsl::not_null<std::unordered_map<std::string, std::string>*> const& + repo_ids, + std::string const& repo) const -> std::optional<std::string> { auto const& unique_repo = DeduplicateRepo(repo); auto repo_it = repo_ids->find(unique_repo); if (repo_it != repo_ids->end()) { @@ -110,7 +111,7 @@ auto RepositoryConfig::AddToGraphAndGetId( auto const* data = Data(unique_repo); if (data != nullptr and data->base_desc) { // Compute the unique id (traversal order) and store it - auto repo_id = (*id_counter)++; + auto repo_id = std::to_string((*id_counter)++); repo_ids->emplace(unique_repo, repo_id); // Compute repository description from content-fixed base @@ -123,11 +124,11 @@ auto RepositoryConfig::AddToGraphAndGetId( if (not global_id) { return std::nullopt; } - repo_desc["bindings"][local_name] = *global_id; + repo_desc["bindings"][local_name] = std::move(*global_id); } // Add repository description to graph with unique id as key - (*graph)[std::to_string(repo_id)] = std::move(repo_desc); + (*graph)[repo_id] = std::move(repo_desc); return repo_id; } return std::nullopt; diff --git a/src/buildtool/common/repository_config.hpp b/src/buildtool/common/repository_config.hpp index 85a388fc..e1144789 100644 --- a/src/buildtool/common/repository_config.hpp +++ b/src/buildtool/common/repository_config.hpp @@ -176,8 +176,9 @@ class RepositoryConfig { [[nodiscard]] auto AddToGraphAndGetId( gsl::not_null<nlohmann::json*> const& graph, gsl::not_null<int*> const& id_counter, - gsl::not_null<std::unordered_map<std::string, int>*> const& repo_ids, - std::string const& repo) const -> std::optional<int>; + gsl::not_null<std::unordered_map<std::string, std::string>*> const& + repo_ids, + std::string const& repo) const -> std::optional<std::string>; }; #endif // INCLUDED_SRC_BUILDTOOL_COMMON_REPOSITORY_CONFIG_HPP diff --git a/test/buildtool/common/repository_config.test.cpp b/test/buildtool/common/repository_config.test.cpp index b62dbd68..19ab25c2 100644 --- a/test/buildtool/common/repository_config.test.cpp +++ b/test/buildtool/common/repository_config.test.cpp @@ -70,7 +70,7 @@ template <class T> // build graph: {"0": (info0 + bindings0), "1": (info1 + bindings1), ...} [[nodiscard]] auto BuildGraph( std::vector<RepositoryConfig::RepositoryInfo const*> const& infos, - std::vector<std::unordered_map<std::string, int>> const& bindings) + std::vector<std::unordered_map<std::string, std::string>> const& bindings) -> nlohmann::json { auto graph = nlohmann::json::object(); for (std::size_t i{}; i < infos.size(); ++i) { @@ -169,7 +169,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, // verify created graph from CAS CHECK(ReadGraph(*foo_key) == BuildGraph({config.Info("foo"), config.Info("baz0")}, - {{{"dep", 1}}, {}})); + {{{"dep", "1"}}, {}})); } SECTION("with cyclic dependency") { @@ -188,7 +188,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, // verify created graph from CAS CHECK(ReadGraph(*foo_key) == BuildGraph({config.Info("foo"), config.Info("baz0")}, - {{{"dep", 1}}, {{"foo", 0}, {"bar", 0}}})); + {{{"dep", "1"}}, {{"foo", "0"}, {"bar", "0"}}})); } SECTION("with two separate cyclic graphs") { @@ -205,7 +205,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, // verify created graph from CAS CHECK(ReadGraph(*foo_key) == - BuildGraph({config.Info("foo")}, {{{"dep", 0}}})); + BuildGraph({config.Info("foo")}, {{{"dep", "0"}}})); } SECTION("for graph with leaf repos refering to themselfs") { @@ -227,6 +227,6 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, // verify created graph from CAS CHECK(ReadGraph(*foo_key) == - BuildGraph({config.Info("foo")}, {{{"dep", 0}}})); + BuildGraph({config.Info("foo")}, {{{"dep", "0"}}})); } } |