Skip to content

[Windows] Run swift-format tests from build.ps1 #76900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion utils/build-windows-toolchain.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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= )

Expand Down
47 changes: 43 additions & 4 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Expand Down Expand Up @@ -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 @{
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down