Skip to content

Commit c740703

Browse files
[windows][toolchain] Prepare non-executable Swift Runtime tests for Android
1 parent c4b0bae commit c740703

File tree

4 files changed

+337
-40
lines changed

4 files changed

+337
-40
lines changed

test/lit.cfg

+27-23
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ elif platform.system() == 'Darwin':
239239
config.substitutions.append( ('%lto_flags', lto_flags) )
240240
config.substitutions.append( ('%use_just_built_liblto', use_just_built_liblto) )
241241
config.substitutions.append( ('%llvm_libs_dir', llvm_libs_dir) )
242-
config.substitutions.append( ('%llvm_plugin_ext', llvm_plugin_ext) )
242+
243+
if llvm_plugin_ext is not None:
244+
config.substitutions.append( ('%llvm_plugin_ext', llvm_plugin_ext) )
243245

244246
# Allow tests to restore the original environment if they need to.
245247
config.substitutions.append( ('%original_path_env', config.environment['PATH']) )
@@ -395,28 +397,6 @@ lit_config.note('Using resource dir: ' + test_resource_dir)
395397
test_clang_resource_dir = lit.util.executeCommand([config.clang, '-print-resource-dir'])[0].rstrip()
396398
lit_config.note('Using Clang resource dir: ' + test_clang_resource_dir)
397399

398-
config.swift_system_overlay_opt = ""
399-
config.clang_system_overlay_opt = ""
400-
config.windows_vfs_overlay_opt = ""
401-
if kIsWindows:
402-
# ucrt.modulemap currently requires -fbuiltin-headers-in-system-modules. -strict-implicit-module-context
403-
# is necessary for -Xcc arguments to be passed through ModuleInterfaceLoader.
404-
config.swift_system_overlay_opt = "-vfsoverlay {} -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
405-
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
406-
)
407-
# this variant is for extract-symbolgraph which doesn't accept all the same arugments as swiftc
408-
# so the extra ceremony lets us pass in the relevant pieces needed for Windows SDK access.
409-
config.windows_vfs_overlay_opt = "-Xcc -vfsoverlay -Xcc {} -Xcc -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
410-
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
411-
)
412-
config.clang_system_overlay_opt = "-Xcc -ivfsoverlay -Xcc {} -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
413-
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
414-
)
415-
config.substitutions.append( ('%windows_vfs_overlay_opt', config.windows_vfs_overlay_opt) )
416-
stdlib_resource_dir_opt = config.resource_dir_opt
417-
sourcekitd_framework_dir = config.swift_lib_dir
418-
config.substitutions.append( ('%test-resource-dir', test_resource_dir) )
419-
420400
# Parse the variant triple.
421401
# FIXME: We ought to parse 'run_environment' separately from 'run_os'.
422402
(run_cpu, run_vendor, run_os, run_vers) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups()
@@ -479,6 +459,28 @@ if test_sdk_overlay_dir is not None:
479459
lit_config.note('Using SDK overlay dir: ' + test_sdk_overlay_dir)
480460
config.resource_dir_opt += (" %s" % sdk_overlay_dir_opt)
481461

