From c6b0084c8f42fd4e85e4884119ec1e65c2838b11 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 2 Feb 2024 09:08:42 -0800 Subject: [PATCH] utils: add support for testing self-hosted SPM `-Test swiftpm` will use the self-hosted build of SPM to run the test suite. By using the `SWIFTCI_USE_LOCAL_DEPS=1` environment variable, we do reduce some of the cost of this by not recloning the repositories, but the entire dependency tree must be built a second time due to the switch in the build system. --- utils/build.ps1 | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index 00a778fef860a..3a82f6f7afb14 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -780,6 +780,7 @@ function Build-SPMProject { [string] $Src, [string] $Bin, [hashtable] $Arch, + [switch] $Test = $false, [Parameter(ValueFromRemainingArguments)] [string[]] $AdditionalArguments ) @@ -816,7 +817,8 @@ function Build-SPMProject { $Arguments += @("-debug-info-format", "none") } - Invoke-Program "$ToolchainInstallRoot\usr\bin\swift.exe" "build" @Arguments @AdditionalArguments + $Action = if ($Test) { "test" } else { "build" } + Invoke-Program "$ToolchainInstallRoot\usr\bin\swift.exe" $Action @Arguments @AdditionalArguments } if (-not $ToBatch) { @@ -1601,14 +1603,14 @@ function Build-Certificates($Arch) { } function Build-PackageManager($Arch) { - $SrcPath = "$SourceCache\swift-package-manager" - if (-not (Test-Path -PathType Container $SrcPath)) { - # The Apple CI clones this repo as "swiftpm" - $SrcPath = "$SourceCache\swiftpm" + $SrcDir = if (Test-Path -Path "$SourceCache\swift-package-manager" -PathType Container) { + "$SourceCache\swift-package-manager" + } else { + "$SourceCache\swiftpm" } Build-CMakeProject ` - -Src $SrcPath ` + -Src $SrcDir ` -Bin $BinaryCache\12 ` -InstallTo "$($Arch.ToolchainInstallRoot)\usr" ` -Arch $Arch ` @@ -1749,6 +1751,25 @@ function Build-DocC() { } } +function Test-PackageManager() { + $OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath swift-package-manager + $SrcDir = if (Test-Path -Path "$SourceCache\swift-package-manager" -PathType Container) { + "$SourceCache\swift-package-manager" + } else { + "$SourceCache\swiftpm" + } + + Isolate-EnvVars { + $env:SWIFTCI_USE_LOCAL_DEPS=1 + Build-SPMProject ` + -Test ` + -Src $SrcDir ` + -Bin $OutDir ` + -Arch $HostArch ` + -Xcc -Xclang -Xcc -fno-split-cold-code -Xcc "-I$LibraryRoot\sqlite-3.43.2\usr\include" -Xlinker "-L$LibraryRoot\sqlite-3.43.2\usr\lib" + } +} + function Build-Installer($Arch) { $Properties = @{ BundleFlavor = "offline"; @@ -1900,6 +1921,7 @@ if ($Test -contains "dispatch") { Build-Dispatch $HostArch -Test } if ($Test -contains "foundation") { Build-Foundation $HostArch -Test } if ($Test -contains "xctest") { Build-XCTest $HostArch -Test } if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test } +if ($Test -contains "swiftpm") { Test-PackageManager $HostArch } # Custom exception printing for more detailed exception information } catch {