Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish "Implement depend-defaults" #538

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c8da40f
Implement depend-defaults
ras0219-msft Dec 3, 2021
5c47307
Merge branch 'main' of https://github.com/Microsoft/vcpkg-tool into HEAD
ras0219-msft Feb 17, 2022
02a2133
Fixup after merge
ras0219-msft Feb 17, 2022
4542303
Fix serialization error
ras0219-msft Feb 18, 2022
e337036
Fix e2e test break
ras0219-msft Feb 18, 2022
a06f544
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort May 10, 2022
8fea981
Fix tests
autoantwort May 11, 2022
4de6b91
Format
autoantwort May 12, 2022
d041774
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort Oct 1, 2022
53bcd53
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort Nov 13, 2022
5d786d3
Fix null pointer access
autoantwort Nov 13, 2022
17f4abd
Ignore default feature when checking if it is installed
autoantwort Nov 14, 2022
fcb6fa2
WIP: Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort Aug 3, 2023
63c4074
Fix build after Merge with main
autoantwort Aug 3, 2023
d40fcb0
Fix tests
autoantwort Aug 5, 2023
5114b65
Remove unnecessary change
autoantwort Aug 5, 2023
fe3b612
Adapt schema.
autoantwort Aug 5, 2023
95e132c
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort Oct 17, 2023
e045dd1
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort Nov 12, 2023
0080184
Fix merge bug
autoantwort Nov 12, 2023
712c126
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort Dec 13, 2023
d71b3e4
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort Apr 17, 2024
9befbe2
More merge conflicts
autoantwort Apr 17, 2024
4cf4f3a
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort May 22, 2024
5f2ad54
Merge branch 'main' into dev/roschuma/depends-defaults
autoantwort Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/vcpkg/base/jsonreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ namespace vcpkg::Json
}
}

// returns whether key \in obj
template<class Type>
bool optional_object_field(const Object& obj,
StringView key,
Optional<Type>& place,
IDeserializer<Type>& visitor)
{
if (auto value = obj.get(key))
{
visit_in_key(*value, key, place.emplace(), visitor);
return true;
}
else
{
return false;
}
}

template<class Type>
Optional<Type> visit(const Value& value, IDeserializer<Type>& visitor)
{
Expand Down
9 changes: 8 additions & 1 deletion include/vcpkg/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ namespace vcpkg::Dependencies
const StatusParagraphs& status_db,
const CreateInstallPlanOptions& options = {Triplet{}});

enum class DependDefaults
{
NO,
YES,
};

ExpectedS<ActionPlan> create_versioned_install_plan(const PortFileProvider::IVersionedPortfileProvider& vprovider,
const PortFileProvider::IBaselineProvider& bprovider,
const PortFileProvider::IOverlayProvider& oprovider,
Expand All @@ -206,7 +212,8 @@ namespace vcpkg::Dependencies
const std::vector<DependencyOverride>& overrides,
const PackageSpec& toplevel,
Triplet host_triplet,
UnsupportedPortAction unsupported_port_action);
UnsupportedPortAction unsupported_port_action,
DependDefaults depend_defaults);

void print_plan(const ActionPlan& action_plan, const bool is_recursive = true, const Path& builtin_ports_dir = {});
}
4 changes: 4 additions & 0 deletions include/vcpkg/packagespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ namespace vcpkg
struct Dependency
{
std::string name;

// When created through parsing a manifest, `features` will be pre-normalized (containing 'core' and 'default'
// as appropriate)
std::vector<std::string> features;
PlatformExpression::Expr platform;
DependencyConstraint constraint;
bool host = false;
Optional<bool> default_features;

Json::Object extra_info;

Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace vcpkg
VersionScheme version_scheme = VersionScheme::String;
std::string raw_version;
int port_version = 0;
bool depend_defaults = true;
std::vector<std::string> description;
std::vector<std::string> summary;
std::vector<std::string> maintainers;
Expand Down
145 changes: 139 additions & 6 deletions src/vcpkg-test/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ struct MockVersionedPortfileProvider : PortFileProvider::IVersionedPortfileProvi
}
};

using Dependencies::DependDefaults;