462+
config.swift_system_overlay_opt = ""
463+
config.clang_system_overlay_opt = ""
464+
config.windows_vfs_overlay_opt = ""
465+
if kIsWindows and run_os in ['windows-msvc']:
466+
# ucrt.modulemap currently requires -fbuiltin-headers-in-system-modules. -strict-implicit-module-context
467+
# is necessary for -Xcc arguments to be passed through ModuleInterfaceLoader.
468+
config.swift_system_overlay_opt = "-vfsoverlay {} -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
469+
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
470+
)
471+
# this variant is for extract-symbolgraph which doesn't accept all the same arugments as swiftc
472+
# so the extra ceremony lets us pass in the relevant pieces needed for Windows SDK access.
473+
config.windows_vfs_overlay_opt = "-Xcc -vfsoverlay -Xcc {} -Xcc -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
474+
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
475+
)
476+
config.clang_system_overlay_opt = "-Xcc -ivfsoverlay -Xcc {} -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
477+
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
478+
)
479+
config.substitutions.append( ('%windows_vfs_overlay_opt', config.windows_vfs_overlay_opt) )
480+
stdlib_resource_dir_opt = config.resource_dir_opt
481+
sourcekitd_framework_dir = config.swift_lib_dir
482+
config.substitutions.append( ('%test-resource-dir', test_resource_dir) )
483+
482484
# Default to Swift 4 for now.
483485
# Note that this accepts both `--param swift-version` (like the compiler flag)
484486
# and `--param swift_version` (like a lit configuration parameter).
@@ -1944,6 +1946,7 @@ elif run_os == 'linux-androideabi' or run_os == 'linux-android':
19441946
config.target_swift_symbolgraph_extract = ' '.join([
19451947
config.swift_symbolgraph_extract,
19461948
'-target', config.variant_triple,
1949+
'-sdk', config.variant_sdk, config.resource_dir_opt,
19471950
mcp_opt])
19481951
config.target_swift_synthesize_interface = ' '.join([
19491952
config.swift_synthesize_interface,
@@ -2747,6 +2750,7 @@ config.substitutions.insert(0, ('%check-c-header-in-clang',
27472750
# Verifies that a C++ file can be compiled without warnings except for some exceptions.
27482751
config.substitutions.insert(0, ('%check-cxx-header-in-clang',
27492752
'%clangxx -fsyntax-only -x c++-header ' + extraCheckWarningFlags +
2753+
' --sysroot %r ' % config.variant_sdk +
27502754
# Use standard header/framework search paths.
27512755
'-F %%clang-importer-sdk-path/frameworks '
27522756
'-I %%clang-include-dir %%cxx-stdlib-include '

test/refactoring/lit.local.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
config.substitutions.append((r'%refactor-check-compiles', f'{config.python} {config.refactor_check_compiles} -swift-refactor {config.swift_refactor} -swift-frontend {config.swift_frontend} -temp-dir %t {config.resource_dir_opt}'))
2-
config.substitutions.append((r'%refactor', f'{config.swift_refactor} {config.resource_dir_opt}'))
1+
config.substitutions.append((r'%refactor-check-compiles', f'{config.python} {config.refactor_check_compiles} -swift-refactor {config.swift_refactor} -swift-frontend {config.swift_frontend} -temp-dir %t {config.resource_dir_opt} -target {config.variant_triple}'))
2+
config.substitutions.append((r'%refactor', f'{config.swift_refactor} {config.resource_dir_opt} -target {config.variant_triple}'))

utils/build.ps1

+60-15
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,24 @@ function Write-PList {
16371637
-OutFile $Path
16381638
}
16391639

1640+
function Load-LitTestOverrides($Filename) {
1641+
function Select-LitTestOverrides($Prefix) {
1642+
$MatchingLines = Get-Content $Filename | Select-String -Pattern "`^${Prefix}.*$"
1643+
return $MatchingLines | ForEach-Object { ($_ -replace $Prefix,"").Trim() }
1644+
}
1645+
1646+
$TestsToXFail = Select-LitTestOverrides "xfail"
1647+
Write-Host "TestsToXFail=$TestsToXFail"
1648+
if ($TestsToXFail -and $TestsToXFail.Length -ne 0) {
1649+
$env:LIT_XFAIL = $TestsToXFail -join ";"
1650+
}
1651+
$TestsToSkip = Select-LitTestOverrides "skip"
1652+
Write-Host "TestsToSkip=$TestsToSkip"
1653+
if ($TestsToSkip -and $TestsToSkip.Length -gt 0) {
1654+
$env:LIT_FILTER_OUT = "($($TestsToSkip -join '|'))"
1655+
}
1656+
}
1657+
16401658
function Build-Compilers() {
16411659
[CmdletBinding(PositionalBinding = $false)]
16421660
param
@@ -1676,19 +1694,8 @@ function Build-Compilers() {
16761694
if ($TestLLDB) {
16771695
$Targets += @("check-lldb")
16781696

1679-
function Select-LitTestOverrides {
1680-
param([string] $TestStatus)
1681-
1682-
$MatchingLines=(Get-Content $PSScriptRoot/windows-llvm-lit-test-overrides.txt | Select-String -Pattern "`^${TestStatus}.*$")
1683-
$TestNames=$MatchingLines | ForEach-Object { ($_ -replace $TestStatus,"").Trim() }
1684-
return $TestNames
1685-
}
1686-
1687-
# Override some test results with llvm-lit.
1688-
$TestsToXFail=Select-LitTestOverrides "xfail"
1689-
$TestsToSkip=Select-LitTestOverrides "skip"
1690-
$env:LIT_XFAIL=$TestsToXFail -join ";"
1691-
$env:LIT_FILTER_OUT="($($TestsToSkip -join '|'))"
1697+
# Override test filter for known issues in downstream LLDB
1698+
Load-LitTestOverrides $PSScriptRoot/windows-llvm-lit-test-overrides.txt
16921699

16931700
# Transitive dependency of _lldb.pyd
16941701
$RuntimeBinaryCache = Get-TargetProjectBinaryCache $Arch Runtime
@@ -2138,8 +2145,6 @@ function Build-Runtime([Platform]$Platform, $Arch) {
21382145
$PlatformDefines += @{
21392146
LLVM_ENABLE_LIBCXX = "YES";
21402147
SWIFT_USE_LINKER = "lld";
2141-
SWIFT_INCLUDE_TESTS = "NO";
2142-
SWIFT_INCLUDE_TEST_BINARIES = "NO";
21432148
# Clang[<18] doesn't provide the _Builtin_float module.
21442149
SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT = "YES";
21452150
}
@@ -2183,6 +2188,40 @@ function Build-Runtime([Platform]$Platform, $Arch) {
21832188
}
21842189
}
21852190

2191+
function Test-Runtime([Platform]$Platform, $Arch) {
2192+
if ($IsCrossCompiling) {
2193+
throw "Swift runtime tests are not supported when cross-compiling"
2194+
}
2195+
if (-not (Test-Path (Get-TargetProjectBinaryCache $Arch Runtime))) {
2196+
throw "Swift runtime tests are supposed to reconfigure the existing build"
2197+
}
2198+
$CompilersBinaryCache = Get-HostProjectBinaryCache Compilers
2199+
if (-not (Test-Path "$CompilersBinaryCache\bin\FileCheck.exe")) {
2200+
# These will exist if we test any of llvm/clang/lldb/lld/swift as well
2201+
throw "LIT test utilities not found in $CompilersBinaryCache\bin"
2202+
}
2203+
2204+
Invoke-IsolatingEnvVars {
2205+
# Filter known issues when testing on Windows
2206+
Load-LitTestOverrides $PSScriptRoot/windows-swift-android-lit-test-overrides.txt
2207+
$env:Path = "$(Get-CMarkBinaryCache $Arch)\src;$(Get-PinnedToolchainRuntime);${env:Path};$UnixToolsBinDir"
2208+
Build-CMakeProject `
2209+
-Src $SourceCache\swift `
2210+
-Bin (Get-TargetProjectBinaryCache $Arch Runtime) `
2211+
-Arch $Arch `
2212+
-Platform $Platform `
2213+
-UseBuiltCompilers C,CXX,Swift `
2214+
-BuildTargets check-swift-validation-only_non_executable `
2215+
-Defines @{
2216+
SWIFT_INCLUDE_TESTS = "YES";
2217+
SWIFT_INCLUDE_TEST_BINARIES = "YES";
2218+
SWIFT_BUILD_TEST_SUPPORT_MODULES = "YES";
2219+
SWIFT_NATIVE_LLVM_TOOLS_PATH = Join-Path -Path $CompilersBinaryCache -ChildPath "bin";
2220+
LLVM_LIT_ARGS = "-vv";
2221+
}
2222+
}
2223+
}
2224+
21862225
function Build-ExperimentalRuntime {
21872226
[CmdletBinding(PositionalBinding = $false)]
21882227
param
@@ -3322,6 +3361,12 @@ if (-not $IsCrossCompiling) {
33223361
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
33233362
if ($Test -contains "swift-format") { Test-Format }
33243363
if ($Test -contains "sourcekit-lsp") { Test-SourceKitLSP }
3364+
3365+
if ($Test -contains "swift") {
3366+
foreach ($Arch in $AndroidSDKArchs) {
3367+
Test-Runtime Android $Arch
3368+
}
3369+
}
33253370
}
33263371

33273372
# Custom exception printing for more detailed exception information

0 commit comments

Comments
 (0)