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 all 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
5 changes: 5 additions & 0 deletions docs/vcpkg.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
}
}
},
"depend-defaults": {
"description": "The default value for the default-features field of a dependency",
"type": "boolean",
"default": true
},
"default-features": {
"description": "Features enabled by default with the package.",
"type": "array",
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/base/contractual-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace vcpkg
inline constexpr StringLiteral JsonIdDefaultTriplet = "default-triplet";
inline constexpr StringLiteral JsonIdDemands = "demands";
inline constexpr StringLiteral JsonIdDependencies = "dependencies";
inline constexpr StringLiteral JsonIdDependDefaults = "depend-defaults";
inline constexpr StringLiteral JsonIdDescription = "description";
inline constexpr StringLiteral JsonIdDetectedCIEnvironment = "detected-ci-environment";
inline constexpr StringLiteral JsonIdDetector = "detector";
Expand Down
6 changes: 5 additions & 1 deletion include/vcpkg/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@ namespace vcpkg
const Path& packages_dir,
UnsupportedPortAction action,
UseHeadVersion use_head_version_if_user_requested,
Editable editable_if_user_requested)
Editable editable_if_user_requested,
ImplicitDefault implicit_default = ImplicitDefault::Yes)
: randomizer(randomizer)
, host_triplet(host_triplet)
, packages_dir(packages_dir)
, unsupported_port_action(action)
, use_head_version_if_user_requested(use_head_version_if_user_requested)
, editable_if_user_requested(editable_if_user_requested)
, implicit_default(implicit_default)
{
}

Expand All @@ -146,6 +148,7 @@ namespace vcpkg
UnsupportedPortAction unsupported_port_action;
UseHeadVersion use_head_version_if_user_requested;
Editable editable_if_user_requested;
ImplicitDefault implicit_default;
};

struct CreateUpgradePlanOptions
Expand All @@ -165,6 +168,7 @@ namespace vcpkg
Triplet host_triplet;
Path packages_dir;
UnsupportedPortAction unsupported_port_action;
ImplicitDefault implicit_default;
};

