diff --git a/libmamba/include/mamba/solver/libsolv/database.hpp b/libmamba/include/mamba/solver/libsolv/database.hpp index 7dc4a0ecc0..0cb1143641 100644 --- a/libmamba/include/mamba/solver/libsolv/database.hpp +++ b/libmamba/include/mamba/solver/libsolv/database.hpp @@ -85,17 +85,15 @@ namespace mamba::solver::libsolv PipAsPythonDependency add = PipAsPythonDependency::No ) -> expected_t; - template auto add_repo_from_packages( - Iter first_package, - Iter last_package, + std::vector::const_iterator first_package, + std::vector::const_iterator last_package, std::string_view name = "", PipAsPythonDependency add = PipAsPythonDependency::No ) -> RepoInfo; - template auto add_repo_from_packages( - const Range& packages, + const std::vector& packages, std::string_view name = "", PipAsPythonDependency add = PipAsPythonDependency::No ) -> RepoInfo; @@ -173,33 +171,6 @@ namespace mamba::solver::libsolv * Implementation * ********************/ - template - auto Database::add_repo_from_packages( - Iter first_package, - Iter last_package, - std::string_view name, - PipAsPythonDependency add - ) -> RepoInfo - { - auto repo = add_repo_from_packages_impl_pre(name); - for (; first_package != last_package; ++first_package) - { - add_repo_from_packages_impl_loop(repo, *first_package); - } - add_repo_from_packages_impl_post(repo, add); - return repo; - } - - template - auto Database::add_repo_from_packages( - const Range& packages, - std::string_view name, - PipAsPythonDependency add - ) -> RepoInfo - { - return add_repo_from_packages(packages.begin(), packages.end(), name, add); - } - // TODO(C++20): Use ranges::transform template void Database::for_each_package_in_repo(RepoInfo repo, Func&& func) const diff --git a/libmamba/src/solver/libsolv/database.cpp b/libmamba/src/solver/libsolv/database.cpp index 552b65c6cf..5375918d30 100644 --- a/libmamba/src/solver/libsolv/database.cpp +++ b/libmamba/src/solver/libsolv/database.cpp @@ -354,4 +354,30 @@ namespace mamba::solver::libsolv ); return out; } + + auto Database::add_repo_from_packages( + std::vector::const_iterator first_package, + std::vector::const_iterator last_package, + std::string_view name, + PipAsPythonDependency add + ) -> RepoInfo + { + auto repo = add_repo_from_packages_impl_pre(name); + for (; first_package != last_package; ++first_package) + { + add_repo_from_packages_impl_loop(repo, *first_package); + } + add_repo_from_packages_impl_post(repo, add); + return repo; + } + + auto Database::add_repo_from_packages( + const std::vector& packages, + std::string_view name, + PipAsPythonDependency add + ) -> RepoInfo + { + return add_repo_from_packages(packages.begin(), packages.end(), name, add); + } + } diff --git a/libmamba/tests/src/solver/libsolv/test_database.cpp b/libmamba/tests/src/solver/libsolv/test_database.cpp index d8a4d105a6..0479b17bc6 100644 --- a/libmamba/tests/src/solver/libsolv/test_database.cpp +++ b/libmamba/tests/src/solver/libsolv/test_database.cpp @@ -45,7 +45,7 @@ TEST_SUITE("solver::libsolv::database") SUBCASE("Add repo from packages") { - auto pkgs = std::array{ + auto pkgs = std::vector{ mkpkg("x", "1.0"), mkpkg("x", "2.0"), mkpkg("z", "1.0", { "x>=1.0" }), @@ -115,7 +115,7 @@ TEST_SUITE("solver::libsolv::database") SUBCASE("Iterate over packages") { - auto repo2 = db.add_repo_from_packages(std::array{ mkpkg("z", "2.0") }, "repo1"); + auto repo2 = db.add_repo_from_packages(std::vector{ mkpkg("z", "2.0") }, "repo1"); SUBCASE("In a given repo") { diff --git a/libmamba/tests/src/solver/libsolv/test_solver.cpp b/libmamba/tests/src/solver/libsolv/test_solver.cpp index 5263975c1d..24e930e481 100644 --- a/libmamba/tests/src/solver/libsolv/test_solver.cpp +++ b/libmamba/tests/src/solver/libsolv/test_solver.cpp @@ -4,7 +4,6 @@ // // The full license is in the file LICENSE, distributed with this software. -#include #include #include #include @@ -359,7 +358,7 @@ TEST_SUITE("solver::libsolv::solver") SUBCASE("numpy 1.0 is installed") { - const auto installed = db.add_repo_from_packages(std::array{ + const auto installed = db.add_repo_from_packages(std::vector{ specs::PackageInfo("numpy", "1.0.0", "phony", 0), }); db.set_installed_repo(installed); @@ -423,7 +422,7 @@ TEST_SUITE("solver::libsolv::solver") { auto pkg_numpy = specs::PackageInfo("numpy", "1.0.0", "phony", 0); pkg_numpy.dependencies = { "python=2.0", "foo" }; - const auto installed = db.add_repo_from_packages(std::array{ + const auto installed = db.add_repo_from_packages(std::vector{ pkg_numpy, specs::PackageInfo("python", "2.0.0", "phony", 0), specs::PackageInfo("foo"), @@ -548,7 +547,7 @@ TEST_SUITE("solver::libsolv::solver") pkg_numpy.dependencies = { "python=4.0", "foo" }; auto pkg_foo = specs::PackageInfo("foo", "1.0.0", "phony", 0); pkg_foo.constrains = { "numpy=1.0.0", "foo" }; - const auto installed = db.add_repo_from_packages(std::array{ + const auto installed = db.add_repo_from_packages(std::vector{ pkg_numpy, pkg_foo, specs::PackageInfo("python", "4.0.0", "phony", 0), @@ -614,10 +613,10 @@ TEST_SUITE("solver::libsolv::solver") { auto db = libsolv::Database({}); - const auto repo1 = db.add_repo_from_packages(std::array{ + const auto repo1 = db.add_repo_from_packages(std::vector{ specs::PackageInfo("numpy", "1.0.0", "repo1", 0), }); - const auto repo2 = db.add_repo_from_packages(std::array{ + const auto repo2 = db.add_repo_from_packages(std::vector{ specs::PackageInfo("numpy", "2.0.0", "repo2", 0), }); db.set_repo_priority(repo1, { 2, 0 }); @@ -675,7 +674,7 @@ TEST_SUITE("solver::libsolv::solver") SUBCASE("Pins are respected") { - db.add_repo_from_packages(std::array{ + db.add_repo_from_packages(std::vector{ mkfoo("1.0.0", 0, { "feat" }, 0), mkfoo("2.0.0", 1, {}, 1), }); @@ -698,7 +697,7 @@ TEST_SUITE("solver::libsolv::solver") SUBCASE("Track features has highest priority") { - db.add_repo_from_packages(std::array{ + db.add_repo_from_packages(std::vector{ mkfoo("1.0.0", 0, {}, 0), mkfoo("2.0.0", 1, { "feat" }, 1), }); @@ -720,7 +719,7 @@ TEST_SUITE("solver::libsolv::solver") SUBCASE("Version has second highest priority") { - db.add_repo_from_packages(std::array{ + db.add_repo_from_packages(std::vector{ mkfoo("2.0.0", 0, {}, 0), mkfoo("1.0.0", 1, {}, 1), }); @@ -742,7 +741,7 @@ TEST_SUITE("solver::libsolv::solver") SUBCASE("Build number has third highest priority") { - db.add_repo_from_packages(std::array{ + db.add_repo_from_packages(std::vector{ mkfoo("2.0.0", 1, {}, 0), mkfoo("2.0.0", 0, {}, 1), }); @@ -764,7 +763,7 @@ TEST_SUITE("solver::libsolv::solver") SUBCASE("Timestamp has lowest priority") { - db.add_repo_from_packages(std::array{ + db.add_repo_from_packages(std::vector{ mkfoo("2.0.0", 0, {}, 0), mkfoo("2.0.0", 0, {}, 1), }); @@ -796,10 +795,10 @@ TEST_SUITE("solver::libsolv::solver") { auto pkg1 = specs::PackageInfo("foo", "1.0.0", "conda", 0); pkg1.package_url = "https://conda.anaconda.org/conda-forge/linux-64/foo-1.0.0-phony.conda"; - db.add_repo_from_packages(std::array{ pkg1 }); + db.add_repo_from_packages(std::vector{ pkg1 }); auto pkg2 = specs::PackageInfo("foo", "1.0.0", "mamba", 0); pkg2.package_url = "https://conda.anaconda.org/mamba-forge/linux-64/foo-1.0.0-phony.conda"; - db.add_repo_from_packages(std::array{ pkg2 }); + db.add_repo_from_packages(std::vector{ pkg2 }); SUBCASE("conda-forge::foo") { @@ -938,7 +937,7 @@ TEST_SUITE("solver::libsolv::solver") auto pkg2 = PackageInfo("foo"); pkg2.version = "2.0"; - db.add_repo_from_packages(std::array{ pkg1, pkg2 }); + db.add_repo_from_packages(std::vector{ pkg1, pkg2 }); auto request = Request{ /* .flags= */ {}, @@ -969,7 +968,7 @@ TEST_SUITE("solver::libsolv::solver") pkg4.version = "2.0"; pkg4.dependencies = { "foo=2.0" }; - db.add_repo_from_packages(std::array{ pkg1, pkg2, pkg3, pkg4 }); + db.add_repo_from_packages(std::vector{ pkg1, pkg2, pkg3, pkg4 }); auto request = Request{ /* .flags= */ {}, @@ -1006,7 +1005,7 @@ TEST_SUITE("solver::libsolv::solver") auto pkg2 = PackageInfo("foo"); pkg2.md5 = "bad"; - db.add_repo_from_packages(std::array{ pkg1, pkg2 }); + db.add_repo_from_packages(std::vector{ pkg1, pkg2 }); auto request = Request{ /* .flags= */ {}, @@ -1031,7 +1030,7 @@ TEST_SUITE("solver::libsolv::solver") auto pkg1 = PackageInfo("foo"); pkg1.md5 = "0bab699354cbd66959550eb9b9866620"; - db.add_repo_from_packages(std::array{ pkg1 }); + db.add_repo_from_packages(std::vector{ pkg1 }); auto request = Request{ /* .flags= */ {}, @@ -1050,7 +1049,7 @@ TEST_SUITE("solver::libsolv::solver") auto pkg2 = PackageInfo("foo"); pkg2.build_string = "bld"; - db.add_repo_from_packages(std::array{ pkg1, pkg2 }); + db.add_repo_from_packages(std::vector{ pkg1, pkg2 }); auto request = Request{ /* .flags= */ {}, @@ -1079,7 +1078,7 @@ TEST_SUITE("solver::libsolv::solver") pkg3.build_string = "bld"; pkg3.build_number = 4; - db.add_repo_from_packages(std::array{ pkg1, pkg2, pkg3 }); + db.add_repo_from_packages(std::vector{ pkg1, pkg2, pkg3 }); auto request = Request{ /* .flags= */ {}, diff --git a/libmamba/tests/src/solver/test_problems_graph.cpp b/libmamba/tests/src/solver/test_problems_graph.cpp index 87223292b2..56f236796f 100644 --- a/libmamba/tests/src/solver/test_problems_graph.cpp +++ b/libmamba/tests/src/solver/test_problems_graph.cpp @@ -103,8 +103,8 @@ namespace * * The underlying packages do not exist, we are only interested in the conflict. */ - template - auto create_pkgs_database(ChannelContext& channel_context, const PkgRange& packages) + auto + create_pkgs_database(ChannelContext& channel_context, const std::vector& packages) { solver::libsolv::Database db{ channel_context.params() }; db.add_repo_from_packages(packages); @@ -116,7 +116,7 @@ TEST_CASE("Test create_pkgs_database utility") { auto& ctx = mambatests::context(); auto channel_context = ChannelContext::make_conda_compatible(ctx); - auto db = create_pkgs_database(channel_context, std::array{ mkpkg("foo", "0.1.0", {}) }); + auto db = create_pkgs_database(channel_context, std::vector{ mkpkg("foo", "0.1.0", {}) }); auto request = Request{ {}, { Request::Install{ "foo"_ms } } }; const auto outcome = solver::libsolv::Solver().solve(db, request).value(); REQUIRE(std::holds_alternative(outcome)); @@ -128,7 +128,7 @@ TEST_CASE("Test empty specs") auto channel_context = ChannelContext::make_conda_compatible(ctx); auto db = create_pkgs_database( channel_context, - std::array{ mkpkg("foo", "0.1.0", {}), mkpkg("", "", {}) } + std::vector{ mkpkg("foo", "0.1.0", {}), mkpkg("", "", {}) } ); auto request = Request{ {}, { Request::Install{ "foo"_ms } } }; const auto outcome = solver::libsolv::Solver().solve(db, request).value(); @@ -142,7 +142,7 @@ namespace return std::pair( create_pkgs_database( channel_context, - std::array{ + std::vector{ mkpkg("A", "0.1.0"), mkpkg("A", "0.2.0"), mkpkg("A", "0.3.0"), @@ -163,7 +163,7 @@ namespace return std::pair( create_pkgs_database( channel_context, - std::array{ + std::vector{ mkpkg("menu", "1.5.0", { "dropdown=2.*" }), mkpkg("menu", "1.4.0", { "dropdown=2.*" }), mkpkg("menu", "1.3.0", { "dropdown=2.*" }), @@ -281,7 +281,7 @@ namespace return std::pair( create_pkgs_database( channel_context, - std::array{ + std::vector{ mkpkg("foo", "2.0.0", { "bar=2.0" }), mkpkg("bar", "1.0.0"), mkpkg("bar", "2.0.0"), @@ -600,7 +600,7 @@ TEST_CASE("Create problem graph") using PbGr = ProblemsGraph; using CpPbGr = CompressedProblemsGraph; - const auto issues = std::array{ + const auto issues = std::vector{ std::pair{ "Basic conflict", &create_basic_conflict }, std::pair{ "PubGrub example", &create_pubgrub }, std::pair{ "Harder PubGrub example", &create_pubgrub_hard },