From c9c8b1cbd678224c9b91289a8a990ed043621725 Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Tue, 22 Aug 2023 19:33:44 +0200 Subject: [PATCH 1/3] vcpkg add port: Handle feature core. --- azure-pipelines/end-to-end-tests-dir/add.ps1 | 47 ++++++++++++++++++-- src/vcpkg/commands.add.cpp | 22 ++++++++- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/azure-pipelines/end-to-end-tests-dir/add.ps1 b/azure-pipelines/end-to-end-tests-dir/add.ps1 index 84565833ea..3062b7ac02 100644 --- a/azure-pipelines/end-to-end-tests-dir/add.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/add.ps1 @@ -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 + } + ] +} +"@ + +$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, + "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" } diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index efad647de1..cebbda5b48 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -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({}); + 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, [](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; + } } } From 5c0d0aa0e1ac7a2a3ca853d9d4d444ad83e32ab3 Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Tue, 5 Sep 2023 19:00:45 +0200 Subject: [PATCH 2/3] Set "default-features": true when "core" is not specified. --- azure-pipelines/end-to-end-tests-dir/add.ps1 | 28 ++++++++++++++++---- src/vcpkg/commands.add.cpp | 7 ++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/azure-pipelines/end-to-end-tests-dir/add.ps1 b/azure-pipelines/end-to-end-tests-dir/add.ps1 index 3062b7ac02..13c1c60435 100644 --- a/azure-pipelines/end-to-end-tests-dir/add.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/add.ps1 @@ -25,9 +25,9 @@ if ($expected -ne $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": [ @@ -38,15 +38,14 @@ $expected = @" ] } "@ - $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 +# Add zlib as a feature in comparison to the previous test +Run-Vcpkg add port "sqlite3[core,zlib]" @manifestDirArgs Throw-IfFailed - $expected = @" { "dependencies": [ @@ -60,8 +59,27 @@ $expected = @" ] } "@ - $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" +} diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index cebbda5b48..875f549fe6 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -123,7 +123,7 @@ namespace vcpkg::Commands new_dep.default_features = false; } } - else if (spec.features) + else { for (const auto& feature : features) { @@ -132,10 +132,7 @@ namespace vcpkg::Commands dep->features.push_back(feature); } } - if (is_core) - { - dep->default_features = false; - } + dep->default_features = !is_core; } } From 5b46696546ec2e1a260fca274f38f038eb78d47e Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Thu, 26 Oct 2023 00:30:15 +0200 Subject: [PATCH 3/3] Don't remove default features via vcpkg add --- azure-pipelines/end-to-end-tests-dir/add.ps1 | 49 ++++++++------------ src/vcpkg/commands.add.cpp | 5 +- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/azure-pipelines/end-to-end-tests-dir/add.ps1 b/azure-pipelines/end-to-end-tests-dir/add.ps1 index 13c1c60435..787dc7e942 100644 --- a/azure-pipelines/end-to-end-tests-dir/add.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/add.ps1 @@ -9,63 +9,52 @@ New-Item -Path $manifestDir -ItemType Directory New-Item -Path $manifestPath -ItemType File ` -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgJson) -Run-Vcpkg add port sqlite3 @manifestDirArgs +Run-Vcpkg add port "sqlite3[core]" "sqlite3[core]" @manifestDirArgs Throw-IfFailed $expected = @" { "dependencies": [ - "sqlite3" + { + "name": "sqlite3", + "default-features": false + } ] } "@ $actual = (Get-Content -Path $manifestPath -Raw).TrimEnd() if ($expected -ne $actual) { - throw "Add port didn't add sqlite3 dependency correctly.`nExpected: $expected`nActual:$actual" + throw "Add port didn't add sqlite3[core] dependency correctly.`nExpected: $expected`nActual:$actual" } -# Add "default-features": false in comparison to the previous test -Run-Vcpkg add port "sqlite3[core]" @manifestDirArgs +# Add default features +Run-Vcpkg add port "sqlite3" "sqlite3[core]" @manifestDirArgs Throw-IfFailed + $expected = @" { "dependencies": [ - { - "name": "sqlite3", - "default-features": false - } + "sqlite3" ] } "@ + $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" + throw "Add port didn't add sqlite3 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 +# Adding sqlite3[core] does not change something because default features are already enabled +Run-Vcpkg add port "sqlite3[core]" @manifestDirArgs Throw-IfFailed -$expected = @" -{ - "dependencies": [ - { - "name": "sqlite3", - "default-features": false, - "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" + throw "Add port didn't add sqlite3[core] dependency correctly.`nExpected: $expected`nActual:$actual" } -# Remove "default-features": false in comparison to the previous test -Run-Vcpkg add port "sqlite3" "sqlite3" @manifestDirArgs +# Add zlib as a feature in comparison to the previous test +Run-Vcpkg add port "sqlite3[core,zlib]" @manifestDirArgs Throw-IfFailed $expected = @" { @@ -81,5 +70,7 @@ $expected = @" "@ $actual = (Get-Content -Path $manifestPath -Raw).TrimEnd() if ($expected -ne $actual) { - throw "Add port didn't add sqlite3 dependency correctly.`nExpected: $expected`nActual:$actual" + throw "Add port didn't add sqlite3[zlib] dependency correctly.`nExpected: $expected`nActual:$actual" } + + diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index 65e22e0915..bda29adb2c 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -142,7 +142,10 @@ namespace vcpkg dep->features.push_back(feature); } } - dep->default_features = !is_core; + if (!is_core) + { + dep->default_features = true; + } } }