From 815396fa4e9e99da7af7d8454859f6247af1ef81 Mon Sep 17 00:00:00 2001 From: ras0219 <533828+ras0219@users.noreply.github.com> Date: Tue, 15 Dec 2020 10:26:00 -0800 Subject: [PATCH] [vcpkg] Refactor end-to-end tests (#15081) * [vcpkg] Refactor end-to-end tests * [vcpkg] Cherry-pick x-builtin-ports-root from #14999 * [vcpkg] Move create test from unit tests to e2e Co-authored-by: Robert Schumacher --- .../backcompat-helpers.ps1 | 26 ++ .../end-to-end-tests-dir/binarycaching.ps1 | 81 ++++++ .../end-to-end-tests-dir/cli.ps1 | 11 + .../end-to-end-tests-dir/create.ps1 | 10 + .../integrate-install.ps1 | 28 +++ .../end-to-end-tests-dir/spaces.ps1 | 11 + .../end-to-end-tests-prelude.ps1 | 64 +++++ scripts/azure-pipelines/end-to-end-tests.ps1 | 230 +----------------- scripts/ports.cmake | 4 +- toolsrc/include/vcpkg/vcpkgcmdarguments.h | 2 + toolsrc/include/vcpkg/vcpkgpaths.h | 3 +- toolsrc/src/vcpkg-test/arguments.cpp | 4 + toolsrc/src/vcpkg-test/commands.create.cpp | 27 -- toolsrc/src/vcpkg/commands.create.cpp | 6 +- toolsrc/src/vcpkg/vcpkgcmdarguments.cpp | 2 + toolsrc/src/vcpkg/vcpkgpaths.cpp | 2 + 16 files changed, 264 insertions(+), 247 deletions(-) create mode 100644 scripts/azure-pipelines/end-to-end-tests-dir/backcompat-helpers.ps1 create mode 100644 scripts/azure-pipelines/end-to-end-tests-dir/binarycaching.ps1 create mode 100644 scripts/azure-pipelines/end-to-end-tests-dir/cli.ps1 create mode 100644 scripts/azure-pipelines/end-to-end-tests-dir/create.ps1 create mode 100644 scripts/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 create mode 100644 scripts/azure-pipelines/end-to-end-tests-dir/spaces.ps1 create mode 100644 scripts/azure-pipelines/end-to-end-tests-prelude.ps1 delete mode 100644 toolsrc/src/vcpkg-test/commands.create.cpp diff --git a/scripts/azure-pipelines/end-to-end-tests-dir/backcompat-helpers.ps1 b/scripts/azure-pipelines/end-to-end-tests-dir/backcompat-helpers.ps1 new file mode 100644 index 0000000000..5b6b1c10f1 --- /dev/null +++ b/scripts/azure-pipelines/end-to-end-tests-dir/backcompat-helpers.ps1 @@ -0,0 +1,26 @@ +. $PSScriptRoot/../end-to-end-tests-prelude.ps1 + +# Test that prohibiting backcompat features actually prohibits +$backcompatFeaturePorts = @('vcpkg-uses-test-cmake', 'vcpkg-uses-vcpkg-common-functions') +foreach ($backcompatFeaturePort in $backcompatFeaturePorts) { + $succeedArgs = $commonArgs + @('install',$backcompatFeaturePort,'--no-binarycaching') + $failArgs = $succeedArgs + @('--x-prohibit-backcompat-features') + $CurrentTest = "Should fail: ./vcpkg $($failArgs -join ' ')" + Write-Host $CurrentTest + ./vcpkg @failArgs + if ($LastExitCode -ne 0) { + Write-Host "... failed (this is good!)" + } else { + throw $CurrentTest + } + + # Install failed when prohibiting backcompat features, so it should succeed if we allow them + $CurrentTest = "Should succeeed: ./vcpkg $($succeedArgs -join ' ')" + Write-Host $CurrentTest + ./vcpkg @succeedArgs + if ($LastExitCode -ne 0) { + throw $CurrentTest + } else { + Write-Host "... succeeded." + } +} diff --git a/scripts/azure-pipelines/end-to-end-tests-dir/binarycaching.ps1 b/scripts/azure-pipelines/end-to-end-tests-dir/binarycaching.ps1 new file mode 100644 index 0000000000..2b7e84fbd9 --- /dev/null +++ b/scripts/azure-pipelines/end-to-end-tests-dir/binarycaching.ps1 @@ -0,0 +1,81 @@ +. $PSScriptRoot/../end-to-end-tests-prelude.ps1 + +# Test simple installation +Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "--binarycaching", "--x-binarysource=clear;files,$ArchiveRoot,write;nuget,$NuGetRoot,readwrite")) +Throw-IfFailed +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" + +# Test simple removal +Run-Vcpkg -TestArgs ($commonArgs + @("remove", "rapidjson")) +Throw-IfFailed +Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" + +# Test restoring from files archive +Remove-Item -Recurse -Force $installRoot +Remove-Item -Recurse -Force $buildtreesRoot +Run-Vcpkg -TestArgs ($commonArgs + @("install","rapidjson","--binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read")) +Throw-IfFailed +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" +Require-FileNotExists "$buildtreesRoot/rapidjson/src" +Require-FileExists "$buildtreesRoot/detect_compiler" + +# Test --no-binarycaching +Remove-Item -Recurse -Force $installRoot +Remove-Item -Recurse -Force $buildtreesRoot +Run-Vcpkg -TestArgs ($commonArgs + @("install","rapidjson","--no-binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read")) +Throw-IfFailed +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" +Require-FileExists "$buildtreesRoot/rapidjson/src" +Require-FileExists "$buildtreesRoot/detect_compiler" + +# Test --editable +Remove-Item -Recurse -Force $installRoot +Remove-Item -Recurse -Force $buildtreesRoot +Run-Vcpkg -TestArgs ($commonArgs + @("install","rapidjson","--editable","--x-binarysource=clear;files,$ArchiveRoot,read")) +Throw-IfFailed +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" +Require-FileExists "$buildtreesRoot/rapidjson/src" +Require-FileNotExists "$buildtreesRoot/detect_compiler" + +# Test restoring from nuget +Remove-Item -Recurse -Force $installRoot +Remove-Item -Recurse -Force $buildtreesRoot +Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "--binarycaching", "--x-binarysource=clear;nuget,$NuGetRoot")) +Throw-IfFailed +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" +Require-FileNotExists "$buildtreesRoot/rapidjson/src" + +# Test four-phase flow +Remove-Item -Recurse -Force $installRoot -ErrorAction SilentlyContinue +Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "--dry-run", "--x-write-nuget-packages-config=$TestingRoot/packages.config")) +Throw-IfFailed +Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" +Require-FileNotExists "$buildtreesRoot/rapidjson/src" +Require-FileExists "$TestingRoot/packages.config" +if ($IsLinux -or $IsMacOS) { + mono $(./vcpkg fetch nuget) restore $TestingRoot/packages.config -OutputDirectory "$NuGetRoot2" -Source "$NuGetRoot" +} else { + & $(./vcpkg fetch nuget) restore $TestingRoot/packages.config -OutputDirectory "$NuGetRoot2" -Source "$NuGetRoot" +} +Throw-IfFailed +Remove-Item -Recurse -Force $NuGetRoot -ErrorAction SilentlyContinue +mkdir $NuGetRoot +Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "tinyxml", "--binarycaching", "--x-binarysource=clear;nuget,$NuGetRoot2;nuget,$NuGetRoot,write")) +Throw-IfFailed +Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" +Require-FileExists "$installRoot/$Triplet/include/tinyxml.h" +Require-FileNotExists "$buildtreesRoot/rapidjson/src" +Require-FileExists "$buildtreesRoot/tinyxml/src" +if ((Get-ChildItem $NuGetRoot -Filter '*.nupkg' | Measure-Object).Count -ne 1) { + throw "In '$CurrentTest': did not create exactly 1 NuGet package" +} + +# Test export +$CurrentTest = 'Exporting' +Require-FileNotExists "$TestingRoot/vcpkg-export-output" +Require-FileNotExists "$TestingRoot/vcpkg-export.1.0.0.nupkg" +Require-FileNotExists "$TestingRoot/vcpkg-export-output.zip" +Run-Vcpkg -TestArgs ($commonArgs + @("export", "rapidjson", "tinyxml", "--nuget", "--nuget-id=vcpkg-export", "--nuget-version=1.0.0", "--output=vcpkg-export-output", "--raw", "--zip", "--output-dir=$TestingRoot")) +Require-FileExists "$TestingRoot/vcpkg-export-output" +Require-FileExists "$TestingRoot/vcpkg-export.1.0.0.nupkg" +Require-FileExists "$TestingRoot/vcpkg-export-output.zip" diff --git a/scripts/azure-pipelines/end-to-end-tests-dir/cli.ps1 b/scripts/azure-pipelines/end-to-end-tests-dir/cli.ps1 new file mode 100644 index 0000000000..47f624fa8f --- /dev/null +++ b/scripts/azure-pipelines/end-to-end-tests-dir/cli.ps1 @@ -0,0 +1,11 @@ +. $PSScriptRoot/../end-to-end-tests-prelude.ps1 + +# Test bad command lines +Run-Vcpkg -TestArgs ($commonArgs + @("install", "zlib", "--vcpkg-rootttttt", "C:\")) +Throw-IfNotFailed + +Run-Vcpkg -TestArgs ($commonArgs + @("install", "zlib", "--vcpkg-rootttttt=C:\")) +Throw-IfNotFailed + +Run-Vcpkg -TestArgs ($commonArgs + @("install", "zlib", "--fast")) # NB: --fast is not a switch +Throw-IfNotFailed diff --git a/scripts/azure-pipelines/end-to-end-tests-dir/create.ps1 b/scripts/azure-pipelines/end-to-end-tests-dir/create.ps1 new file mode 100644 index 0000000000..53686fe509 --- /dev/null +++ b/scripts/azure-pipelines/end-to-end-tests-dir/create.ps1 @@ -0,0 +1,10 @@ +. $PSScriptRoot/../end-to-end-tests-prelude.ps1 + +# Test vcpkg create +$CurrentTest = "create zlib" +Write-Host $CurrentTest +./vcpkg --x-builtin-ports-root=$TestingRoot/ports create zlib https://github.com/madler/zlib/archive/v1.2.11.tar.gz zlib-1.2.11.tar.gz +Throw-IfFailed + +Require-FileExists "$TestingRoot/ports/zlib/portfile.cmake" +Require-FileExists "$TestingRoot/ports/zlib/vcpkg.json" diff --git a/scripts/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 b/scripts/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 new file mode 100644 index 0000000000..3876977514 --- /dev/null +++ b/scripts/azure-pipelines/end-to-end-tests-dir/integrate-install.ps1 @@ -0,0 +1,28 @@ +if (-not $IsLinux -and -not $IsMacOS) { + . $PSScriptRoot/../end-to-end-tests-prelude.ps1 + + # Test msbuild props and targets + $CurrentTest = "zlib:x86-windows-static msbuild scripts\testing\integrate-install\..." + Write-Host $CurrentTest + ./vcpkg $commonArgs install zlib:x86-windows-static --x-binarysource=clear + Throw-IfFailed + foreach ($project in @("VcpkgTriplet", "VcpkgTriplet2", "VcpkgUseStatic", "VcpkgUseStatic2")) { + $CurrentTest = "msbuild scripts\testing\integrate-install\$project.vcxproj" + ./vcpkg $commonArgs env "msbuild scripts\testing\integrate-install\$project.vcxproj /p:VcpkgRoot=$TestingRoot /p:IntDir=$TestingRoot\int\ /p:OutDir=$TestingRoot\out\ " + Throw-IfFailed + Remove-Item -Recurse -Force $TestingRoot\int + Remove-Item -Recurse -Force $TestingRoot\out + } + $CurrentTest = "zlib:x86-windows msbuild scripts\testing\integrate-install\..." + Write-Host $CurrentTest + ./vcpkg $commonArgs install zlib:x86-windows --x-binarysource=clear + Throw-IfFailed + foreach ($project in @("Project1", "NoProps")) { + $CurrentTest = "msbuild scripts\testing\integrate-install\$project.vcxproj" + Write-Host $CurrentTest + ./vcpkg $commonArgs env "msbuild scripts\testing\integrate-install\$project.vcxproj /p:VcpkgRoot=$TestingRoot /p:IntDir=$TestingRoot\int\ /p:OutDir=$TestingRoot\out\ " + Throw-IfFailed + Remove-Item -Recurse -Force $TestingRoot\int + Remove-Item -Recurse -Force $TestingRoot\out + } +} diff --git a/scripts/azure-pipelines/end-to-end-tests-dir/spaces.ps1 b/scripts/azure-pipelines/end-to-end-tests-dir/spaces.ps1 new file mode 100644 index 0000000000..49796c1b06 --- /dev/null +++ b/scripts/azure-pipelines/end-to-end-tests-dir/spaces.ps1 @@ -0,0 +1,11 @@ +. $PSScriptRoot/../end-to-end-tests-prelude.ps1 + +##### Test spaces in the path +$CurrentTest = "zlib with spaces in path" +Write-Host $CurrentTest +./vcpkg install zlib "--triplet" $Triplet ` + "--no-binarycaching" ` + "--x-buildtrees-root=$TestingRoot/build Trees" ` + "--x-install-root=$TestingRoot/instalL ed" ` + "--x-packages-root=$TestingRoot/packaG es" +Throw-IfFailed diff --git a/scripts/azure-pipelines/end-to-end-tests-prelude.ps1 b/scripts/azure-pipelines/end-to-end-tests-prelude.ps1 new file mode 100644 index 0000000000..057df9fa66 --- /dev/null +++ b/scripts/azure-pipelines/end-to-end-tests-prelude.ps1 @@ -0,0 +1,64 @@ +$TestingRoot = Join-Path $WorkingRoot 'testing' +$buildtreesRoot = Join-Path $TestingRoot 'buildtrees' +$installRoot = Join-Path $TestingRoot 'installed' +$packagesRoot = Join-Path $TestingRoot 'packages' +$NuGetRoot = Join-Path $TestingRoot 'nuget' +$NuGetRoot2 = Join-Path $TestingRoot 'nuget2' +$ArchiveRoot = Join-Path $TestingRoot 'archives' +$VersionFilesRoot = Join-Path $TestingRoot 'version-test' +$commonArgs = @( + "--triplet", + $Triplet, + "--x-buildtrees-root=$buildtreesRoot", + "--x-install-root=$installRoot", + "--x-packages-root=$packagesRoot", + "--overlay-ports=scripts/e2e_ports" +) +$CurrentTest = 'unassigned' + +function Refresh-TestRoot { + Remove-Item -Recurse -Force $TestingRoot -ErrorAction SilentlyContinue + mkdir $TestingRoot | Out-Null + mkdir $NuGetRoot | Out-Null +} + +function Require-FileExists { + [CmdletBinding()] + Param( + [string]$File + ) + if (-Not (Test-Path $File)) { + throw "'$CurrentTest' failed to create file '$File'" + } +} + +function Require-FileNotExists { + [CmdletBinding()] + Param( + [string]$File + ) + if (Test-Path $File) { + throw "'$CurrentTest' should not have created file '$File'" + } +} + +function Throw-IfFailed { + if ($LASTEXITCODE -ne 0) { + throw "'$CurrentTest' had a step with a nonzero exit code" + } +} + +function Throw-IfNotFailed { + if ($LASTEXITCODE -eq 0) { + throw "'$CurrentTest' had a step with an unexpectedly zero exit code" + } +} + +function Run-Vcpkg { + param([string[]]$TestArgs) + $CurrentTest = "./vcpkg $($testArgs -join ' ')" + Write-Host $CurrentTest + ./vcpkg @testArgs +} + +Refresh-TestRoot diff --git a/scripts/azure-pipelines/end-to-end-tests.ps1 b/scripts/azure-pipelines/end-to-end-tests.ps1 index 99e56ce45d..f6b5c2e6bf 100644 --- a/scripts/azure-pipelines/end-to-end-tests.ps1 +++ b/scripts/azure-pipelines/end-to-end-tests.ps1 @@ -24,229 +24,25 @@ Param( [string]$Triplet, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [string]$WorkingRoot + [string]$WorkingRoot, + [Parameter(Mandatory = $false)] + [ValidateNotNullOrEmpty()] + [string]$Filter ) $ErrorActionPreference = "Stop" -$TestingRoot = Join-Path $WorkingRoot 'testing' -$buildtreesRoot = Join-Path $TestingRoot 'buildtrees' -$installRoot = Join-Path $TestingRoot 'installed' -$packagesRoot = Join-Path $TestingRoot 'packages' -$NuGetRoot = Join-Path $TestingRoot 'nuget' -$NuGetRoot2 = Join-Path $TestingRoot 'nuget2' -$ArchiveRoot = Join-Path $TestingRoot 'archives' -$commonArgs = @( - "--triplet", - $Triplet, - "--x-buildtrees-root=$buildtreesRoot", - "--x-install-root=$installRoot", - "--x-packages-root=$packagesRoot", - "--overlay-ports=scripts/e2e_ports" -) -$CurrentTest = 'unassigned' - -function Refresh-TestRoot { - Remove-Item -Recurse -Force $TestingRoot -ErrorAction SilentlyContinue - mkdir $TestingRoot - mkdir $NuGetRoot +$AllTests = Get-ChildItem $PSScriptRoot/end-to-end-tests-dir/*.ps1 +if ($Filter -ne $Null) { + $AllTests = $AllTests | ? { $_ -match $Filter } } +$n = 1 +$m = $AllTests.Count -function Require-FileExists { - [CmdletBinding()] - Param( - [string]$File - ) - if (-Not (Test-Path $File)) { - throw "'$CurrentTest' failed to create file '$File'" - } +$AllTests | % { + Write-Host "[end-to-end-tests.ps1] [$n/$m] Running suite $_" + & $_ + $n += 1 } -function Require-FileNotExists { - [CmdletBinding()] - Param( - [string]$File - ) - if (Test-Path $File) { - throw "'$CurrentTest' should not have created file '$File'" - } -} - -function Throw-IfFailed { - if ($LASTEXITCODE -ne 0) { - throw "'$CurrentTest' had a step with a nonzero exit code" - } -} - -function Throw-IfNotFailed { - if ($LASTEXITCODE -eq 0) { - throw "'$CurrentTest' had a step with an unexpectedly zero exit code" - } -} - -function Run-Vcpkg { - param([string[]]$TestArgs) - $CurrentTest = "./vcpkg $($testArgs -join ' ')" - Write-Host $CurrentTest - ./vcpkg @testArgs -} - -##### Test spaces in the path -Refresh-TestRoot -$CurrentTest = "zlib with spaces in path" -Write-Host $CurrentTest -./vcpkg install zlib "--triplet" $Triplet ` - "--no-binarycaching" ` - "--x-buildtrees-root=$TestingRoot/build Trees" ` - "--x-install-root=$TestingRoot/instalL ed" ` - "--x-packages-root=$TestingRoot/packaG es" -Throw-IfFailed - -##### Binary caching tests -if (-not $IsLinux -and -not $IsMacOS) { - Refresh-TestRoot - # Test msbuild props and targets - $CurrentTest = "zlib:x86-windows-static msbuild scripts\testing\integrate-install\..." - Write-Host $CurrentTest - ./vcpkg $commonArgs install zlib:x86-windows-static --x-binarysource=clear - Throw-IfFailed - foreach ($project in @("VcpkgTriplet", "VcpkgTriplet2", "VcpkgUseStatic", "VcpkgUseStatic2")) { - $CurrentTest = "msbuild scripts\testing\integrate-install\$project.vcxproj" - ./vcpkg $commonArgs env "msbuild scripts\testing\integrate-install\$project.vcxproj /p:VcpkgRoot=$TestingRoot /p:IntDir=$TestingRoot\int\ /p:OutDir=$TestingRoot\out\ " - Throw-IfFailed - Remove-Item -Recurse -Force $TestingRoot\int - Remove-Item -Recurse -Force $TestingRoot\out - } - $CurrentTest = "zlib:x86-windows msbuild scripts\testing\integrate-install\..." - Write-Host $CurrentTest - ./vcpkg $commonArgs install zlib:x86-windows --x-binarysource=clear - Throw-IfFailed - foreach ($project in @("Project1", "NoProps")) { - $CurrentTest = "msbuild scripts\testing\integrate-install\$project.vcxproj" - Write-Host $CurrentTest - ./vcpkg $commonArgs env "msbuild scripts\testing\integrate-install\$project.vcxproj /p:VcpkgRoot=$TestingRoot /p:IntDir=$TestingRoot\int\ /p:OutDir=$TestingRoot\out\ " - Throw-IfFailed - Remove-Item -Recurse -Force $TestingRoot\int - Remove-Item -Recurse -Force $TestingRoot\out - } -} - -Refresh-TestRoot - -# Test simple installation -Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "--binarycaching", "--x-binarysource=clear;files,$ArchiveRoot,write;nuget,$NuGetRoot,readwrite")) -Throw-IfFailed -Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" - -# Test simple removal -Run-Vcpkg -TestArgs ($commonArgs + @("remove", "rapidjson")) -Throw-IfFailed -Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" - -# Test restoring from files archive -Remove-Item -Recurse -Force $installRoot -Remove-Item -Recurse -Force $buildtreesRoot -Run-Vcpkg -TestArgs ($commonArgs + @("install","rapidjson","--binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read")) -Throw-IfFailed -Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" -Require-FileNotExists "$buildtreesRoot/rapidjson/src" -Require-FileExists "$buildtreesRoot/detect_compiler" - -# Test --no-binarycaching -Remove-Item -Recurse -Force $installRoot -Remove-Item -Recurse -Force $buildtreesRoot -Run-Vcpkg -TestArgs ($commonArgs + @("install","rapidjson","--no-binarycaching","--x-binarysource=clear;files,$ArchiveRoot,read")) -Throw-IfFailed -Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" -Require-FileExists "$buildtreesRoot/rapidjson/src" -Require-FileExists "$buildtreesRoot/detect_compiler" - -# Test --editable -Remove-Item -Recurse -Force $installRoot -Remove-Item -Recurse -Force $buildtreesRoot -Run-Vcpkg -TestArgs ($commonArgs + @("install","rapidjson","--editable","--x-binarysource=clear;files,$ArchiveRoot,read")) -Throw-IfFailed -Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" -Require-FileExists "$buildtreesRoot/rapidjson/src" -Require-FileNotExists "$buildtreesRoot/detect_compiler" - -# Test restoring from nuget -Remove-Item -Recurse -Force $installRoot -Remove-Item -Recurse -Force $buildtreesRoot -Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "--binarycaching", "--x-binarysource=clear;nuget,$NuGetRoot")) -Throw-IfFailed -Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" -Require-FileNotExists "$buildtreesRoot/rapidjson/src" - -# Test four-phase flow -Remove-Item -Recurse -Force $installRoot -ErrorAction SilentlyContinue -Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "--dry-run", "--x-write-nuget-packages-config=$TestingRoot/packages.config")) -Throw-IfFailed -Require-FileNotExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" -Require-FileNotExists "$buildtreesRoot/rapidjson/src" -Require-FileExists "$TestingRoot/packages.config" -if ($IsLinux -or $IsMacOS) { - mono $(./vcpkg fetch nuget) restore $TestingRoot/packages.config -OutputDirectory "$NuGetRoot2" -Source "$NuGetRoot" -} else { - & $(./vcpkg fetch nuget) restore $TestingRoot/packages.config -OutputDirectory "$NuGetRoot2" -Source "$NuGetRoot" -} -Throw-IfFailed -Remove-Item -Recurse -Force $NuGetRoot -ErrorAction SilentlyContinue -mkdir $NuGetRoot -Run-Vcpkg -TestArgs ($commonArgs + @("install", "rapidjson", "tinyxml", "--binarycaching", "--x-binarysource=clear;nuget,$NuGetRoot2;nuget,$NuGetRoot,write")) -Throw-IfFailed -Require-FileExists "$installRoot/$Triplet/include/rapidjson/rapidjson.h" -Require-FileExists "$installRoot/$Triplet/include/tinyxml.h" -Require-FileNotExists "$buildtreesRoot/rapidjson/src" -Require-FileExists "$buildtreesRoot/tinyxml/src" -if ((Get-ChildItem $NuGetRoot -Filter '*.nupkg' | Measure-Object).Count -ne 1) { - throw "In '$CurrentTest': did not create exactly 1 NuGet package" -} - -# Test that prohibiting backcompat features actually prohibits -$backcompatFeaturePorts = @('vcpkg-uses-test-cmake', 'vcpkg-uses-vcpkg-common-functions') -foreach ($backcompatFeaturePort in $backcompatFeaturePorts) { - $succeedArgs = $commonArgs + @('install',$backcompatFeaturePort,'--no-binarycaching') - $failArgs = $succeedArgs + @('--x-prohibit-backcompat-features') - $CurrentTest = "Should fail: ./vcpkg $($failArgs -join ' ')" - Write-Host $CurrentTest - ./vcpkg @failArgs - if ($LastExitCode -ne 0) { - Write-Host "... failed (this is good!)" - } else { - throw $CurrentTest - } - - # Install failed when prohibiting backcompat features, so it should succeed if we allow them - $CurrentTest = "Should succeeed: ./vcpkg $($succeedArgs -join ' ')" - Write-Host $CurrentTest - ./vcpkg @succeedArgs - if ($LastExitCode -ne 0) { - throw $CurrentTest - } else { - Write-Host "... succeeded." - } -} - -# Test export -$CurrentTest = 'Prepare for export test' -Write-Host $CurrentTest -Require-FileNotExists "$TestingRoot/vcpkg-export-output" -Require-FileNotExists "$TestingRoot/vcpkg-export.1.0.0.nupkg" -Require-FileNotExists "$TestingRoot/vcpkg-export-output.zip" -Run-Vcpkg -TestArgs ($commonArgs + @("export", "rapidjson", "tinyxml", "--nuget", "--nuget-id=vcpkg-export", "--nuget-version=1.0.0", "--output=vcpkg-export-output", "--raw", "--zip", "--output-dir=$TestingRoot")) -Require-FileExists "$TestingRoot/vcpkg-export-output" -Require-FileExists "$TestingRoot/vcpkg-export.1.0.0.nupkg" -Require-FileExists "$TestingRoot/vcpkg-export-output.zip" - -# Test bad command lines -Run-Vcpkg -TestArgs ($commonArgs + @("install", "zlib", "--vcpkg-rootttttt", "C:\")) -Throw-IfNotFailed - -Run-Vcpkg -TestArgs ($commonArgs + @("install", "zlib", "--vcpkg-rootttttt=C:\")) -Throw-IfNotFailed - -Run-Vcpkg -TestArgs ($commonArgs + @("install", "zlib", "--fast")) # NB: --fast is not a switch -Throw-IfNotFailed - $LASTEXITCODE = 0 diff --git a/scripts/ports.cmake b/scripts/ports.cmake index 9381b3d1ae..723d7e1df7 100644 --- a/scripts/ports.cmake +++ b/scripts/ports.cmake @@ -140,7 +140,9 @@ if(CMD MATCHES "^BUILD$") elseif(CMD MATCHES "^CREATE$") file(TO_NATIVE_PATH ${VCPKG_ROOT_DIR} NATIVE_VCPKG_ROOT_DIR) file(TO_NATIVE_PATH ${DOWNLOADS} NATIVE_DOWNLOADS) - set(PORT_PATH "${VCPKG_ROOT_DIR}/ports/${PORT}") + if(NOT DEFINED PORT_PATH) + set(PORT_PATH "${VCPKG_ROOT_DIR}/ports/${PORT}") + endif() file(TO_NATIVE_PATH ${PORT_PATH} NATIVE_PORT_PATH) set(PORTFILE_PATH "${PORT_PATH}/portfile.cmake") file(TO_NATIVE_PATH ${PORTFILE_PATH} NATIVE_PORTFILE_PATH) diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h index 16e433d63d..f18f4843cb 100644 --- a/toolsrc/include/vcpkg/vcpkgcmdarguments.h +++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h @@ -132,6 +132,8 @@ namespace vcpkg std::unique_ptr packages_root_dir; constexpr static StringLiteral SCRIPTS_ROOT_DIR_ARG = "x-scripts-root"; std::unique_ptr scripts_root_dir; + constexpr static StringLiteral BUILTIN_PORTS_ROOT_DIR_ARG = "x-builtin-ports-root"; + std::unique_ptr builtin_ports_root_dir; constexpr static StringLiteral DEFAULT_VISUAL_STUDIO_PATH_ENV = "VCPKG_VISUAL_STUDIO_PATH"; std::unique_ptr default_visual_studio_path; diff --git a/toolsrc/include/vcpkg/vcpkgpaths.h b/toolsrc/include/vcpkg/vcpkgpaths.h index 257ecf7bbd..e71f28b0a6 100644 --- a/toolsrc/include/vcpkg/vcpkgpaths.h +++ b/toolsrc/include/vcpkg/vcpkgpaths.h @@ -91,6 +91,7 @@ namespace vcpkg fs::path community_triplets; fs::path scripts; fs::path prefab; + fs::path builtin_ports; fs::path tools; fs::path buildsystems; @@ -142,7 +143,7 @@ namespace vcpkg // the directory of the builtin ports // this should be used only for helper commands, not core commands like `install`. - fs::path builtin_ports_directory() const { return root / fs::u8path("ports"); } + fs::path builtin_ports_directory() const { return this->builtin_ports; } private: std::unique_ptr m_pimpl; diff --git a/toolsrc/src/vcpkg-test/arguments.cpp b/toolsrc/src/vcpkg-test/arguments.cpp index 00a1beb817..f5cbf7b15e 100644 --- a/toolsrc/src/vcpkg-test/arguments.cpp +++ b/toolsrc/src/vcpkg-test/arguments.cpp @@ -14,6 +14,7 @@ TEST_CASE ("VcpkgCmdArguments from lowercase argument sequence", "[arguments]") std::vector t = {"--vcpkg-root", "C:\\vcpkg", "--x-scripts-root=C:\\scripts", + "--x-builtin-ports-root=C:\\ports", "--debug", "--sendmetrics", "--printmetrics", @@ -25,6 +26,7 @@ TEST_CASE ("VcpkgCmdArguments from lowercase argument sequence", "[arguments]") REQUIRE(*v.vcpkg_root_dir == "C:\\vcpkg"); REQUIRE(*v.scripts_root_dir == "C:\\scripts"); + REQUIRE(*v.builtin_ports_root_dir == "C:\\ports"); REQUIRE(v.debug); REQUIRE(*v.debug.get()); REQUIRE(v.send_metrics); @@ -46,6 +48,7 @@ TEST_CASE ("VcpkgCmdArguments from uppercase argument sequence", "[arguments]") std::vector t = {"--VCPKG-ROOT", "C:\\vcpkg", "--X-SCRIPTS-ROOT=C:\\scripts", + "--X-BUILTIN-PORTS-ROOT=C:\\ports", "--DEBUG", "--SENDMETRICS", "--PRINTMETRICS", @@ -57,6 +60,7 @@ TEST_CASE ("VcpkgCmdArguments from uppercase argument sequence", "[arguments]") REQUIRE(*v.vcpkg_root_dir == "C:\\vcpkg"); REQUIRE(*v.scripts_root_dir == "C:\\scripts"); + REQUIRE(*v.builtin_ports_root_dir == "C:\\ports"); REQUIRE(v.debug); REQUIRE(*v.debug.get()); REQUIRE(v.send_metrics); diff --git a/toolsrc/src/vcpkg-test/commands.create.cpp b/toolsrc/src/vcpkg-test/commands.create.cpp deleted file mode 100644 index 8b8dfa2307..0000000000 --- a/toolsrc/src/vcpkg-test/commands.create.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -#include - -#include -#include -#include - -#include -#include - -TEST_CASE ("create smoke test", "[commands-create]") -{ - using namespace vcpkg; - static const std::string argsRaw[] = {"create", "zlib2", "http://zlib.net/zlib-1.2.11.tar.gz", "zlib-1.2.11.zip"}; - - auto& fsWrapper = Files::get_real_filesystem(); - VcpkgCmdArguments args = VcpkgCmdArguments::create_from_arg_sequence(std::begin(argsRaw), std::end(argsRaw)); - VcpkgPaths paths(fsWrapper, args); - const auto exit_code = Commands::Create::perform(args, paths); - REQUIRE(exit_code == 0); - const auto expected_port = paths.builtin_ports_directory() / fs::u8path("zlib2"); - const auto expected_portfile_cmake = expected_port / fs::u8path("portfile.cmake"); - const auto lines = fsWrapper.read_lines(expected_portfile_cmake); - REQUIRE(lines.has_value()); - fsWrapper.remove_all(expected_port, ignore_errors); -} diff --git a/toolsrc/src/vcpkg/commands.create.cpp b/toolsrc/src/vcpkg/commands.create.cpp index c3268bd5eb..28f0377c58 100644 --- a/toolsrc/src/vcpkg/commands.create.cpp +++ b/toolsrc/src/vcpkg/commands.create.cpp @@ -34,7 +34,11 @@ namespace vcpkg::Commands::Create const std::string port_name = args.command_arguments.at(0); const std::string url = remove_trailing_slashes(args.command_arguments.at(1)); - std::vector cmake_args{{"CMD", "CREATE"}, {"PORT", port_name}, {"URL", url}}; + std::vector cmake_args{ + {"CMD", "CREATE"}, + {"PORT", port_name}, + {"URL", url}, + {"PORT_PATH", fs::generic_u8string(paths.builtin_ports_directory() / fs::u8path(port_name))}}; if (args.command_arguments.size() >= 3) { diff --git a/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp b/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp index c311d28e94..5b25b32d8a 100644 --- a/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp +++ b/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp @@ -276,6 +276,7 @@ namespace vcpkg {INSTALL_ROOT_DIR_ARG, &VcpkgCmdArguments::install_root_dir}, {PACKAGES_ROOT_DIR_ARG, &VcpkgCmdArguments::packages_root_dir}, {SCRIPTS_ROOT_DIR_ARG, &VcpkgCmdArguments::scripts_root_dir}, + {BUILTIN_PORTS_ROOT_DIR_ARG, &VcpkgCmdArguments::builtin_ports_root_dir}, }; constexpr static std::pair VcpkgCmdArguments::*> @@ -913,6 +914,7 @@ namespace vcpkg constexpr StringLiteral VcpkgCmdArguments::INSTALL_ROOT_DIR_ARG; constexpr StringLiteral VcpkgCmdArguments::PACKAGES_ROOT_DIR_ARG; constexpr StringLiteral VcpkgCmdArguments::SCRIPTS_ROOT_DIR_ARG; + constexpr StringLiteral VcpkgCmdArguments::BUILTIN_PORTS_ROOT_DIR_ARG; constexpr StringLiteral VcpkgCmdArguments::DEFAULT_VISUAL_STUDIO_PATH_ENV; diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp index 869605ed57..5c7e6a77e8 100644 --- a/toolsrc/src/vcpkg/vcpkgpaths.cpp +++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp @@ -340,6 +340,8 @@ If you wish to silence this error and use classic mode, you can: packages = process_output_directory(filesystem, root, args.packages_root_dir.get(), "packages", VCPKG_LINE_INFO); scripts = process_input_directory(filesystem, root, args.scripts_root_dir.get(), "scripts", VCPKG_LINE_INFO); + builtin_ports = + process_output_directory(filesystem, root, args.builtin_ports_root_dir.get(), "ports", VCPKG_LINE_INFO); prefab = root / fs::u8path("prefab"); if (args.default_visual_studio_path)