Skip to content

Commit befc15e

Browse files
authored
Merge pull request #80082 from compnerd/isolated
utils: split `Build-*` into `Build-` and `Test-`
2 parents 8a0d118 + f20ff95 commit befc15e

File tree

1 file changed

+121
-116
lines changed

1 file changed

+121
-116
lines changed

utils/build.ps1

+121-116
Original file line numberDiff line numberDiff line change
@@ -2283,25 +2283,31 @@ function Write-SDKSettingsPlist([Platform]$Platform, $Arch) {
22832283
$SDKSettings | ConvertTo-JSON | Out-FIle -FilePath "$(Get-SwiftSDK $Platform)\SDKSettings.json"
22842284
}
22852285

2286-
function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
2287-
Invoke-IsolatingEnvVars {
2288-
if ($Test) {
2289-
$Targets = @("default", "ExperimentalTest")
2290-
$InstallPath = ""
2291-
$env:CTEST_OUTPUT_ON_FAILURE = "YES"
2292-
} else {
2293-
$Targets = @("install")
2294-
$InstallPath = "$(Get-SwiftSDK $Platform)\usr"
2286+
function Build-Dispatch([Platform]$Platform, $Arch) {
2287+
Build-CMakeProject `
2288+
-Src $SourceCache\swift-corelibs-libdispatch `
2289+
-Bin (Get-ProjectBinaryCache $Arch Dispatch) `
2290+
-InstallTo "$(Get-SwiftSDK $Platform)\usr" `
2291+
-Arch $Arch `
2292+
-Platform $Platform `
2293+
-SwiftSDK (Get-SwiftSDK $Platform) `
2294+
-UseBuiltCompilers C,CXX,Swift `
2295+
-Defines @{
2296+
ENABLE_SWIFT = "YES";
22952297
}
2298+
}
2299+
2300+
function Test-Dispatch {
2301+
Invoke-IsolatingEnvVars {
2302+
$env:CTEST_OUTPUT_ON_FAILURE = "YES"
22962303

22972304
Build-CMakeProject `
22982305
-Src $SourceCache\swift-corelibs-libdispatch `
2299-
-Bin (Get-ProjectBinaryCache $Arch Dispatch) `
2300-
-InstallTo $InstallPath `
2301-
-Arch $Arch `
2302-
-Platform $Platform `
2303-
-BuildTargets $Targets `
2304-
-SwiftSDK (Get-SwiftSDK $Platform) `
2306+
-Bin (Get-ProjectBinaryCache $BuildArch Dispatch) `
2307+
-Arch $BuildArch `
2308+
-Platform Windows `
2309+
-SwiftSDK (Get-SwiftSDK Windows) `
2310+
-BuildTargets default,ExperimentalTest `
23052311
-UseBuiltCompilers C,CXX,Swift `
23062312
-Defines @{
23072313
ENABLE_SWIFT = "YES";
@@ -2317,72 +2323,68 @@ function Build-Foundation {
23172323
[Platform] $Platform,
23182324
[Parameter(Position = 1, Mandatory = $true)]
23192325
[hashtable] $Arch,
2320-
[switch] $Static = $false,
2321-
[switch] $Test = $false
2326+
[switch] $Static = $false
23222327
)
23232328

2324-
if ($Test) {
2325-
# Foundation tests build via swiftpm rather than CMake
2326-
Build-SPMProject `
2327-
-Action Test `
2328-
-Src $SourceCache\swift-foundation `
2329-
-Bin "$BinaryCache\$($Arch.LLVMTarget)\CoreFoundationTests" `
2330-
-Arch $HostArch `
2331-
-Configuration $FoundationTestConfiguration
2332-
2333-
$ShortArch = $Arch.LLVMName
2334-
Invoke-IsolatingEnvVars {
2335-
$env:DISPATCH_INCLUDE_PATH="$(Get-SwiftSDK $Platform)/usr/include"
2336-
$env:LIBXML_LIBRARY_PATH="$LibraryRoot/libxml2-2.11.5/usr/lib/$Platform/$ShortArch"
2337-
$env:LIBXML_INCLUDE_PATH="$LibraryRoot/libxml2-2.11.5/usr/include/libxml2"
2338-
$env:ZLIB_LIBRARY_PATH="$LibraryRoot/zlib-1.3.1/usr/lib/$Platform/$ShortArch"
2339-
$env:CURL_LIBRARY_PATH="$LibraryRoot/curl-8.9.1/usr/lib/$Platform/$ShortArch"
2340-
$env:CURL_INCLUDE_PATH="$LibraryRoot/curl-8.9.1/usr/include"
2341-
Build-SPMProject `
2342-
-Action Test `
2343-
-Src $SourceCache\swift-corelibs-foundation `
2344-
-Bin "$BinaryCache\$($Arch.LLVMTarget)\FoundationTests" `
2345-
-Arch $HostArch `
2346-
-Configuration $FoundationTestConfiguration
2347-
}
2329+
$FoundationBinaryCache = if ($Static) {
2330+
Get-ProjectBinaryCache $Arch StaticFoundation
23482331
} else {
2349-
$FoundationBinaryCache = if ($Static) {
2350-
Get-ProjectBinaryCache $Arch StaticFoundation
2351-
} else {
2352-
Get-ProjectBinaryCache $Arch DynamicFoundation
2332+
Get-ProjectBinaryCache $Arch DynamicFoundation
2333+
}
2334+
2335+
Build-CMakeProject `
2336+
-Src $SourceCache\swift-corelibs-foundation `
2337+
-Bin $FoundationBinaryCache `
2338+
-InstallTo $(if ($Static) { "$(Get-SwiftSDK $Platform -Identifier "${Platform}Experimental")\usr" } else { "$(Get-SwiftSDK $Platform)\usr" }) `
2339+
-Arch $Arch `
2340+
-Platform $Platform `
2341+
-UseBuiltCompilers ASM,C,CXX,Swift `
2342+
-SwiftSDK (Get-SwiftSDK $Platform) `
2343+
-Defines @{
2344+
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
2345+
CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES";
2346+
CMAKE_NINJA_FORCE_RESPONSE_FILE = "YES";
2347+
CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib";
2348+
ENABLE_TESTING = "NO";
2349+
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
2350+
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$($Arch.LLVMName)\cmake\CURL";
2351+
LibXml2_DIR = "$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$($Arch.LLVMName)\cmake\libxml2-2.11.5";
2352+
ZLIB_LIBRARY = if ($Platform -eq "Windows") {
2353+
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$($Arch.LLVMName)\zlibstatic.lib"
2354+
} else {
2355+
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$($Arch.LLVMName)\libz.a"
2356+
};
2357+
ZLIB_INCLUDE_DIR = "$LibraryRoot\zlib-1.3.1\usr\include";
2358+
dispatch_DIR = (Get-ProjectCMakeModules $Arch Dispatch);
2359+
SwiftSyntax_DIR = (Get-ProjectBinaryCache $HostArch Compilers);
2360+
_SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation";
2361+
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
2362+
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections";
2363+
SwiftFoundation_MACRO = "$(Get-ProjectBinaryCache $BuildArch FoundationMacros)\bin"
23532364
}
2354-
$ShortArch = $Arch.LLVMName
2365+
}
23552366

2356-
Build-CMakeProject `
2367+
function Test-Foundation {
2368+
# Foundation tests build via swiftpm rather than CMake
2369+
Build-SPMProject `
2370+
-Action Test `
2371+
-Src $SourceCache\swift-foundation `
2372+
-Bin "$BinaryCache\$($BuildArch.LLVMTarget)\CoreFoundationTests" `
2373+
-Arch $BuildArch
2374+
2375+
Invoke-IsolatingEnvVars {
2376+
$env:DISPATCH_INCLUDE_PATH="$(Get-SwiftSDK Windows)/usr/include"
2377+
$env:LIBXML_LIBRARY_PATH="$LibraryRoot/libxml2-2.11.5/usr/lib/windows/$($BuildArch.LLVMName)"
2378+
$env:LIBXML_INCLUDE_PATH="$LibraryRoot/libxml2-2.11.5/usr/include/libxml2"
2379+
$env:ZLIB_LIBRARY_PATH="$LibraryRoot/zlib-1.3.1/usr/lib/windows/$($BuildArch.LLVMName)"
2380+
$env:CURL_LIBRARY_PATH="$LibraryRoot/curl-8.9.1/usr/lib/windows/$($BuildArch.LLVMName)"
2381+
$env:CURL_INCLUDE_PATH="$LibraryRoot/curl-8.9.1/usr/include"
2382+
Build-SPMProject `
2383+
-Action Test `
23572384
-Src $SourceCache\swift-corelibs-foundation `
2358-
-Bin $FoundationBinaryCache `
2359-
-InstallTo $(if ($Static) { "$(Get-SwiftSDK $Platform -Identifier "${Platform}Experimental")\usr" } else { "$(Get-SwiftSDK $Platform)\usr" }) `
2360-
-Arch $Arch `
2361-
-Platform $Platform `
2362-
-UseBuiltCompilers ASM,C,CXX,Swift `
2363-
-SwiftSDK (Get-SwiftSDK $Platform) `
2364-
-Defines @{
2365-
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
2366-
CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES";
2367-
CMAKE_NINJA_FORCE_RESPONSE_FILE = "YES";
2368-
CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib";
2369-
ENABLE_TESTING = "NO";
2370-
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
2371-
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
2372-
LibXml2_DIR = "$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$ShortArch\cmake\libxml2-2.11.5";
2373-
ZLIB_LIBRARY = if ($Platform -eq "Windows") {
2374-
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$ShortArch\zlibstatic.lib"
2375-
} else {
2376-
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$ShortArch\libz.a"
2377-
};
2378-
ZLIB_INCLUDE_DIR = "$LibraryRoot\zlib-1.3.1\usr\include";
2379-
dispatch_DIR = (Get-ProjectCMakeModules $Arch Dispatch);
2380-
SwiftSyntax_DIR = (Get-ProjectBinaryCache $HostArch Compilers);
2381-
_SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation";
2382-
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
2383-
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections";
2384-
SwiftFoundation_MACRO = "$(Get-ProjectBinaryCache $BuildArch FoundationMacros)\bin"
2385-
}
2385+
-Bin "$BinaryCache\$($BuildArch.LLVMTarget)\FoundationTests" `
2386+
-Arch $BuildArch `
2387+
-Configuration $FoundationTestConfiguration
23862388
}
23872389
}
23882390

@@ -2474,6 +2476,10 @@ function Build-Testing([Platform]$Platform, $Arch) {
24742476
}
24752477
}
24762478

2479+
function Test-Testing {
2480+
throw "testing Testing is not supported"
2481+
}
2482+
24772483
function Write-PlatformInfoPlist([Platform] $Platform) {
24782484
$Settings = @{
24792485
DefaultProperties = @{
@@ -2579,46 +2585,53 @@ function Build-ToolsSupportCore($Arch) {
25792585
}
25802586
}
25812587

2582-
function Build-LLBuild($Arch, [switch]$Test = $false) {
2588+
function Build-LLBuild($Arch) {
2589+
Build-CMakeProject `
2590+
-Src $SourceCache\llbuild `
2591+
-Bin (Get-ProjectBinaryCache $Arch LLBuild) `
2592+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2593+
-Arch $Arch `
2594+
-Platform Windows `
2595+
-UseMSVCCompilers CXX `
2596+
-UseBuiltCompilers Swift `
2597+
-SwiftSDK (Get-SwiftSDK Windows) `
2598+
-Defines @{
2599+
BUILD_SHARED_LIBS = "YES";
2600+
LLBUILD_SUPPORT_BINDINGS = "Swift";
2601+
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
2602+
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
2603+
}
2604+
}
2605+
2606+
function Test-LLBuild {
2607+
# Build additional llvm executables needed by tests
25832608
Invoke-IsolatingEnvVars {
2584-
if ($Test) {
2585-
# Build additional llvm executables needed by tests
2586-
Invoke-IsolatingEnvVars {
2587-
Invoke-VsDevShell $BuildArch
2588-
Invoke-Program ninja.exe -C (Get-ProjectBinaryCache $BuildArch BuildTools) FileCheck not
2589-
}
2609+
Invoke-VsDevShell $BuildArch
2610+
Invoke-Program ninja.exe -C (Get-ProjectBinaryCache $BuildArch BuildTools) FileCheck not
2611+
}
25902612

2591-
$Targets = @("default", "test-llbuild")
2592-
$TestingDefines = @{
2593-
FILECHECK_EXECUTABLE = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch BuildTools), "bin", "FileCheck.exe"));
2594-
LIT_EXECUTABLE = "$SourceCache\llvm-project\llvm\utils\lit\lit.py";
2595-
}
2596-
$env:Path = "$env:Path;$UnixToolsBinDir"
2597-
$env:AR = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch Compilers), "bin", "llvm-ar.exe"))
2598-
$env:CLANG = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch Compilers), "bin", "clang.exe"))
2599-
$InstallPath = ""
2600-
} else {
2601-
$Targets = @()
2602-
$TestingDefines = @{}
2603-
$InstallPath = "$($Arch.ToolchainInstallRoot)\usr"
2604-
}
2613+
Invoke-IsolatingEnvVars {
2614+
$env:Path = "$env:Path;$UnixToolsBinDir"
2615+
$env:AR = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch Compilers), "bin", "llvm-ar.exe"))
2616+
$env:CLANG = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch Compilers), "bin", "clang.exe"))
26052617

