Skip to content

Commit 252e44f

Browse files
committed
Invoke foundation tests via SwiftPM
1 parent cc8af17 commit 252e44f

File tree

6 files changed

+218
-17
lines changed

6 files changed

+218
-17
lines changed

utils/build-windows-toolchain.bat

Lines changed: 1 addition & 1 deletion
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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,26 +1618,40 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
16181618
}
16191619

16201620
function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
1621-
$DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch
1622-
$SwiftSyntaxDir = Get-HostProjectCMakeModules Compilers
1623-
$FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation
1624-
$ShortArch = $Arch.LLVMName
1621+
if ($Test) {
1622+
# Foundation tests build via swiftpm rather than CMake
1623+
$OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath swift-foundation-tests
16251624

1626-
Isolate-EnvVars {
1627-
if ($Test) {
1628-
$XCTestBinaryCache = Get-TargetProjectBinaryCache $Arch XCTest
1629-
$TestingDefines = @{
1630-
ENABLE_TESTING = "YES";
1631-
XCTest_DIR = "$XCTestBinaryCache\cmake\modules";
1632-
}
1633-
$Targets = @("default", "test")
1634-
$env:Path = "$XCTestBinaryCache;$FoundationBinaryCache\bin;$DispatchBinaryCache;$(Get-TargetProjectBinaryCache $Arch Runtime)\bin;$env:Path"
1635-
$InstallPath = ""
1636-
} else {
1625+
Isolate-EnvVars {
1626+
$env:SWIFTCI_USE_LOCAL_DEPS=1
1627+
Build-SPMProject `
1628+
-Test `
1629+
-Src $SourceCache\swift-foundation `
1630+
-Bin $OutDir `
1631+
-Arch $HostArch
1632+
}
1633+
1634+
$OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath foundation-tests
1635+
1636+
Isolate-EnvVars {
1637+
$env:SWIFTCI_USE_LOCAL_DEPS=1
1638+
Build-SPMProject `
1639+
-Test `
1640+
-Src $SourceCache\swift-corelibs-foundation `
1641+
-Bin $OutDir `
1642+
-Arch $HostArch
1643+
}
1644+
} else {
1645+
$DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch
1646+
$SwiftSyntaxDir = Get-HostProjectCMakeModules Compilers
1647+
$FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation
1648+
$ShortArch = $Arch.LLVMName
1649+
1650+
Isolate-EnvVars {
16371651
$TestingDefines = @{ ENABLE_TESTING = "NO" }
16381652
$Targets = @("default", "install")
16391653
$InstallPath = "$($Arch.SDKInstallRoot)\usr"
1640-
}
1654+
16411655

16421656
$env:CTEST_OUTPUT_ON_FAILURE = 1
16431657
Build-CMakeProject `
@@ -1670,6 +1684,7 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
16701684
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
16711685
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections"
16721686
} + $TestingDefines)
1687+
}
16731688
}
16741689
}
16751690

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
@@ -672,6 +672,10 @@ def compute_product_pipelines(self):
672672

673673
builder.add_product(products.SwiftPM,
674674
is_enabled=self.args.build_swiftpm)
675+
builder.add_product(products.SwiftFoundationTests,
676+
is_enabled=self.args.build_foundation)
677+
builder.add_product(products.FoundationTests,
678+
is_enabled=self.args.build_foundation)
675679
builder.add_product(products.SwiftSyntax,
676680
is_enabled=self.args.build_swiftsyntax)
677681
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,7 @@
1515
from .curl import LibCurl
1616
from .earlyswiftdriver import EarlySwiftDriver
1717
from .foundation import Foundation
18+
from .foundationtests import FoundationTests
1819
from .indexstoredb import IndexStoreDB
1920
from .libcxx import LibCXX
2021
from .libdispatch import LibDispatch
@@ -33,6 +34,7 @@
3334
from .swiftdoccrender import SwiftDocCRender
3435
from .swiftdriver import SwiftDriver
3536
from .swiftformat import SwiftFormat
37+
from .swiftfoundationtests import SwiftFoundationTests
3638
from .swiftinspect import SwiftInspect
3739
from .swiftpm import SwiftPM
3840
from .swiftsyntax import SwiftSyntax
@@ -47,6 +49,8 @@
4749
__all__ = [
4850
'CMark',
4951
'Foundation',
52+
'FoundationTests',
53+
'SwiftFoundationTests',
5054
'LibCXX',
5155
'LibDispatch',
5256
'LibXML2',
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 llbuild
20+
from . import llvm
21+
from . import product
22+
from . import swift
23+
from . import swiftpm
24+
from . import swiftsyntax
25+
from . import xctest
26+
from .. import shell
27+
28+
29+
class FoundationTests(product.Product):
30+
@classmethod
31+
def is_build_script_impl_product(cls):
32+
return False
33+
34+
@classmethod
35+
def is_before_build_script_impl_product(cls):
36+
return False
37+
38+
@classmethod
39+
def is_ignore_install_all_product(cls):
40+
return True
41+
42+
@classmethod
43+
def is_nondarwin_only_build_product(cls):
44+
return True
45+
46+
def should_build(self, host_target):
47+
return False
48+
49+
def should_install(self, host_target):
50+
return False
51+
52+
def should_test(self, host_target):
53+
return True
54+
55+
def configuration(self):
56+
return 'release' if self.is_release() else 'debug'
57+
58+
def test(self, host_target):
59+
swift_exec = os.path.join(
60+
self.install_toolchain_path(host_target),
61+
'bin',
62+
'swift'
63+
)
64+
package_path = os.path.join(self.source_dir, '..', 'swift-corelibs-foundation')
65+
package_path = os.path.abspath(package_path)
66+
cmd = [
67+
swift_exec,
68+
'test',
69+
'--toolchain', self.install_toolchain_path(host_target),
70+
'--configuration', self.configuration(),
71+
'--scratch-path', self.build_dir,
72+
'--package-path', package_path
73+
]
74+
if self.args.verbose_build:
75+
cmd.append('--verbose')
76+
shell.call(cmd, env={'SWIFTCI_USE_LOCAL_DEPS': '1'})
77+
78+
@classmethod
79+
def get_dependencies(cls):
80+
return [cmark.CMark,
81+
llvm.LLVM,
82+
libcxx.LibCXX,
83+
swift.Swift,
84+
libdispatch.LibDispatch,
85+
foundation.Foundation,
86+
xctest.XCTest,
87+
llbuild.LLBuild,
88+
swiftpm.SwiftPM,
89+
swiftsyntax.SwiftSyntax]
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 llbuild
20+
from . import llvm
21+
from . import product
22+
from . import swift
23+
from . import swiftpm
24+
from . import swiftsyntax
25+
from . import xctest
26+
from .. import shell
27+
28+
29+
class SwiftFoundationTests(product.Product):
30+
@classmethod
31+
def is_build_script_impl_product(cls):
32+
return False
33+
34+
@classmethod
35+
def is_before_build_script_impl_product(cls):
36+
return False
37+
38+
@classmethod
39+
def is_ignore_install_all_product(cls):
40+
return True
41+
42+
@classmethod
43+
def is_nondarwin_only_build_product(cls):
44+
return True
45+
46+
def should_build(self, host_target):
47+
return False
48+
49+
def should_install(self, host_target):
50+
return False
51+
52+
def should_test(self, host_target):
53+
return True
54+
55+
def configuration(self):
56+
return 'release' if self.is_release() else 'debug'
57+
58+
def test(self, host_target):
59+
swift_exec = os.path.join(
60+
self.install_toolchain_path(host_target),
61+
'bin',
62+
'swift'
63+
)
64+
package_path = os.path.join(self.source_dir, '..', 'swift-foundation')
65+
package_path = os.path.abspath(package_path)
66+
cmd = [
67+
swift_exec,
68+
'test',
69+
'--toolchain', self.install_toolchain_path(host_target),
70+
'--configuration', self.configuration(),
71+
'--scratch-path', self.build_dir,
72+
'--package-path', package_path
73+
]
74+
if self.args.verbose_build:
75+
cmd.append('--verbose')
76+
shell.call(cmd, env={'SWIFTCI_USE_LOCAL_DEPS': '1'})
77+
78+
@classmethod
79+
def get_dependencies(cls):
80+
return [cmark.CMark,
81+
llvm.LLVM,
82+
libcxx.LibCXX,
83+
swift.Swift,
84+
libdispatch.LibDispatch,
85+
foundation.Foundation,
86+
xctest.XCTest,
87+
llbuild.LLBuild,
88+
swiftpm.SwiftPM,
89+
swiftsyntax.SwiftSyntax]

0 commit comments

Comments
 (0)