Skip to content

Commit ab7f7a4

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

File tree

6 files changed

+220
-17
lines changed

6 files changed

+220
-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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
from .. import targets
28+
29+
30+
class FoundationTests(product.Product):
31+
@classmethod
32+
def is_build_script_impl_product(cls):
33+
return False
34+
35+
@classmethod
36+
def is_before_build_script_impl_product(cls):
37+
return False
38+
39+
@classmethod
40+
def is_ignore_install_all_product(cls):
41+
return True
42+
43+
@classmethod
44+
def is_nondarwin_only_build_product(cls):
45+
return True
46+
47+
def should_build(self, host_target):
48+
return False
49+
50+
def should_install(self, host_target):
51+
return False
52+
53+
def should_test(self, host_target):
54+
return True
55+
56+
def configuration(self):
57+
return 'release' if self.is_release() else 'debug'
58+
59+
def test(self, host_target):
60+
swift_exec = os.path.join(
61+
self.install_toolchain_path(host_target),
62+
'bin',
63+
'swift'
64+
)
65+
package_path = os.path.join(self.source_dir, '..', 'swift-corelibs-foundation')
66+
package_path = os.path.abspath(package_path)
67+
cmd = [
68+
swift_exec,
69+
'test',
70+
'--toolchain', self.install_toolchain_path(host_target),
71+
'--configuration', self.configuration(),
72+
'--scratch-path', self.build_dir,
73+
'--package-path', package_path
74+
]
75+
if self.args.verbose_build:
76+
cmd.append('--verbose')
77+
shell.call(cmd, env={'SWIFTCI_USE_LOCAL_DEPS': '1'})
78+
79+
@classmethod
80+
def get_dependencies(cls):
81+
return [cmark.CMark,
82+
llvm.LLVM,
83+
libcxx.LibCXX,
84+
swift.Swift,
85+
libdispatch.LibDispatch,
86+
foundation.Foundation,
87+
xctest.XCTest,
88+
llbuild.LLBuild,
89+
swiftpm.SwiftPM,
90+
swiftsyntax.SwiftSyntax]
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
from .. import targets
28+
29+
30+
class SwiftFoundationTests(product.Product):
31+
@classmethod
32+
def is_build_script_impl_product(cls):
33+
return False
34+
35+
@classmethod
36+
def is_before_build_script_impl_product(cls):
37+
return False
38+
39+
@classmethod
40+
def is_ignore_install_all_product(cls):
41+
return True
42+
43+
@classmethod
44+
def is_nondarwin_only_build_product(cls):
45+
return True
46+
47+
def should_build(self, host_target):
48+
return False
49+
50+
def should_install(self, host_target):
51+
return False
52+
53+
def should_test(self, host_target):
54+
return True
55+
56+
def configuration(self):
57+
return 'release' if self.is_release() else 'debug'
58+
59+
def test(self, host_target):
60+
swift_exec = os.path.join(
61+
self.install_toolchain_path(host_target),
62+
'bin',
63+
'swift'
64+
)
65+
package_path = os.path.join(self.source_dir, '..', 'swift-foundation')
66+
package_path = os.path.abspath(package_path)
67+
cmd = [
68+
swift_exec,
69+
'test',
70+
'--toolchain', self.install_toolchain_path(host_target),
71+
'--configuration', self.configuration(),
72+
'--scratch-path', self.build_dir,
73+
'--package-path', package_path
74+
]
75+
if self.args.verbose_build:
76+
cmd.append('--verbose')
77+
shell.call(cmd, env={'SWIFTCI_USE_LOCAL_DEPS': '1'})
78+
79+
@classmethod
80+
def get_dependencies(cls):
81+
return [cmark.CMark,
82+
llvm.LLVM,
83+
libcxx.LibCXX,
84+
swift.Swift,
85+
libdispatch.LibDispatch,
86+
foundation.Foundation,
87+
xctest.XCTest,
88+
llbuild.LLBuild,
89+
swiftpm.SwiftPM,
90+
swiftsyntax.SwiftSyntax]

0 commit comments

Comments
 (0)