26062618
Build-CMakeProject `
26072619
-Src $SourceCache\llbuild `
2608-
-Bin (Get-ProjectBinaryCache $Arch LLBuild) `
2609-
-InstallTo $InstallPath `
2610-
-Arch $Arch `
2620+
-Bin (Get-ProjectBinaryCache $BuildArch LLBuild) `
2621+
-Arch $BuildArch `
26112622
-Platform Windows `
26122623
-UseMSVCCompilers CXX `
26132624
-UseBuiltCompilers Swift `
26142625
-SwiftSDK (Get-SwiftSDK Windows) `
2615-
-BuildTargets $Targets `
2616-
-Defines ($TestingDefines + @{
2626+
-BuildTargets default,test-llbuild `
2627+
-Defines = @{
26172628
BUILD_SHARED_LIBS = "YES";
2629+
FILECHECK_EXECUTABLE = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch BuildTools), "bin", "FileCheck.exe"));
2630+
LIT_EXECUTABLE = "$SourceCache\llvm-project\llvm\utils\lit\lit.py";
26182631
LLBUILD_SUPPORT_BINDINGS = "Swift";
26192632
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
26202633
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
2621-
})
2634+
}
26222635
}
26232636
}
26242637

@@ -3280,20 +3293,12 @@ if (-not $IsCrossCompiling) {
32803293
Build-Compilers $HostArch @Tests
32813294
}
32823295

3283-
if ($Test -contains "dispatch") {
3284-
Build-Dispatch Windows $HostArch -Test
3285-
}
3286-
if ($Test -contains "foundation") {
3287-
Build-Foundation Windows $HostArch -Test
3288-
}
3289-
if ($Test -contains "xctest") {
3290-
Test-XCTest
3291-
}
3292-
if ($Test -contains "testing") {
3293-
Build-Testing Windows $HostArch -Test
3294-
}
3295-
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
3296-
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
3296+
if ($Test -contains "dispatch") { Test-Dispatch }
3297+
if ($Test -contains "foundation") { Test-Foundation }
3298+
if ($Test -contains "xctest") { Test-XCTest }
3299+
if ($Test -contains "testing") { Test-Testing }
3300+
if ($Test -contains "llbuild") { Test-LLBuild }
3301+
if ($Test -contains "swiftpm") { Test-PackageManager }
32973302
if ($Test -contains "swift-format") { Test-Format }
32983303
if ($Test -contains "sourcekit-lsp") { Test-SourceKitLSP }
32993304

0 commit comments

Comments
 (0)