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

vcpkg add port: Handle feature core. #1163

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 53 additions & 3 deletions azure-pipelines/end-to-end-tests-dir/add.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,68 @@ New-Item -Path $manifestDir -ItemType Directory
New-Item -Path $manifestPath -ItemType File `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgJson)

Run-Vcpkg add port zlib @manifestDirArgs
Run-Vcpkg add port "sqlite3[core]" "sqlite3[core]" @manifestDirArgs
Throw-IfFailed

$expected = @"
{
"dependencies": [
"zlib"
{
"name": "sqlite3",
"default-features": false
}
]
}
"@

$actual = (Get-Content -Path $manifestPath -Raw).TrimEnd()
if ($expected -ne $actual) {
throw "Add port didn't add zlib dependency correctly.`nExpected: $expected`nActual:$actual"
throw "Add port didn't add sqlite3[core] dependency correctly.`nExpected: $expected`nActual:$actual"
}

# Add default features
Run-Vcpkg add port "sqlite3" "sqlite3[core]" @manifestDirArgs
Throw-IfFailed

$expected = @"
{
"dependencies": [
"sqlite3"
]
}
"@

$actual = (Get-Content -Path $manifestPath -Raw).TrimEnd()
if ($expected -ne $actual) {
throw "Add port didn't add sqlite3 dependency correctly.`nExpected: $expected`nActual:$actual"
}

# Adding sqlite3[core] does not change something because default features are already enabled
Run-Vcpkg add port "sqlite3[core]" @manifestDirArgs
Throw-IfFailed
$actual = (Get-Content -Path $manifestPath -Raw).TrimEnd()
if ($expected -ne $actual) {
throw "Add port didn't add sqlite3[core] dependency correctly.`nExpected: $expected`nActual:$actual"
}

# Add zlib as a feature in comparison to the previous test
Run-Vcpkg add port "sqlite3[core,zlib]" @manifestDirArgs
Throw-IfFailed
$expected = @"
{
"dependencies": [
{
"name": "sqlite3",
"features": [
"zlib"
]
}
]
}
"@
$actual = (Get-Content -Path $manifestPath -Raw).TrimEnd()
if ($expected -ne $actual) {
throw "Add port didn't add sqlite3[zlib] dependency correctly.`nExpected: $expected`nActual:$actual"
}


24 changes: 21 additions & 3 deletions src/vcpkg/commands.add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,30 @@ namespace vcpkg
return dep.name == spec.name && !dep.host &&
structurally_equal(spec.platform.value_or(PlatformExpression::Expr()), dep.platform);
});
const auto features = Util::fmap(spec.features.value_or({}), [](const std::string& feature) {
auto feature_names = spec.features.value_or({});
BillyONeal marked this conversation as resolved.
Show resolved Hide resolved
bool is_core = false;
Util::erase_if(feature_names, [&](const auto& feature_name) {
if (feature_name == "core")
{
is_core = true;
return true;
}
return false;
});
BillyONeal marked this conversation as resolved.
Show resolved Hide resolved
const auto features = Util::fmap(feature_names, [](const std::string& feature) {
Checks::check_exit(VCPKG_LINE_INFO, !feature.empty() && feature != "core" && feature != "default");
return DependencyRequestedFeature{feature};
});
if (dep == manifest_scf.core_paragraph->dependencies.end())
{
manifest_scf.core_paragraph->dependencies.push_back(
auto& new_dep = manifest_scf.core_paragraph->dependencies.emplace_back(
Dependency{spec.name, features, spec.platform.value_or({})});
if (is_core)
{
new_dep.default_features = false;
}
}
else if (spec.features)
else
{
for (const auto& feature : features)
{
Expand All @@ -128,6 +142,10 @@ namespace vcpkg
dep->features.push_back(feature);
}
}
if (!is_core)
{
dep->default_features = true;
}
}
}

Expand Down