template<class T, class E>
T unwrap(ExpectedT<T, E> e)
{
Expand Down Expand Up @@ -242,7 +244,8 @@ static ExpectedS<Dependencies::ActionPlan> create_versioned_install_plan(
overrides,
toplevel,
Test::ARM_UWP,
Dependencies::UnsupportedPortAction::Error);
Dependencies::UnsupportedPortAction::Error,
DependDefaults::YES);
}

static ExpectedS<vcpkg::Dependencies::ActionPlan> create_versioned_install_plan(
Expand All @@ -262,7 +265,30 @@ static ExpectedS<vcpkg::Dependencies::ActionPlan> create_versioned_install_plan(
overrides,
toplevel,
Test::ARM_UWP,
Dependencies::UnsupportedPortAction::Error);
Dependencies::UnsupportedPortAction::Error,
Dependencies::DependDefaults::YES);
}

static ExpectedS<vcpkg::Dependencies::ActionPlan> create_versioned_install_plan(
const PortFileProvider::IOverlayProvider& oprovider,
const std::vector<Dependency>& deps,
const PackageSpec& toplevel,
DependDefaults depend_defaults)
{
MockVersionedPortfileProvider vp;
MockCMakeVarProvider var_provider;
MockBaselineProvider bp;

return vcpkg::Dependencies::create_versioned_install_plan(vp,
bp,
oprovider,
var_provider,
deps,
{},
toplevel,
Test::ARM_UWP,
Dependencies::UnsupportedPortAction::Error,
depend_defaults);
}

TEST_CASE ("basic version install single", "[versionplan]")
Expand Down Expand Up @@ -1561,11 +1587,118 @@ TEST_CASE ("version install default features", "[versionplan]")
MockBaselineProvider bp;
bp.v["a"] = {"1", 0};

auto install_plan =
unwrap(create_versioned_install_plan(vp, bp, var_provider, {Dependency{"a"}}, {}, toplevel_spec()));
SECTION ("toplevel requires defaults")
{
auto install_plan =
unwrap(create_versioned_install_plan(vp, bp, var_provider, {Dependency{"a"}}, {}, toplevel_spec()));

REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"1", 0}, {"x"});
REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"1", 0}, {"x"});
}

SECTION ("default-features false")
{
auto install_plan = unwrap(create_versioned_install_plan(
vp, bp, var_provider, {Dependency{"a", {"core"}, {}, {}, false, false}}, {}, toplevel_spec()));

REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"1", 0}, {});
}

SECTION ("default-features true")
{
auto install_plan = unwrap(create_versioned_install_plan(
vp, bp, var_provider, {Dependency{"a", {"core", "default"}, {}, {}, false, false}}, {}, toplevel_spec()));

REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"1", 0}, {"x"});
}

SECTION ("default-features true 2")
{
auto install_plan = unwrap(create_versioned_install_plan(
vp, bp, var_provider, {Dependency{"a", {"core", "default"}, {}, {}, false, true}}, {}, toplevel_spec()));

REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"1", 0}, {"x"});
}
}

