Fix build trailing `*` display (#3619)

This commit is contained in:
Hind-M 2024-11-21 11:38:40 +01:00 committed by GitHub
parent 7b0a957dc0
commit ebe0d4f89c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 17 deletions

View File

@ -1322,18 +1322,28 @@ namespace mamba::solver
return arr; return arr;
} }
auto rstrip_excessive_free(std::string_view str) -> std::string_view // Single dependency with only name constraint often end up looking like
{ // ``python =* *`` so `rstrip_excessive_free` was used to strip all this.
str = util::rstrip(str); // Best would be to handle this with a richer NamedList that contains
str = util::remove_suffix(str, specs::GlobSpec::free_pattern); // ``VersionSpecs`` to avoid flaky reliance on string modification.
str = util::rstrip(str);
for (const auto& suffix : sorted_suffix(specs::VersionSpec::all_free_strs)) // As `rstrip_excessive_free` side effect was to strip `*` from a regex,
{ // (which is not wanted and confusing when trying to understand the
str = util::remove_suffix(str, suffix); // unsolvability problems), it is not used anymore on `vers_builds_trunc`.
} // But we still keep it uncommented for a while (in case we need to
str = util::rstrip(str); // restore it later).
return str; // auto rstrip_excessive_free(std::string_view str) -> std::string_view
} // {
// str = util::rstrip(str);
// str = util::remove_suffix(str, specs::GlobSpec::free_pattern);
// str = util::rstrip(str);
// for (const auto& suffix : sorted_suffix(specs::VersionSpec::all_free_strs))
// {
// str = util::remove_suffix(str, suffix);
// }
// str = util::rstrip(str);
// return str;
// }
void TreeExplainer::write_pkg_dep(const TreeNode& tn) void TreeExplainer::write_pkg_dep(const TreeNode& tn)
{ {
@ -1348,11 +1358,7 @@ namespace mamba::solver
} }
else else
{ {
// Single dependency with only name constraint often end up looking like const auto relevant_vers_builds_trunc = vers_builds_trunc;
// ``python =* *`` so we strip all this.
// Best would be to handle this with a richer NamedList that contains
// ``VersionSpecs`` to avoid flaky reliance on string modification.
const auto relevant_vers_builds_trunc = rstrip_excessive_free(vers_builds_trunc);
if (relevant_vers_builds_trunc.empty()) if (relevant_vers_builds_trunc.empty())
{ {
write(fmt::format(style, "{}", edges.name())); write(fmt::format(style, "{}", edges.name()));

View File

@ -1097,5 +1097,33 @@ TEST_SUITE("solver::libsolv::solver")
CHECK_EQ(std::get<Solution::Install>(solution.actions.front()).install.build_string, "bld"); CHECK_EQ(std::get<Solution::Install>(solution.actions.front()).install.build_string, "bld");
CHECK_EQ(std::get<Solution::Install>(solution.actions.front()).install.build_number, 4); CHECK_EQ(std::get<Solution::Install>(solution.actions.front()).install.build_number, 4);
} }
SUBCASE("foo[version='=*,=*', build='pyhd*']")
{
auto pkg = PackageInfo("foo");
pkg.version = "=*,=*";
pkg.build_string = "pyhd*";
db.add_repo_from_packages(std::array{ pkg });
auto request = Request{
/* .flags= */ {},
/* .jobs= */ { Request::Install{ "foo[version='=*,=*', build='pyhd*']"_ms } },
};
const auto outcome = libsolv::Solver().solve(db, request);
REQUIRE(outcome.has_value());
REQUIRE(std::holds_alternative<libsolv::UnSolvable>(outcome.value()));
const auto& unsolvable = std::get<libsolv::UnSolvable>(outcome.value());
const auto problems_explained = unsolvable.explain_problems(db, {});
// To avoid mismatch due to color formatting, we perform the check by splitting the
// output following the format
CHECK(util::contains(problems_explained, "foo =*,=* pyhd*"));
CHECK(util::contains(
problems_explained,
"does not exist (perhaps a typo or a missing channel)."
));
}
} }
} }