Skip to content

Commit

Permalink
Fix overpowered default-features = false specification in manifest mo…
Browse files Browse the repository at this point in the history
…de (#292)

* Fix overpowered default-features=false specification in manifest mode

* Update src/vcpkg/dependencies.cpp

Co-authored-by: Billy O'Neal <[email protected]>

Co-authored-by: Billy O'Neal <[email protected]>
  • Loading branch information
ras0219-msft and BillyONeal authored Dec 3, 2021
1 parent 59307f0 commit 583d996
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/vcpkg-test/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,18 +1520,29 @@ 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()));

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)
Expand Down
27 changes: 26 additions & 1 deletion src/vcpkg/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ namespace vcpkg::Dependencies

std::pair<const PackageSpec, PackageNode>& 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<const PackageSpec, PackageNode>& ref,
const Dependency& dep,
const std::string& origin);
Expand All @@ -1397,6 +1397,8 @@ namespace vcpkg::Dependencies
const std::string& feature,
const std::string& origin);

void require_port_defaults(std::pair<const PackageSpec, PackageNode>& ref, const std::string& origin);

void add_feature_to(std::pair<const PackageSpec, PackageNode>& ref,
VersionSchemeInfo& vsi,
const std::string& feature);
Expand Down Expand Up @@ -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<const PackageSpec, PackageNode>& graph_entry,
const Versions::Version& version,
Expand Down Expand Up @@ -1701,6 +1708,24 @@ namespace vcpkg::Dependencies
}
}

void VersionedPackageGraph::require_port_defaults(std::pair<const PackageSpec, PackageNode>& 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<const PackageSpec, PackageNode>& ref,
const std::string& feature,
const std::string& origin)
Expand Down

0 comments on commit 583d996

Please sign in to comment.