From bb217a3a97c281a8de6d9958be6640559a175471 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Fri, 11 Oct 2024 16:39:09 -0700 Subject: [PATCH] [Windows] Run swift-format tests from build.ps1 The basic idea is that we build all libraries for the executable that will be included in the toolchain using CMake. swift-format then has a mode in its Package manifest that allows it to build just the test and test support targets, requiring all search paths to find those libraries to be passed in. We use that to only build swift-format's test using SwiftPM and re-use all the libraries that were already built using CMake. --- utils/build-windows-toolchain.bat | 2 +- utils/build.ps1 | 47 ++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/utils/build-windows-toolchain.bat b/utils/build-windows-toolchain.bat index 42f3309fe895f..64a00b0ee3da0 100644 --- a/utils/build-windows-toolchain.bat +++ b/utils/build-windows-toolchain.bat @@ -60,7 +60,7 @@ set TMPDIR=%BuildRoot%\tmp set NINJA_STATUS=[%%f/%%t][%%p][%%es] :: Build the -Test argument, if any, by subtracting skipped tests -set TestArg=-Test lld,swift,dispatch,foundation,xctest, +set TestArg=-Test lld,swift,dispatch,foundation,xctest,swift-format, for %%I in (%SKIP_TESTS%) do (call set TestArg=%%TestArg:%%I,=%%) if "%TestArg:~-1%"=="," (set TestArg=%TestArg:~0,-1%) else (set TestArg= ) diff --git a/utils/build.ps1 b/utils/build.ps1 index 27559ea2e946d..05b9e9f115295 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -1182,7 +1182,7 @@ function Build-CMakeProject { } if ($UseBuiltCompilers.Contains("Swift")) { - $env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$($BuildArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}" + $env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMark-BinaryCache($Arch))\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}" } elseif ($UsePinnedCompilers.Contains("Swift")) { $env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}" } @@ -1326,12 +1326,15 @@ function Build-WiXProject() { Invoke-Program $msbuild @MSBuildArgs } +function Get-CMark-BinaryCache($Arch) { + return "$($Arch.BinaryCache)\cmark-gfm-0.29.0.gfm.13" +} function Build-CMark($Arch) { $ArchName = $Arch.LLVMName Build-CMakeProject ` -Src $SourceCache\cmark ` - -Bin "$($Arch.BinaryCache)\cmark-gfm-0.29.0.gfm.13" ` + -Bin (Get-CMark-BinaryCache($Arch)) ` -InstallTo "$($Arch.ToolchainInstallRoot)\usr" ` -Arch $Arch ` -Defines @{ @@ -1400,7 +1403,7 @@ function Build-Compilers() { $BuildTools = Join-Path -Path (Get-BuildProjectBinaryCache BuildTools) -ChildPath bin if ($TestClang -or $TestLLD -or $TestLLDB -or $TestLLVM -or $TestSwift) { - $env:Path = "$($HostArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$CompilersBinaryCache\tools\swift\libdispatch-windows-$($Arch.LLVMName)-prefix\bin;$CompilersBinaryCache\bin;$env:Path;$VSInstallRoot\DIA SDK\bin\$($HostArch.VSName);$UnixToolsBinDir" + $env:Path = "$(Get-CMark-BinaryCache($Arch))\src;$CompilersBinaryCache\tools\swift\libdispatch-windows-$($Arch.LLVMName)-prefix\bin;$CompilersBinaryCache\bin;$env:Path;$VSInstallRoot\DIA SDK\bin\$($HostArch.VSName);$UnixToolsBinDir" $Targets = @() $TestingDefines = @{ SWIFT_BUILD_DYNAMIC_SDK_OVERLAY = "YES"; @@ -1745,7 +1748,7 @@ function Build-Runtime([Platform]$Platform, $Arch) { Isolate-EnvVars { - $env:Path = "$($BuildArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$(Get-PinnedToolchainRuntime);${env:Path}" + $env:Path = "$(Get-CMark-BinaryCache($Arch))\src;$(Get-PinnedToolchainRuntime);${env:Path}" $CompilersBinaryCache = if ($IsCrossCompiling) { Get-BuildProjectBinaryCache Compilers @@ -2374,6 +2377,41 @@ function Build-Format($Arch) { } } +function Test-Format { + $SwiftPMArguments = @( + # swift-syntax + "-Xswiftc", "-I$(Get-HostProjectBinaryCache Compilers)\lib\swift\host", + "-Xswiftc", "-L$(Get-HostProjectBinaryCache Compilers)\lib\swift\host", + # swift-argument-parser + "-Xswiftc", "-I$(Get-HostProjectBinaryCache ArgumentParser)\swift", + "-Xlinker", "-L$(Get-HostProjectBinaryCache ArgumentParser)\lib", + # swift-cmark + "-Xswiftc", "-I$($SourceCache)\cmark\src\include", + "-Xswiftc", "-I$($SourceCache)\cmark\extensions\include", + "-Xlinker", "-I$($SourceCache)\cmark\extensions\include", + "-Xlinker", "$(Get-CMark-BinaryCache($HostArch))\src\cmark-gfm.lib", + "-Xlinker", "$(Get-CMark-BinaryCache($HostArch))\extensions\cmark-gfm-extensions.lib", + # swift-markdown + "-Xlinker", "$(Get-HostProjectBinaryCache Markdown)\lib\CAtomic.lib", + "-Xswiftc", "-I$($SourceCache)\swift-markdown\Sources\CAtomic\include", + "-Xswiftc", "-I$(Get-HostProjectBinaryCache Markdown)\swift", + "-Xlinker", "-L$(Get-HostProjectBinaryCache Markdown)\lib", + # swift-format + "-Xswiftc", "-I$(Get-HostProjectBinaryCache Format)\swift", + "-Xlinker", "-L$(Get-HostProjectBinaryCache Format)\lib" + ) + + Isolate-EnvVars { + $env:SWIFTFORMAT_BUILD_ONLY_TESTS=1 + Build-SPMProject ` + -Src "$SourceCache\swift-format" ` + -Bin (Join-Path -Path $HostArch.BinaryCache -ChildPath swift-format) ` + -Arch $HostArch ` + -Test ` + @SwiftPMArguments + } +} + function Build-IndexStoreDB($Arch) { $SDKInstallRoot = (Get-HostSwiftSDK); @@ -2744,6 +2782,7 @@ if (-not $IsCrossCompiling) { } if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test } if ($Test -contains "swiftpm") { Test-PackageManager $HostArch } + if ($Test -contains "swift-format") { Test-Format } } # Custom exception printing for more detailed exception information