Skip to content

Invoke foundation tests via SwiftPM #74594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1618,28 +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 `
-Src $SourceCache\swift-corelibs-foundation `
-Bin $FoundationBinaryCache `
Expand Down Expand Up @@ -1670,6 +1683,7 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections"
} + $TestingDefines)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -47,6 +49,8 @@
__all__ = [
'CMark',
'Foundation',
'FoundationTests',
'SwiftFoundationTests',
'LibCXX',
'LibDispatch',
'LibXML2',
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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]