Skip to content

Commit bb217a3

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 bb217a3

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

utils/build-windows-toolchain.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ set TMPDIR=%BuildRoot%\tmp
6060
set NINJA_STATUS=[%%f/%%t][%%p][%%es]
6161

6262
:: Build the -Test argument, if any, by subtracting skipped tests
63-
set TestArg=-Test lld,swift,dispatch,foundation,xctest,
63+
set TestArg=-Test lld,swift,dispatch,foundation,xctest,swift-format,
6464
for %%I in (%SKIP_TESTS%) do (call set TestArg=%%TestArg:%%I,=%%)
6565
if "%TestArg:~-1%"=="," (set TestArg=%TestArg:~0,-1%) else (set TestArg= )
6666

utils/build.ps1

Lines changed: 43 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,41 @@ 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+
"-Xswiftc", "-L$(Get-HostProjectBinaryCache Compilers)\lib\swift\host",
2385+
# swift-argument-parser
2386+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache ArgumentParser)\swift",
2387+
"-Xlinker", "-L$(Get-HostProjectBinaryCache ArgumentParser)\lib",
2388+
# swift-cmark
2389+
"-Xswiftc", "-I$($SourceCache)\cmark\src\include",
2390+
"-Xswiftc", "-I$($SourceCache)\cmark\extensions\include",
2391+
"-Xlinker", "-I$($SourceCache)\cmark\extensions\include",
2392+
"-Xlinker", "$(Get-CMark-BinaryCache($HostArch))\src\cmark-gfm.lib",
2393+
"-Xlinker", "$(Get-CMark-BinaryCache($HostArch))\extensions\cmark-gfm-extensions.lib",
2394+
# swift-markdown
2395+
"-Xlinker", "$(Get-HostProjectBinaryCache Markdown)\lib\CAtomic.lib",
2396+
"-Xswiftc", "-I$($SourceCache)\swift-markdown\Sources\CAtomic\include",
2397+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Markdown)\swift",
2398+
"-Xlinker", "-L$(Get-HostProjectBinaryCache Markdown)\lib",
2399+
# swift-format
2400+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Format)\swift",
2401+
"-Xlinker", "-L$(Get-HostProjectBinaryCache Format)\lib"
2402+
)
2403+
2404+
Isolate-EnvVars {
2405+
$env:SWIFTFORMAT_BUILD_ONLY_TESTS=1
2406+
Build-SPMProject `
2407+
-Src "$SourceCache\swift-format" `
2408+
-Bin (Join-Path -Path $HostArch.BinaryCache -ChildPath swift-format) `
2409+
-Arch $HostArch `
2410+
-Test `
2411+
@SwiftPMArguments
2412+
}
2413+
}
2414+
23772415
function Build-IndexStoreDB($Arch) {
23782416
$SDKInstallRoot = (Get-HostSwiftSDK);
23792417

@@ -2744,6 +2782,7 @@ if (-not $IsCrossCompiling) {
27442782
}
27452783
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
27462784
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
2785+
if ($Test -contains "swift-format") { Test-Format }
27472786
}
27482787

27492788
# Custom exception printing for more detailed exception information

0 commit comments

Comments
 (0)