Skip to content

Commit

Permalink
vcpkg add port: Handle feature core. (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
autoantwort authored Oct 31, 2023
1 parent fe0ad6c commit f07df71
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
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 @@ -111,16 +111,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({});
bool is_core = false;
Util::erase_if(feature_names, [&](const auto& feature_name) {
if (feature_name == "core")
{
is_core = true;
return true;
}
return false;
});
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 @@ -129,6 +143,10 @@ namespace vcpkg
dep->features.push_back(feature);
}
}
if (!is_core)
{
dep->default_features = true;
}
}
}

Expand Down

0 comments on commit f07df71

Please sign in to comment.