From 583d99603db279c1004799629f703913851a21cd Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Fri, 3 Dec 2021 14:39:30 -0800 Subject: [PATCH] Fix overpowered default-features = false specification in manifest mode (#292) * Fix overpowered default-features=false specification in manifest mode * Update src/vcpkg/dependencies.cpp Co-authored-by: Billy O'Neal Co-authored-by: Billy O'Neal --- src/vcpkg-test/dependencies.cpp | 11 +++++++++++ src/vcpkg/dependencies.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/vcpkg-test/dependencies.cpp b/src/vcpkg-test/dependencies.cpp index 293f6d9c32..e36e9b1cb3 100644 --- a/src/vcpkg-test/dependencies.cpp +++ b/src/vcpkg-test/dependencies.cpp @@ -1520,11 +1520,15 @@ TEST_CASE ("version install transitive default features", "[versionplan]") auto& b_scf = vp.emplace("b", {"1", 0}, Scheme::Relaxed).source_control_file; b_scf->core_paragraph->dependencies.push_back({"a", {"core"}}); + auto& c_scf = vp.emplace("c", {"1", 0}, Scheme::Relaxed).source_control_file; + c_scf->core_paragraph->dependencies.push_back({"a"}); + MockCMakeVarProvider var_provider; MockBaselineProvider bp; bp.v["a"] = {"1", 0}; bp.v["b"] = {"1", 0}; + bp.v["c"] = {"1", 0}; auto install_plan = unwrap(create_versioned_install_plan(vp, bp, var_provider, {Dependency{"b"}}, {}, toplevel_spec())); @@ -1532,6 +1536,13 @@ TEST_CASE ("version install transitive default features", "[versionplan]") REQUIRE(install_plan.size() == 2); check_name_and_version(install_plan.install_actions[0], "a", {"1", 0}, {"x"}); check_name_and_version(install_plan.install_actions[1], "b", {"1", 0}); + + install_plan = unwrap(create_versioned_install_plan( + vp, bp, var_provider, {Dependency{"a", {"core"}}, Dependency{"c"}}, {}, toplevel_spec())); + + REQUIRE(install_plan.size() == 2); + check_name_and_version(install_plan.install_actions[0], "a", {"1", 0}, {"x"}); + check_name_and_version(install_plan.install_actions[1], "c", {"1", 0}); } static PlatformExpression::Expr parse_platform(StringView l) diff --git a/src/vcpkg/dependencies.cpp b/src/vcpkg/dependencies.cpp index c6d315a537..909ef6f528 100644 --- a/src/vcpkg/dependencies.cpp +++ b/src/vcpkg/dependencies.cpp @@ -1386,7 +1386,7 @@ namespace vcpkg::Dependencies std::pair& emplace_package(const PackageSpec& spec); - // the following 4 functions will add stuff recursivly + // the following functions will add stuff recursively void require_dependency(std::pair& ref, const Dependency& dep, const std::string& origin); @@ -1397,6 +1397,8 @@ namespace vcpkg::Dependencies const std::string& feature, const std::string& origin); + void require_port_defaults(std::pair& ref, const std::string& origin); + void add_feature_to(std::pair& ref, VersionSchemeInfo& vsi, const std::string& feature); @@ -1621,6 +1623,11 @@ namespace vcpkg::Dependencies { require_port_feature(ref, f, origin); } + + if (Util::find(dep.features, StringView{"core"}) == dep.features.end()) + { + require_port_defaults(ref, origin); + } } void VersionedPackageGraph::require_port_version(std::pair& graph_entry, const Versions::Version& version, @@ -1701,6 +1708,24 @@ namespace vcpkg::Dependencies } } + void VersionedPackageGraph::require_port_defaults(std::pair& ref, + const std::string& origin) + { + (void)origin; + if (!ref.second.default_features) + { + ref.second.default_features = true; + ref.second.foreach_vsi([this, &ref](VersionSchemeInfo& vsi) { + if (vsi.scfl) + { + for (auto&& f : vsi.scfl->source_control_file->core_paragraph->default_features) + { + this->add_feature_to(ref, vsi, f); + } + } + }); + } + } void VersionedPackageGraph::require_port_feature(std::pair& ref, const std::string& feature, const std::string& origin)