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 3 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
65 changes: 62 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,77 @@ 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"
}

# Add "default-features": false in comparison to the previous test
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"
}

# 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",
"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"
}

# Remove "default-features": false in comparison to the previous test
Run-Vcpkg add port "sqlite3" "sqlite3" @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 dependency correctly.`nExpected: $expected`nActual:$actual"
}
21 changes: 18 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,7 @@ namespace vcpkg
dep->features.push_back(feature);
}
}
dep->default_features = !is_core;
}
}

Expand Down