Skip to content

Commit c19939b

Browse files
committed
Invoke foundation tests via SwiftPM
1 parent 71c27a9 commit c19939b

File tree

6 files changed

+224
-17
lines changed

6 files changed

+224
-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,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
@@ -47,6 +49,8 @@
4749
__all__ = [
4850
'CMark',
4951
'Foundation',
52+
'FoundationTests',
53+
'SwiftFoundationTests',
5054
'LibCXX',
5155
'LibDispatch',
5256
'LibXML2',
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)