Skip to content

Commit 4d1d1c5

Browse files
committed
Invoke foundation tests via SwiftPM
1 parent cc55495 commit 4d1d1c5

File tree

6 files changed

+275
-69
lines changed

6 files changed

+275
-69
lines changed

utils/build-windows-toolchain.bat

+1-1
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 swift,dispatch,xctest,
63+
set TestArg=-Test swift,dispatch,foundation,xctest,
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

+82-68
Original file line numberDiff line numberDiff line change
@@ -1647,79 +1647,93 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
16471647
}
16481648

16491649
function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
1650-
$DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch
1651-
$SwiftSyntaxDir = Get-HostProjectCMakeModules Compilers
1652-
$FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation
1653-
$ShortArch = $Arch.LLVMName
1650+
if ($Test) {
1651+
# Foundation tests build via swiftpm rather than CMake
1652+
$OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath swift-foundation-tests
16541653

1655-
Isolate-EnvVars {
1656-
if ($Test) {
1657-
$XCTestBinaryCache = Get-TargetProjectBinaryCache $Arch XCTest
1658-
$TestingDefines = @{
1659-
ENABLE_TESTING = "YES";
1660-
XCTest_DIR = "$XCTestBinaryCache\cmake\modules";
1661-
}
1662-
$Targets = @("default", "test")
1663-
$env:Path = "$XCTestBinaryCache;$FoundationBinaryCache\bin;$DispatchBinaryCache;$(Get-TargetProjectBinaryCache $Arch Runtime)\bin;$env:Path"
1664-
$InstallPath = ""
1665-
} else {
1654+
Isolate-EnvVars {
1655+
$env:SWIFTCI_USE_LOCAL_DEPS=1
1656+
Build-SPMProject `
1657+
-Test `
1658+
-Src $SourceCache\swift-foundation `
1659+
-Bin $OutDir `
1660+
-Arch $HostArch
1661+
}
1662+
1663+
$OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath foundation-tests
1664+
1665+
Isolate-EnvVars {
1666+
$env:SWIFTCI_USE_LOCAL_DEPS=1
1667+
Build-SPMProject `
1668+
-Test `
1669+
-Src $SourceCache\swift-corelibs-foundation `
1670+
-Bin $OutDir `
1671+
-Arch $HostArch
1672+
}
1673+
} else {
1674+
$DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch
1675+
$SwiftSyntaxDir = Get-HostProjectCMakeModules Compilers
1676+
$FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation
1677+
$ShortArch = $Arch.LLVMName
1678+
1679+
Isolate-EnvVars {
16661680
$TestingDefines = @{ ENABLE_TESTING = "NO" }
16671681
$Targets = @("default", "install")
16681682
$InstallPath = "$($Arch.SDKInstallRoot)\usr"
1669-
}
16701683

1671-
$env:CTEST_OUTPUT_ON_FAILURE = 1
1672-
Build-CMakeProject `
1673-
-Src $SourceCache\swift-corelibs-foundation `
1674-
-Bin $FoundationBinaryCache `
1675-
-InstallTo $InstallPath `
1676-
-Arch $Arch `
1677-
-Platform $Platform `
1678-
-UseBuiltCompilers ASM,C,CXX,Swift `
1679-
-BuildTargets $Targets `
1680-
-Defines (@{
1681-
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
1682-
# Turn off safeseh for lld as it has safeseh enabled by default
1683-
# and fails with an ICU data object file icudt69l_dat.obj. This
1684-
# matters to X86 only.
1685-
CMAKE_Swift_FLAGS = if ($Arch -eq $ArchX86) { @("-Xlinker", "/SAFESEH:NO") } else { "" };
1686-
CURL_DIR = "$LibraryRoot\curl-8.5.0\usr\lib\$Platform\$ShortArch\cmake\CURL";
1687-
ICU_DATA_LIBRARY_RELEASE = if ($Platform -eq "Windows") {
1688-
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicudt69.lib"
1689-
} else {
1690-
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\libicudt69.a"
1691-
};
1692-
ICU_I18N_LIBRARY_RELEASE = if ($Platform -eq "Windows") {
1693-
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicuin69.lib"
1694-
} else {
1695-
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\libicuin69.a"
1696-
};
1697-
ICU_ROOT = "$LibraryRoot\icu-69.1\usr";
1698-
ICU_INCLUDE_DIR = "$LibraryRoot\icu-69.1\usr\include";
1699-
ICU_UC_LIBRARY_RELEASE = if ($Platform -eq "Windows") {
1700-
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicuuc69.lib";
1701-
} else {
1702-
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\libicuuc69.a"
1703-
};
1704-
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
1705-
"$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$ShortArch\libxml2s.lib";
1706-
} else {
1707-
"$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$ShortArch\libxml2.a";
1708-
};
1709-
LIBXML2_INCLUDE_DIR = "$LibraryRoot\libxml2-2.11.5\usr\include\libxml2";
1710-
LIBXML2_DEFINITIONS = "-DLIBXML_STATIC";
1711-
ZLIB_LIBRARY = if ($Platform -eq "Windows") {
1712-
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$ShortArch\zlibstatic.lib"
1713-
} else {
1714-
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$ShortArch\libz.a"
1715-
};
1716-
ZLIB_INCLUDE_DIR = "$LibraryRoot\zlib-1.3.1\usr\include";
1717-
dispatch_DIR = "$DispatchBinaryCache\cmake\modules";
1718-
SwiftSyntax_DIR = "$SwiftSyntaxDir";
1719-
_SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation";
1720-
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
1721-
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections"
1722-
} + $TestingDefines)
1684+
$env:CTEST_OUTPUT_ON_FAILURE = 1
1685+
Build-CMakeProject `
1686+
-Src $SourceCache\swift-corelibs-foundation `
1687+
-Bin $FoundationBinaryCache `
1688+
-InstallTo $InstallPath `
1689+
-Arch $Arch `
1690+
-Platform $Platform `
1691+
-UseBuiltCompilers ASM,C,CXX,Swift `
1692+
-BuildTargets $Targets `
1693+
-Defines (@{
1694+
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
1695+
# Turn off safeseh for lld as it has safeseh enabled by default
1696+
# and fails with an ICU data object file icudt69l_dat.obj. This
1697+
# matters to X86 only.
1698+
CMAKE_Swift_FLAGS = if ($Arch -eq $ArchX86) { @("-Xlinker", "/SAFESEH:NO") } else { "" };
1699+
CURL_DIR = "$LibraryRoot\curl-8.5.0\usr\lib\$Platform\$ShortArch\cmake\CURL";
1700+
ICU_DATA_LIBRARY_RELEASE = if ($Platform -eq "Windows") {
1701+
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicudt69.lib"
1702+
} else {
1703+
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\libicudt69.a"
1704+
};
1705+
ICU_I18N_LIBRARY_RELEASE = if ($Platform -eq "Windows") {
1706+
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicuin69.lib"
1707+
} else {
1708+
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\libicuin69.a"
1709+
};
1710+
ICU_ROOT = "$LibraryRoot\icu-69.1\usr";
1711+
ICU_INCLUDE_DIR = "$LibraryRoot\icu-69.1\usr\include";
1712+
ICU_UC_LIBRARY_RELEASE = if ($Platform -eq "Windows") {
1713+
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicuuc69.lib";
1714+
} else {
1715+
"$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\libicuuc69.a"
1716+
};
1717+
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
1718+
"$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$ShortArch\libxml2s.lib";
1719+
} else {
1720+
"$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$ShortArch\libxml2.a";
1721+
};
1722+
LIBXML2_INCLUDE_DIR = "$LibraryRoot\libxml2-2.11.5\usr\include\libxml2";
1723+
LIBXML2_DEFINITIONS = "-DLIBXML_STATIC";
1724+
ZLIB_LIBRARY = if ($Platform -eq "Windows") {
1725+
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$ShortArch\zlibstatic.lib"
1726+
} else {
1727+
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$ShortArch\libz.a"
1728+
};
1729+
ZLIB_INCLUDE_DIR = "$LibraryRoot\zlib-1.3.1\usr\include";
1730+
dispatch_DIR = "$DispatchBinaryCache\cmake\modules";
1731+
SwiftSyntax_DIR = "$SwiftSyntaxDir";
1732+
_SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation";
1733+
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
1734+
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections"
1735+
} + $TestingDefines)
1736+
}
17231737
}
17241738
}
17251739