struct RemovePlan
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace vcpkg
std::string name;
VersionScheme version_scheme = VersionScheme::String;
Version version;
bool depend_defaults = true;
std::vector<std::string> description;
std::vector<std::string> summary;
std::vector<std::string> maintainers;
Expand Down
154 changes: 132 additions & 22 deletions src/vcpkg-test/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static void check_name_and_features(const InstallPlanAction& ipa,
std::initializer_list<StringLiteral> features)
{
CHECK(ipa.spec.name() == name);
INFO("spec.name: " << name);
CHECK(ipa.source_control_file_and_location.has_value());
{
INFO("ipa.feature_list = [" << Strings::join(", ", ipa.feature_list) << "]");
Expand Down Expand Up @@ -220,15 +221,20 @@ static ExpectedL<ActionPlan> create_versioned_install_plan(const IVersionedPortf
const std::vector<DependencyOverride>& overrides,
const PackageSpec& toplevel)
{
return create_versioned_install_plan(
provider,
bprovider,
s_empty_mock_overlay,
var_provider,
deps,
overrides,
toplevel,
{nullptr, Test::ARM_UWP, "pkgs", UnsupportedPortAction::Error, UseHeadVersion::No, Editable::No});
return create_versioned_install_plan(provider,
bprovider,
s_empty_mock_overlay,
var_provider,
deps,
overrides,
toplevel,
{nullptr,
Test::ARM_UWP,
"pkgs",
UnsupportedPortAction::Error,
UseHeadVersion::No,
Editable::No,
ImplicitDefault::Yes});
}

static ExpectedL<ActionPlan> create_versioned_install_plan(const IVersionedPortfileProvider& provider,
Expand All @@ -239,15 +245,45 @@ static ExpectedL<ActionPlan> create_versioned_install_plan(const IVersionedPortf
const std::vector<DependencyOverride>& overrides,
const PackageSpec& toplevel)
{
return create_versioned_install_plan(
provider,
bprovider,
oprovider,
var_provider,
deps,
overrides,
toplevel,
{nullptr, Test::ARM_UWP, "pkgs", UnsupportedPortAction::Error, UseHeadVersion::No, Editable::No});
return create_versioned_install_plan(provider,
bprovider,
oprovider,
var_provider,
deps,
overrides,
toplevel,
{nullptr,
Test::ARM_UWP,
"pkgs",
UnsupportedPortAction::Error,
UseHeadVersion::No,
Editable::No,
ImplicitDefault::Yes});
}

static ExpectedL<ActionPlan> create_versioned_install_plan(const IOverlayProvider& oprovider,
const std::vector<Dependency>& deps,
const PackageSpec& toplevel,
ImplicitDefault implicit_default)
{
MockVersionedPortfileProvider vp;
MockCMakeVarProvider var_provider;
MockBaselineProvider bp;

return vcpkg::create_versioned_install_plan(vp,
bp,
oprovider,
var_provider,
deps,
{},
toplevel,
{nullptr,
Test::ARM_UWP,
"pkgs",
UnsupportedPortAction::Error,
UseHeadVersion::No,
Editable::No,
implicit_default});
}

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

WITH_EXPECTED(install_plan,
create_versioned_install_plan(vp, bp, var_provider, {Dependency{"a"}}, {}, toplevel_spec()));
SECTION ("toplevel requires defaults")
{
WITH_EXPECTED(install_plan,
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 =
create_versioned_install_plan(vp, bp, var_provider, {CoreDependency{"a"}}, {}, toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);

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

SECTION ("default-features true")
{
auto install_plan = create_versioned_install_plan(vp, bp, var_provider, {Dependency{"a"}}, {}, toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);

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 = create_versioned_install_plan(vp, bp, var_provider, {Dependency{"a"}}, {}, toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);

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]")
{
// Dependencies:
// b has default feature '0'
// a -> b[core]
// c -> b[default]

MockOverlayProvider op;
auto& a_scf = op.emplace("a");
a_scf.source_control_file->core_paragraph->dependencies.push_back(CoreDependency{"b"});
auto& b_scf = op.emplace("b");
b_scf.source_control_file->core_paragraph->default_features.push_back({"0"});
b_scf.source_control_file->feature_paragraphs.emplace_back(make_fpgh("0"));
auto& d_scf = op.emplace("c");
d_scf.source_control_file->core_paragraph->dependencies.push_back(Dependency{"b"});

SECTION ("toplevel ImplicitDefault::Yes")
{
auto install_plan = create_versioned_install_plan(op, {Dependency{"a"}}, toplevel_spec(), ImplicitDefault::Yes)
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 2);
check_name_and_features(install_plan.install_actions[0], "b", {"0"});
check_name_and_features(install_plan.install_actions[1], "a", {});
}

SECTION ("toplevel ImplicitDefault::No")
{
auto install_plan = create_versioned_install_plan(op, {Dependency{"a"}}, toplevel_spec(), ImplicitDefault::No)
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 2);

check_name_and_features(install_plan.install_actions[0], "b", {});
check_name_and_features(install_plan.install_actions[1], "a", {});

// c -> b[default], so depend-defaults should not suppress it
install_plan = create_versioned_install_plan(op, {Dependency{"c"}}, toplevel_spec(), ImplicitDefault::No)
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 2);
check_name_and_features(install_plan.install_actions[0], "b", {"0"});
check_name_and_features(install_plan.install_actions[1], "c", {});
}
}

TEST_CASE ("version dont install default features", "[versionplan]")
Expand Down
63 changes: 63 additions & 0 deletions src/vcpkg-test/manifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ TEST_CASE ("manifest construct minimum", "[manifests]")
REQUIRE(pgh.to_name() == "zlib");
REQUIRE(pgh.to_version_scheme() == VersionScheme::String);
REQUIRE(pgh.to_version() == Version{"1.2.8", 0});
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 @@ -1060,6 +1061,68 @@ TEST_CASE ("manifest construct maximum", "[manifests]")
check_json_eq_ordered(serialize_manifest(pgh), object);
}

TEST_CASE ("SourceParagraph manifest depend-default", "[manifests]")
{
auto json = parse_json_object(R"json({
"name": "zlib",
"version-string": "1.2.8",
"depend-defaults": false,
"dependencies": [
"y",
{"name": "z", "host": true},
{"name": "z2", "host": true, "default-features": true}
],
"features": {
"t": {
"description": "",
"dependencies": ["z"]
}
}
})json");
SECTION ("depend-defaults: false")
{
auto m_pgh = test_parse_port_manifest(json);
REQUIRE(m_pgh.has_value());
auto& pgh = **m_pgh.get();
REQUIRE(pgh.core_paragraph->depend_defaults == false);
REQUIRE(pgh.core_paragraph->dependencies.size() == 3);
REQUIRE(pgh.core_paragraph->dependencies[0].name == "y");
REQUIRE(pgh.core_paragraph->dependencies[0].default_features == false);
REQUIRE(pgh.core_paragraph->dependencies[1].name == "z");
REQUIRE(pgh.core_paragraph->dependencies[1].default_features == false);
REQUIRE(pgh.core_paragraph->dependencies[2].name == "z2");
REQUIRE(pgh.core_paragraph->dependencies[2].default_features == true);

REQUIRE(pgh.feature_paragraphs.size() == 1);
REQUIRE(pgh.feature_paragraphs[0]->dependencies[0].name == "z");
REQUIRE(pgh.feature_paragraphs[0]->dependencies[0].default_features == false);
check_json_eq_ordered(serialize_manifest(pgh), json);
}
SECTION ("depend-defaults: true")
{
json.remove("depend-defaults");
json["dependencies"].array(VCPKG_LINE_INFO)[2].object(VCPKG_LINE_INFO)["default-features"] =
Json::Value::boolean(false);
auto m_pgh = test_parse_port_manifest(json);
REQUIRE(m_pgh.has_value());
auto& pgh = **m_pgh.get();

REQUIRE(pgh.core_paragraph->depend_defaults == true);
REQUIRE(pgh.core_paragraph->dependencies.size() == 3);
REQUIRE(pgh.core_paragraph->dependencies[0].name == "y");
REQUIRE(pgh.core_paragraph->dependencies[0].default_features == true);
REQUIRE(pgh.core_paragraph->dependencies[1].name == "z");
REQUIRE(pgh.core_paragraph->dependencies[1].default_features == true);
REQUIRE(pgh.core_paragraph->dependencies[2].name == "z2");
REQUIRE(pgh.core_paragraph->dependencies[2].default_features == false);

REQUIRE(pgh.feature_paragraphs.size() == 1);
REQUIRE(pgh.feature_paragraphs[0]->dependencies[0].name == "z");
REQUIRE(pgh.feature_paragraphs[0]->dependencies[0].default_features == true);
check_json_eq_ordered(serialize_manifest(pgh), json);
}
}

TEST_CASE ("SourceParagraph manifest two dependencies", "[manifests]")
{
auto m_pgh = test_parse_port_manifest(R"json({
Expand Down
Loading
Loading