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
Changes from 1 commit
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
47 changes: 44 additions & 3 deletions azure-pipelines/end-to-end-tests-dir/add.ps1
Original file line number Diff line number Diff line change
@@ -9,18 +9,59 @@ 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 @manifestDirArgs
Throw-IfFailed

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

$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 dependency correctly.`nExpected: $expected`nActual:$actual"
}

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

$expected = @"
{
"dependencies": [
{
"name": "sqlite3",
"default-features": false
autoantwort marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
"@

$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"
}

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

$expected = @"
{
"dependencies": [
{
"name": "sqlite3",
"default-features": false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be clarified that this is still here from the previous run, but it would also be better to have an independent test with [core,somethingelse].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought I think this should make default features be true because that's what sqlite3[zlib] requests.

@ras0219-msft also points out that we should have tests for multiple references to the same name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now have the test vcpkg add port "sqlite3" "sqlite3[core]"

"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"
}
22 changes: 20 additions & 2 deletions src/vcpkg/commands.add.cpp
Original file line number Diff line number Diff line change
@@ -101,13 +101,27 @@ namespace vcpkg::Commands
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({}), [](auto& 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, [](auto& feature) {
return DependencyRequestedFeature{feature, PlatformExpression::Expr::Empty()};
});
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)
{
@@ -118,6 +132,10 @@ namespace vcpkg::Commands
dep->features.push_back(feature);
}
}
if (is_core)
{
dep->default_features = false;
}
}
}