From 0a941ba332b0b6758f7f430a07867b809a64b70b Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Wed, 24 Jul 2024 09:23:41 -0700 Subject: [PATCH 1/2] Invoke foundation tests via SwiftPM --- utils/build.ps1 | 48 ++++++--- .../build_script_invocation.py | 4 + .../swift_build_support/products/__init__.py | 4 + .../products/foundationtests.py | 97 +++++++++++++++++++ .../products/swiftfoundationtests.py | 89 +++++++++++++++++ 5 files changed, 226 insertions(+), 16 deletions(-) create mode 100644 utils/swift_build_support/swift_build_support/products/foundationtests.py create mode 100644 utils/swift_build_support/swift_build_support/products/swiftfoundationtests.py diff --git a/utils/build.ps1 b/utils/build.ps1 index 753b4759a9f96..c92d6702f5532 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -1618,26 +1618,41 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) { } function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) { - $DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch - $SwiftSyntaxDir = Get-HostProjectCMakeModules Compilers - $FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation - $ShortArch = $Arch.LLVMName + if ($Test) { + # Foundation tests build via swiftpm rather than CMake + $OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath swift-foundation-tests - Isolate-EnvVars { - if ($Test) { - $XCTestBinaryCache = Get-TargetProjectBinaryCache $Arch XCTest - $TestingDefines = @{ - ENABLE_TESTING = "YES"; - XCTest_DIR = "$XCTestBinaryCache\cmake\modules"; - } - $Targets = @("default", "test") - $env:Path = "$XCTestBinaryCache;$FoundationBinaryCache\bin;$DispatchBinaryCache;$(Get-TargetProjectBinaryCache $Arch Runtime)\bin;$env:Path" - $InstallPath = "" - } else { + Isolate-EnvVars { + $env:SWIFTCI_USE_LOCAL_DEPS=1 + Build-SPMProject ` + -Test ` + -Src $SourceCache\swift-foundation ` + -Bin $OutDir ` + -Arch $HostArch + } + + $OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath foundation-tests + + Isolate-EnvVars { + $env:SWIFTCI_USE_LOCAL_DEPS=1 + $env:DISPATCH_INCLUDE_PATH="$($Arch.SDKInstallRoot)/usr/lib/swift" + Build-SPMProject ` + -Test ` + -Src $SourceCache\swift-corelibs-foundation ` + -Bin $OutDir ` + -Arch $HostArch + } + } else { + $DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch + $SwiftSyntaxDir = Get-HostProjectCMakeModules Compilers + $FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation + $ShortArch = $Arch.LLVMName + + Isolate-EnvVars { $TestingDefines = @{ ENABLE_TESTING = "NO" } $Targets = @("default", "install") $InstallPath = "$($Arch.SDKInstallRoot)\usr" - } + $env:CTEST_OUTPUT_ON_FAILURE = 1 Build-CMakeProject ` @@ -1670,6 +1685,7 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) { _SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu"; _SwiftCollections_SourceDIR = "$SourceCache\swift-collections" } + $TestingDefines) + } } } diff --git a/utils/swift_build_support/swift_build_support/build_script_invocation.py b/utils/swift_build_support/swift_build_support/build_script_invocation.py index 0666ba961a904..3f4aa70338d67 100644 --- a/utils/swift_build_support/swift_build_support/build_script_invocation.py +++ b/utils/swift_build_support/swift_build_support/build_script_invocation.py @@ -672,6 +672,10 @@ def compute_product_pipelines(self): builder.add_product(products.SwiftPM, is_enabled=self.args.build_swiftpm) + builder.add_product(products.SwiftFoundationTests, + is_enabled=self.args.build_foundation) + builder.add_product(products.FoundationTests, + is_enabled=self.args.build_foundation) builder.add_product(products.SwiftSyntax, is_enabled=self.args.build_swiftsyntax) builder.add_product(products.SwiftFormat, diff --git a/utils/swift_build_support/swift_build_support/products/__init__.py b/utils/swift_build_support/swift_build_support/products/__init__.py index 1ef4efac89c5a..a029b952e0faa 100644 --- a/utils/swift_build_support/swift_build_support/products/__init__.py +++ b/utils/swift_build_support/swift_build_support/products/__init__.py @@ -15,6 +15,7 @@ from .curl import LibCurl from .earlyswiftdriver import EarlySwiftDriver from .foundation import Foundation +from .foundationtests import FoundationTests from .indexstoredb import IndexStoreDB from .libcxx import LibCXX from .libdispatch import LibDispatch @@ -33,6 +34,7 @@ from .swiftdoccrender import SwiftDocCRender from .swiftdriver import SwiftDriver from .swiftformat import SwiftFormat +from .swiftfoundationtests import SwiftFoundationTests from .swiftinspect import SwiftInspect from .swiftpm import SwiftPM from .swiftsyntax import SwiftSyntax @@ -47,6 +49,8 @@ __all__ = [ 'CMark', 'Foundation', + 'FoundationTests', + 'SwiftFoundationTests', 'LibCXX', 'LibDispatch', 'LibXML2', diff --git a/utils/swift_build_support/swift_build_support/products/foundationtests.py b/utils/swift_build_support/swift_build_support/products/foundationtests.py new file mode 100644 index 0000000000000..1ef36b8527da7 --- /dev/null +++ b/utils/swift_build_support/swift_build_support/products/foundationtests.py @@ -0,0 +1,97 @@ +# swift_build_support/products/foundationtests.py -----------------------*- python -*- +# +# This source file is part of the Swift.org open source project +# +# Copyright (c) 2024 Apple Inc. and the Swift project authors +# Licensed under Apache License v2.0 with Runtime Library Exception +# +# See https://swift.org/LICENSE.txt for license information +# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +# +# ---------------------------------------------------------------------------- + +import os + +from . import cmark +from . import foundation +from . import libcxx +from . import libdispatch +from . import llbuild +from . import llvm +from . import product +from . import swift +from . import swiftpm +from . import swiftsyntax +from . import xctest +from .. import shell + + +class FoundationTests(product.Product): + @classmethod + def is_build_script_impl_product(cls): + return False + + @classmethod + def is_before_build_script_impl_product(cls): + return False + + @classmethod + def is_ignore_install_all_product(cls): + return True + + @classmethod + def is_nondarwin_only_build_product(cls): + return True + + def should_build(self, host_target): + return False + + def should_install(self, host_target): + return False + + def should_test(self, host_target): + return True + + def configuration(self): + return 'release' if self.is_release() else 'debug' + + def test(self, host_target): + swift_exec = os.path.join( + self.install_toolchain_path(host_target), + 'bin', + 'swift' + ) + package_path = os.path.join(self.source_dir, '..', 'swift-corelibs-foundation') + package_path = os.path.abspath(package_path) + include_path = os.path.join( + self.install_toolchain_path(host_target), + 'lib', + 'swift' + ) + cmd = [ + swift_exec, + 'test', + '--toolchain', self.install_toolchain_path(host_target), + '--configuration', self.configuration(), + '--scratch-path', self.build_dir, + '--package-path', package_path + ] + if self.args.verbose_build: + cmd.append('--verbose') + shell.call(cmd, env={ + 'SWIFTCI_USE_LOCAL_DEPS': '1', + 'DISPATCH_INCLUDE_PATH': include_path + }) + + @classmethod + def get_dependencies(cls): + return [cmark.CMark, + llvm.LLVM, + libcxx.LibCXX, + swift.Swift, + libdispatch.LibDispatch, + foundation.Foundation, + xctest.XCTest, + llbuild.LLBuild, + swiftpm.SwiftPM, + swiftsyntax.SwiftSyntax] diff --git a/utils/swift_build_support/swift_build_support/products/swiftfoundationtests.py b/utils/swift_build_support/swift_build_support/products/swiftfoundationtests.py new file mode 100644 index 0000000000000..c7f15f9c5f53b --- /dev/null +++ b/utils/swift_build_support/swift_build_support/products/swiftfoundationtests.py @@ -0,0 +1,89 @@ +# swift_build_support/products/foundationtests.py -----------------------*- python -*- +# +# This source file is part of the Swift.org open source project +# +# Copyright (c) 2024 Apple Inc. and the Swift project authors +# Licensed under Apache License v2.0 with Runtime Library Exception +# +# See https://swift.org/LICENSE.txt for license information +# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +# +# ---------------------------------------------------------------------------- + +import os + +from . import cmark +from . import foundation +from . import libcxx +from . import libdispatch +from . import llbuild +from . import llvm +from . import product +from . import swift +from . import swiftpm +from . import swiftsyntax +from . import xctest +from .. import shell + + +class SwiftFoundationTests(product.Product): + @classmethod + def is_build_script_impl_product(cls): + return False + + @classmethod + def is_before_build_script_impl_product(cls): + return False + + @classmethod + def is_ignore_install_all_product(cls): + return True + + @classmethod + def is_nondarwin_only_build_product(cls): + return True + + def should_build(self, host_target): + return False + + def should_install(self, host_target): + return False + + def should_test(self, host_target): + return True + + def configuration(self): + return 'release' if self.is_release() else 'debug' + + def test(self, host_target): + swift_exec = os.path.join( + self.install_toolchain_path(host_target), + 'bin', + 'swift' + ) + package_path = os.path.join(self.source_dir, '..', 'swift-foundation') + package_path = os.path.abspath(package_path) + cmd = [ + swift_exec, + 'test', + '--toolchain', self.install_toolchain_path(host_target), + '--configuration', self.configuration(), + '--scratch-path', self.build_dir, + '--package-path', package_path + ] + if self.args.verbose_build: + cmd.append('--verbose') + shell.call(cmd, env={'SWIFTCI_USE_LOCAL_DEPS': '1'}) + + @classmethod + def get_dependencies(cls): + return [cmark.CMark, + llvm.LLVM, + libcxx.LibCXX, + swift.Swift, + libdispatch.LibDispatch, + foundation.Foundation, + xctest.XCTest, + llbuild.LLBuild, + swiftpm.SwiftPM, + swiftsyntax.SwiftSyntax] From 2c6195af00dc2f38ec1a8095937ccfcd7da54b8e Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Wed, 24 Jul 2024 15:18:29 -0700 Subject: [PATCH 2/2] Remove CTEST_OUTPUT_ON_FAILURE from Foundation build --- utils/build.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index c92d6702f5532..fea017bd3ed7a 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -1653,8 +1653,6 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) { $Targets = @("default", "install") $InstallPath = "$($Arch.SDKInstallRoot)\usr" - - $env:CTEST_OUTPUT_ON_FAILURE = 1 Build-CMakeProject ` -Src $SourceCache\swift-corelibs-foundation ` -Bin $FoundationBinaryCache `