Skip to content

Commit f1bbfc8

Browse files
committed
[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.
1 parent 8ae66ec commit f1bbfc8

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

utils/build.ps1

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ function Build-CMakeProject {
11821182
}
11831183

11841184
if ($UseBuiltCompilers.Contains("Swift")) {
1185-
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$($BuildArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1185+
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMark-BinaryCache($Arch))\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
11861186
} elseif ($UsePinnedCompilers.Contains("Swift")) {
11871187
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
11881188
}
@@ -1326,12 +1326,15 @@ function Build-WiXProject() {
13261326
Invoke-Program $msbuild @MSBuildArgs
13271327
}
13281328

1329+
function Get-CMark-BinaryCache($Arch) {
1330+
return "$($Arch.BinaryCache)\cmark-gfm-0.29.0.gfm.13"
1331+
}
13291332
function Build-CMark($Arch) {
13301333
$ArchName = $Arch.LLVMName
13311334

13321335
Build-CMakeProject `
13331336
-Src $SourceCache\cmark `
1334-
-Bin "$($Arch.BinaryCache)\cmark-gfm-0.29.0.gfm.13" `
1337+
-Bin (Get-CMark-BinaryCache($Arch)) `
13351338
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
13361339
-Arch $Arch `
13371340
-Defines @{
@@ -1400,7 +1403,7 @@ function Build-Compilers() {
14001403
$BuildTools = Join-Path -Path (Get-BuildProjectBinaryCache BuildTools) -ChildPath bin
14011404

14021405
if ($TestClang -or $TestLLD -or $TestLLDB -or $TestLLVM -or $TestSwift) {
1403-
$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"
1406+
$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"
14041407
$Targets = @()
14051408
$TestingDefines = @{
14061409
SWIFT_BUILD_DYNAMIC_SDK_OVERLAY = "YES";
@@ -1745,7 +1748,7 @@ function Build-Runtime([Platform]$Platform, $Arch) {
17451748

17461749

17471750
Isolate-EnvVars {
1748-
$env:Path = "$($BuildArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$(Get-PinnedToolchainRuntime);${env:Path}"
1751+
$env:Path = "$(Get-CMark-BinaryCache($Arch))\src;$(Get-PinnedToolchainRuntime);${env:Path}"
17491752

17501753
$CompilersBinaryCache = if ($IsCrossCompiling) {
17511754
Get-BuildProjectBinaryCache Compilers
@@ -2374,6 +2377,40 @@ function Build-Format($Arch) {
23742377
}
23752378
}
23762379

2380+
function Test-Format {
2381+
$SwiftPMArguments = @(
2382+
# swift-syntax
2383+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Compilers)\lib\swift\host",
2384+
# swift-argument-parser
2385+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache ArgumentParser)\swift",
2386+
"-Xlinker", "-L$(Get-HostProjectBinaryCache ArgumentParser)\lib",
2387+
# swift-cmark
2388+
"-Xswiftc", "-I$($SourceCache)\cmark\src\include",
2389+
"-Xswiftc", "-I$($SourceCache)\cmark\extensions\include",
2390+
"-Xlinker", "-I$($SourceCache)\cmark\extensions\include",
2391+
"-Xlinker", "$(Get-CMark-BinaryCache($HostArch))\src\cmark-gfm.lib",
2392+
"-Xlinker", "$(Get-CMark-BinaryCache($HostArch))\extensions\cmark-gfm-extensions.lib",
2393+
# swift-markdown
2394+
"-Xlinker", "$(Get-HostProjectBinaryCache Markdown)\lib\CAtomic.lib",
2395+
"-Xswiftc", "-I$($SourceCache)\swift-markdown\Sources\CAtomic\include",
2396+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Markdown)\swift",
2397+
"-Xlinker", "-L$(Get-HostProjectBinaryCache Markdown)\lib",
2398+
# swift-format
2399+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Format)\swift",
2400+
"-Xlinker", "-L$(Get-HostProjectBinaryCache Format)\lib"
2401+
)
2402+
2403+
Isolate-EnvVars {
2404+
$env:SWIFTFORMAT_BUILD_ONLY_TESTS=1
2405+
Build-SPMProject `
2406+
-Src "$SourceCache\swift-format" `
2407+
-Bin (Join-Path -Path $HostArch.BinaryCache -ChildPath swift-format) `
2408+
-Arch $HostArch `
2409+
-Test `
2410+
@SwiftPMArguments
2411+
}
2412+
}
2413+
23772414
function Build-IndexStoreDB($Arch) {
23782415
$SDKInstallRoot = (Get-HostSwiftSDK);
23792416

@@ -2744,6 +2781,7 @@ if (-not $IsCrossCompiling) {
27442781
}
27452782
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
27462783
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
2784+
if ($Test -contains "swift-format") { Test-Format }
27472785
}
27482786

27492787
# Custom exception printing for more detailed exception information

0 commit comments

Comments
 (0)