TEST_CASE ("version install depend-defaults", "[versionplan]")
{
MockOverlayProvider op;
auto& a_scf = op.emplace("a");
a_scf.source_control_file->core_paragraph->dependencies.push_back(Dependency{"b"});
auto& b_scf = op.emplace("b");
b_scf.source_control_file->core_paragraph->default_features.emplace_back("0");
b_scf.source_control_file->feature_paragraphs.emplace_back(make_fpgh("0"));
auto& c_scf = op.emplace("c");
auto& c0 = c_scf.source_control_file->feature_paragraphs.emplace_back(make_fpgh("0"));
c0->dependencies.push_back(Dependency{"b"});

auto& d_scf = op.emplace("d");
d_scf.source_control_file->core_paragraph->dependencies.push_back(Dependency{"b", {"core"}});

auto& e_scf = op.emplace("e");
e_scf.source_control_file->core_paragraph->dependencies.push_back(Dependency{"b"});
e_scf.source_control_file->core_paragraph->depend_defaults = false;

SECTION ("toplevel depend-defaults true")
{
auto install_plan =
unwrap(create_versioned_install_plan(op, {Dependency{"b"}}, toplevel_spec(), DependDefaults::YES));
REQUIRE(install_plan.size() == 1);
check_name_and_features(install_plan.install_actions[0], "b", {"0"});
}

SECTION ("toplevel depend-defaults false")
{
auto install_plan =
unwrap(create_versioned_install_plan(op, {Dependency{"b"}}, toplevel_spec(), DependDefaults::NO));
REQUIRE(install_plan.size() == 1);
check_name_and_features(install_plan.install_actions[0], "b", {});

// a -> b[default], so depend-defaults should not suppress it
install_plan =
unwrap(create_versioned_install_plan(op, {Dependency{"a"}}, toplevel_spec(), DependDefaults::NO));
REQUIRE(install_plan.size() == 2);
check_name_and_features(install_plan.install_actions[0], "b", {"0"});
}

SECTION ("toplevel depend-defaults true (transitive)")
{
auto install_plan =
unwrap(create_versioned_install_plan(op, {Dependency{"d"}}, toplevel_spec(), DependDefaults::YES));
REQUIRE(install_plan.size() == 2);
check_name_and_features(install_plan.install_actions[0], "b", {"0"});
}

SECTION ("toplevel depend-defaults false (transitive)")
{
auto install_plan =
unwrap(create_versioned_install_plan(op, {Dependency{"d"}}, toplevel_spec(), DependDefaults::NO));
REQUIRE(install_plan.size() == 2);
check_name_and_features(install_plan.install_actions[0], "b", {});
}

SECTION ("transitive depend-defaults false")
{
SECTION ("toplevel false")
{
auto install_plan =
unwrap(create_versioned_install_plan(op, {Dependency{"e"}}, toplevel_spec(), DependDefaults::NO));
REQUIRE(install_plan.size() == 2);
check_name_and_features(install_plan.install_actions[0], "b", {});
}

SECTION ("toplevel core")
{
auto install_plan = unwrap(create_versioned_install_plan(
op, {Dependency{"e"}, Dependency{"b", {"core"}}}, toplevel_spec(), DependDefaults::YES));
REQUIRE(install_plan.size() == 2);
check_name_and_features(install_plan.install_actions[0], "b", {});
}
}
}

TEST_CASE ("version dont install default features", "[versionplan]")
Expand Down
15 changes: 9 additions & 6 deletions src/vcpkg-test/manifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ TEST_CASE ("manifest construct minimum", "[manifests]")

REQUIRE(pgh.core_paragraph->name == "zlib");
REQUIRE(pgh.core_paragraph->raw_version == "1.2.8");
REQUIRE(pgh.core_paragraph->depend_defaults == true);
REQUIRE(pgh.core_paragraph->maintainers.empty());
REQUIRE(pgh.core_paragraph->contacts.is_empty());
REQUIRE(pgh.core_paragraph->summary.empty());
Expand Down Expand Up @@ -712,6 +713,7 @@ TEST_CASE ("manifest construct maximum", "[manifests]")
"summary": "d",
"description": "d",
"builtin-baseline": "123",
"depend-defaults": false,
"dependencies": ["bd"],
"default-features": ["df"],
"features": {
Expand All @@ -726,11 +728,11 @@ TEST_CASE ("manifest construct maximum", "[manifests]")
"name": "order.white-lotus",
"features": [ "the-ancient-ways" ],
"platform": "!(windows & arm)"
},
{
"$extra": [],
"$my": [],
"name": "tea"
},
{
"$extra": [],
"$my": [],
"name": "tea"
}
]
},
Expand Down Expand Up @@ -764,6 +766,7 @@ TEST_CASE ("manifest construct maximum", "[manifests]")
REQUIRE(contact_a_aa->string() == "aa");
REQUIRE(pgh.core_paragraph->summary.size() == 1);
REQUIRE(pgh.core_paragraph->summary[0] == "d");
REQUIRE(pgh.core_paragraph->depend_defaults == false);
REQUIRE(pgh.core_paragraph->description.size() == 1);
REQUIRE(pgh.core_paragraph->description[0] == "d");
REQUIRE(pgh.core_paragraph->dependencies.size() == 1);
Expand All @@ -782,7 +785,7 @@ TEST_CASE ("manifest construct maximum", "[manifests]")
REQUIRE(pgh.feature_paragraphs[0]->dependencies[0].name == "firebending");

