Skip to content

Commit 2fc9504

Browse files
committed
Invoke foundation tests via SwiftPM
1 parent 0512428 commit 2fc9504

File tree

5 files changed

+274
-68
lines changed

5 files changed

+274
-68
lines changed

utils/build.ps1

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,79 +1630,93 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
16301630
}
16311631

16321632
function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
1633-
$DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch
1634-
$SwiftSyntaxDir = Get-HostProjectCMakeModules Compilers
1635-
$FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation
1636-
$ShortArch = $Arch.LLVMName
1633+
if ($Test) {
1634+
# Foundation tests build via swiftpm rather than CMake
1635+
$OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath swift-foundation-tests
16371636

1638-
Isolate-EnvVars {
1639-
if ($Test) {
1640-
$XCTestBinaryCache = Get-TargetProjectBinaryCache $Arch XCTest
1641-
$TestingDefines = @{
1642-
ENABLE_TESTING = "YES";
1643-
XCTest_DIR = "$XCTestBinaryCache\cmake\modules";
1644-
}
1645-
$Targets = @("default", "test")
1646-
$env:Path = "$XCTestBinaryCache;$FoundationBinaryCache\bin;$DispatchBinaryCache;$(Get-TargetProjectBinaryCache $Arch Runtime)\bin;$env:Path"
1647-
$InstallPath = ""
1648-
} else {
1637+
Isolate-EnvVars {
1638+
$env:SWIFTCI_USE_LOCAL_DEPS=1
1639+
Build-SPMProject `
1640+
-Test `
1641+
-Src $SourceCache\swift-foundation `
1642+
-Bin $OutDir `
1643+
-Arch $HostArch
1644+
}
1645+
1646+
$OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath foundation-tests
1647+
1648+
Isolate-EnvVars {
1649+
$env:SWIFTCI_USE_LOCAL_DEPS=1
1650+
Build-SPMProject `
1651+
-Test `
1652+
-Src $SourceCache\swift-corelibs-foundation `
1653+
-Bin $OutDir `
1654+
-Arch $HostArch
1655+
}
1656+
} else {
1657+
$DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch
1658+
$SwiftSyntaxDir = Get-HostProjectCMakeModules Compilers
1659+
$FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation
1660+
$ShortArch = $Arch.LLVMName
1661+
1662+
Isolate-EnvVars {
16491663
$TestingDefines = @{ ENABLE_TESTING = "NO" }
16501664
$Targets = @("default", "install")
16511665
$InstallPath = "$($Arch.SDKInstallRoot)\usr"
1652-
}
16531666

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

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 4 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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',
Lines changed: 92 additions & 0 deletions
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]
Lines changed: 92 additions & 0 deletions
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)