utils/swift_build_support/swift_build_support/build_script_invocation.py

+4
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ def compute_product_pipelines(self):
677677

678678
builder.add_product(products.SwiftPM,
679679
is_enabled=self.args.build_swiftpm)
680+
builder.add_product(products.SwiftFoundationTests,
681+
is_enabled=self.args.build_foundation)
682+
builder.add_product(products.FoundationTests,
683+
is_enabled=self.args.build_foundation)
680684
builder.add_product(products.SwiftSyntax,
681685
is_enabled=self.args.build_swiftsyntax)
682686
builder.add_product(products.SwiftFormat,

utils/swift_build_support/swift_build_support/products/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from .curl import LibCurl
1616
from .earlyswiftdriver import EarlySwiftDriver
1717
from .foundation import Foundation
18+
from .foundationtests import FoundationTests
19+
from .swiftfoundationtests import SwiftFoundationTests
1820
from .indexstoredb import IndexStoreDB
1921
from .libcxx import LibCXX
2022
from .libdispatch import LibDispatch
@@ -48,6 +50,8 @@
4850
__all__ = [
4951
'CMark',
5052
'Foundation',
53+
'FoundationTests',
54+
'SwiftFoundationTests',
5155
'LibCXX',
5256
'LibDispatch',
5357
'LibICU',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# swift_build_support/products/foundationtests.py -----------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
15+
from . import cmark
16+
from . import foundation
17+
from . import libcxx
18+
from . import libdispatch
19+
from . import libicu
20+
from . import llbuild
21+
from . import llvm
22+
from . import product
23+
from . import swift
24+
from . import swiftpm
25+
from . import swiftsyntax
26+
from . import xctest
27+
from .. import shell
28+
from .. import targets
29+
30+
31+
class FoundationTests(product.Product):
32+
@classmethod
33+
def is_build_script_impl_product(cls):
34+
return False
35+
36+
@classmethod
37+
def is_before_build_script_impl_product(cls):
38+
return False
39+
40+
@classmethod
41+
def is_ignore_install_all_product(cls):
42+
return True
43+
44+
@classmethod
45+
def is_nondarwin_only_build_product(cls):
46+
return True
47+
48+
def should_build(self, host_target):
49+
return False
50+
51+
def should_install(self, host_target):
52+
return False
53+
54+
def should_test(self, host_target):
55+
return True
56+
57+
def configuration(self):
58+
return 'release' if self.is_release() else 'debug'
59+
60+
def test(self, host_target):
61+
swift_exec = os.path.join(
62+
self.install_toolchain_path(host_target),
63+
'bin',
64+
'swift'
65+
)
66+
package_path = os.path.join(self.source_dir, '..', 'swift-corelibs-foundation')
67+
package_path = os.path.abspath(package_path)
68+
cmd = [
69+
swift_exec,
70+
'test',
71+
'--toolchain', self.install_toolchain_path(host_target),
72+
'--configuration', self.configuration(),
73+
'--scratch-path', self.build_dir,
74+
'--package-path', package_path
75+
]
76+
if self.args.verbose_build:
77+
cmd.append('--verbose')
78+
shell.call(cmd, env={'SWIFTCI_USE_LOCAL_DEPS': '1'})
79+
80+
@classmethod
81+
def get_dependencies(cls):
82+
return [cmark.CMark,
83+
llvm.LLVM,
84+
libcxx.LibCXX,
85+
libicu.LibICU,
86+
swift.Swift,
87+
libdispatch.LibDispatch,
88+
foundation.Foundation,
89+
xctest.XCTest,
90+
llbuild.LLBuild,
91+
swiftpm.SwiftPM,
92+
swiftsyntax.SwiftSyntax]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# swift_build_support/products/foundationtests.py -----------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
15+
from . import cmark
16+
from . import foundation
17+
from . import libcxx
18+
from . import libdispatch
19+
from . import libicu
20+
from . import llbuild
21+
from . import llvm
22+
from . import product
23+
from . import swift
24+
from . import swiftpm
25+
from . import swiftsyntax
26+
from . import xctest
27+
from .. import shell
28+
from .. import targets
29+
30+
31+
class SwiftFoundationTests(product.Product):
32+
@classmethod
33+
def is_build_script_impl_product(cls):
34+
return False
35+
36+
@classmethod
37+
def is_before_build_script_impl_product(cls):
38+
return False
39+
40+
@classmethod
41+
def is_ignore_install_all_product(cls):
42+
return True
43+
44+
@classmethod
45+
def is_nondarwin_only_build_product(cls):
46+
return True
47+
48+
def should_build(self, host_target):
49+
return False
50+
51+
def should_install(self, host_target):
52+
return False
53+
54+
def should_test(self, host_target):
55+
return True
56+
57+
def configuration(self):
58+
return 'release' if self.is_release() else 'debug'
59+
60+
def test(self, host_target):
61+
swift_exec = os.path.join(
62+
self.install_toolchain_path(host_target),
63+
'bin',
64+
'swift'
65+
)
66+
package_path = os.path.join(self.source_dir, '..', 'swift-foundation')
67+
package_path = os.path.abspath(package_path)
68+
cmd = [
69+
swift_exec,
70+
'test',
71+
'--toolchain', self.install_toolchain_path(host_target),
72+
'--configuration', self.configuration(),
73+
'--scratch-path', self.build_dir,
74+
'--package-path', package_path
75+
]
76+
if self.args.verbose_build:
77+
cmd.append('--verbose')
78+
shell.call(cmd, env={'SWIFTCI_USE_LOCAL_DEPS': '1'})
79+
80+
@classmethod
81+
def get_dependencies(cls):
82+
return [cmark.CMark,
83+
llvm.LLVM,
84+
libcxx.LibCXX,
85+
libicu.LibICU,
86+
swift.Swift,
87+
libdispatch.LibDispatch,
88+
foundation.Foundation,
89+
xctest.XCTest,
90+
llbuild.LLBuild,
91+
swiftpm.SwiftPM,
92+
swiftsyntax.SwiftSyntax]

0 commit comments

Comments
 (0)