REQUIRE(pgh.feature_paragraphs[0]->dependencies[1].name == "order.white-lotus");
REQUIRE(pgh.feature_paragraphs[0]->dependencies[1].features.size() == 1);
REQUIRE(pgh.feature_paragraphs[0]->dependencies[1].features.size() == 2); // "core" and "default"
REQUIRE(pgh.feature_paragraphs[0]->dependencies[1].features[0] == "the-ancient-ways");
REQUIRE_FALSE(pgh.feature_paragraphs[0]->dependencies[1].platform.evaluate(
{{"VCPKG_CMAKE_SYSTEM_NAME", ""}, {"VCPKG_TARGET_ARCHITECTURE", "arm"}}));
Expand Down
73 changes: 73 additions & 0 deletions src/vcpkg-test/plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,79 @@ TEST_CASE ("install with default features", "[plan]")
features_check(install_plan.install_actions.at(1), "a", {"0", "core"});
}

TEST_CASE ("install with depend-defaults false", "[plan]")
{
StatusParagraphs status_db;

PackageSpecMap spec_map;
auto a_spec = spec_map.emplace("a", "b");
auto b_spec = spec_map.emplace("b", "", {{"0", ""}}, {"0"});
auto c_spec = spec_map.emplace("c", "", {{"0", "b"}}, {"0"});
auto d_spec = spec_map.emplace("d", "b");
spec_map.map["d"].source_control_file->core_paragraph->depend_defaults = false;
spec_map.map["d"].source_control_file->core_paragraph->dependencies[0].default_features = true;

PortFileProvider::MapPortFileProvider map_port{spec_map.map};
MockCMakeVarProvider var_provider;

std::vector<FullPackageSpec> full_package_specs{
FullPackageSpec{a_spec, {"core"}},
FullPackageSpec{b_spec, {"core"}},
};

std::vector<FullPackageSpec> full_package_specs2{
FullPackageSpec{c_spec, {"default", "core"}},
FullPackageSpec{b_spec, {"core"}},
};

std::vector<FullPackageSpec> full_package_specs_d{
FullPackageSpec{d_spec, {"core"}},
};

// Install "a" and then "b" _should_ install default features
SECTION ("depend-defaults true from core")
{
auto install_plan = Dependencies::create_feature_install_plan(map_port, var_provider, full_package_specs, {});
REQUIRE(install_plan.size() == 2);
features_check(install_plan.install_actions.at(0), "b", {"0", "core"});
features_check(install_plan.install_actions.at(1), "a", {"core"});
}

SECTION ("depend-defaults true from feature")
{
auto install_plan = Dependencies::create_feature_install_plan(map_port, var_provider, full_package_specs2, {});
REQUIRE(install_plan.size() == 2);
features_check(install_plan.install_actions.at(0), "b", {"0", "core"});
features_check(install_plan.install_actions.at(1), "c", {"0", "core"});
}

SECTION ("depend-defaults false overridden from dependency")
{
auto install_plan = Dependencies::create_feature_install_plan(map_port, var_provider, full_package_specs_d, {});
REQUIRE(install_plan.size() == 2);
features_check(install_plan.install_actions.at(0), "b", {"0", "core"});
features_check(install_plan.install_actions.at(1), "d", {"core"});
}

// now, disable the implicit default dependency from `a` and `c[0]`
SECTION ("depend-defaults false from core")
{
spec_map.map["a"].source_control_file->core_paragraph->depend_defaults = false;
auto install_plan = Dependencies::create_feature_install_plan(map_port, var_provider, full_package_specs, {});
REQUIRE(install_plan.size() == 2);
features_check(install_plan.install_actions.at(0), "b", {"core"});
features_check(install_plan.install_actions.at(1), "a", {"core"});
}
SECTION ("depend-defaults false from feature")
{
spec_map.map["c"].source_control_file->core_paragraph->depend_defaults = false;
auto install_plan = Dependencies::create_feature_install_plan(map_port, var_provider, full_package_specs2, {});
REQUIRE(install_plan.size() == 2);
features_check(install_plan.install_actions.at(0), "b", {"core"});
features_check(install_plan.install_actions.at(1), "c", {"0", "core"});
}
}

TEST_CASE ("upgrade with default features 1", "[plan]")
{
std::vector<std::unique_ptr<StatusParagraph>> pghs;
Expand Down
Loading