Skip to content

Commit aabc951

Browse files
authored
Add and apply a test trait for tests which require Xcode 16 tools (swiftlang#80)
Also, ensure that we unset environment overrides to the Swift compiler and frontend when initializing a testing core
1 parent 8d38668 commit aabc951

35 files changed

+74
-49
lines changed

Sources/SWBCore/Settings/Settings.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ fileprivate struct PreOverridesSettings {
141141

142142
table.push(BuiltinMacros.DIAGNOSE_MISSING_TARGET_DEPENDENCIES, literal: .yes)
143143

144+
// This is a hack to allow more tests to run in Swift CI when using older Xcode versions.
145+
if core.xcodeProductBuildVersion < (try! ProductBuildVersion("16A242d")) {
146+
table.push(BuiltinMacros.LM_SKIP_METADATA_EXTRACTION, BuiltinMacros.namespace.parseString("YES"))
147+
}
148+
144149
// Add the "calculated" settings.
145150
addCalculatedUniversalDefaults(&table)
146151

Sources/SWBTestSupport/CoreTestSupport.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ extension Core {
5151
// This is a "well known" launch parameter set in Xcode's schemes.
5252
let developerPath = getEnvironmentVariable("XCODE_DEVELOPER_DIR_PATH").map(Path.init)
5353

54+
// Unset variables which may interfere with testing in Swift CI
55+
for variable in ["SWIFT_EXEC", "SWIFT_DRIVER_SWIFT_FRONTEND_EXEC", "SWIFT_DRIVER_SWIFT_EXEC"] {
56+
try POSIX.unsetenv(variable)
57+
}
58+
5459
// When this code is being loaded directly via unit tests *and* we detect the products directory we are running in is for Xcode, then we should run using inferior search paths.
5560
let inferiorProductsPath: Path? = self.inferiorProductsPath()
5661

Sources/SWBTestSupport/SkippedTestSupport.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ extension Trait where Self == Testing.ConditionTrait {
214214
getEnvironmentVariable(key) == value
215215
}
216216
}
217+
218+
package static func skipIfEnvironmentVariableSet(key: String) -> Self {
219+
disabled("environment sets '\(key)'") {
220+
getEnvironmentVariable(key) != nil
221+
}
222+
}
217223
}
218224

219225
// MARK: Condition traits for Xcode and SDK version requirements
@@ -243,6 +249,15 @@ extension Trait where Self == Testing.ConditionTrait {
243249
requireXcodeBuildVersions(in: try ProductBuildVersion(version)..., sourceLocation: sourceLocation)
244250
}
245251

252+
package static func requireXcode16(sourceLocation: SourceLocation = #_sourceLocation) -> Self {
253+
enabled("Xcode version is not suitable", sourceLocation: sourceLocation, {
254+
guard let installedVersion = try? await InstalledXcode.currentlySelected().productBuildVersion() else {
255+
return true
256+
}
257+
return installedVersion > (try ProductBuildVersion("16A242d"))
258+
})
259+
}
260+
246261
/// Constructs a condition trait that causes a test to be disabled if not running against at least the given version of Xcode.
247262
package static func requireMinimumXcodeBuildVersion(_ version: ProductBuildVersion, sourceLocation: SourceLocation = #_sourceLocation) -> Self {
248263
requireXcodeBuildVersions(in: version..., sourceLocation: sourceLocation)

Tests/SWBBuildSystemTests/AppIntentsNLTrainingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SWBTestSupport
1818
import SWBTaskExecution
1919
import SWBUtil
2020

21-
@Suite
21+
@Suite(.requireXcode16())
2222
fileprivate struct AppIntentsNLTrainingTests: CoreBasedTests {
2323
let appShortcutsStringsFileName = "AppShortcuts.strings"
2424
let appIntentsSourceFileName = "source.swift"

Tests/SWBBuildSystemTests/AppShortcutsStringsValidationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SWBTestSupport
1818
import SWBTaskExecution
1919
import SWBUtil
2020

21-
@Suite
21+
@Suite(.requireXcode16())
2222
fileprivate struct AppShortcutsStringsValidationTests: CoreBasedTests {
2323
let appShortcutsStringsFileName = "AppShortcuts.strings"
2424

Tests/SWBBuildSystemTests/BuildCommandTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Testing
2020
@Suite
2121
fileprivate struct BuildCommandTests: CoreBasedTests {
2222
/// Check compilation of a single file in C, ObjC and Swift, including the `uniquingSuffix` behaviour.
23-
@Test(.requireSDKs(.macOS))
23+
@Test(.requireSDKs(.macOS), .requireXcode16())
2424
func singleFileCompile() async throws {
2525
try await withTemporaryDirectory { tmpDirPath async throws -> Void in
2626
let testWorkspace = try await TestWorkspace(

Tests/SWBBuildSystemTests/BuildOperationDescriptionTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fileprivate struct BuildOperationDescriptionTests: CoreBasedTests {
140140
}
141141

142142
/// Generate a `BuildDescription` from our test workspace, build it, and check results. Then try doing it again to make sure we can use the results loaded from the on-disk cache.
143-
@Test(.requireSDKs(.macOS))
143+
@Test(.requireSDKs(.macOS), .requireXcode16())
144144
func onDiskBuildDescriptionCache() async throws {
145145
try await withTemporaryDirectory { tmpDirPath in
146146
let testWorkspace = try await getTestWorkspace(in: tmpDirPath)
@@ -358,7 +358,7 @@ fileprivate struct BuildOperationDescriptionTests: CoreBasedTests {
358358
}
359359

360360
/// Generate a `BuildDescription` from our test workspace, build it, and check results. Then try doing it again to make sure we can use the results loaded from the on-disk cache.
361-
@Test(.requireSDKs(.macOS))
361+
@Test(.requireSDKs(.macOS), .requireXcode16())
362362
func inMemoryBuildDescriptionCache() async throws {
363363
try await withTemporaryDirectory { tmpDirPath in
364364
let testWorkspace = try await getTestWorkspace(in: tmpDirPath)
@@ -499,7 +499,7 @@ fileprivate struct BuildOperationDescriptionTests: CoreBasedTests {
499499
}
500500

501501
/// Generate a `BuildDescription` from our test workspace, build it, and check results. Then try doing it again to make sure we can use the cached build system object
502-
@Test(.requireSDKs(.macOS))
502+
@Test(.requireSDKs(.macOS), .requireXcode16())
503503
func buildDescriptionUseInBuildSystemCaching() async throws {
504504
try await withTemporaryDirectory { tmpDirPath in
505505
let testWorkspace = try await getTestWorkspace(in: tmpDirPath)

Tests/SWBBuildSystemTests/BuildOperationTests.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import SWBTaskExecution
2828
@_spi(Testing) import SWBUtil
2929
import SWBTestSupport
3030

31-
@Suite
31+
@Suite(.requireXcode16())
3232
fileprivate struct BuildOperationTests: CoreBasedTests {
3333
@Test(.requireSDKs(.host), .requireThreadSafeWorkingDirectory)
3434
func commandLineTool() async throws {
@@ -4612,57 +4612,57 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script
46124612
}
46134613
}
46144614

4615-
@Test(.requireSDKs(.macOS))
4615+
@Test(.requireSDKs(.macOS), .requireXcode16())
46164616
func frameworkInstallAPITBDSigning() async throws {
46174617
try await checkTBDSigning(useStubify: false, productType: .framework)
46184618
}
4619-
@Test(.requireSDKs(.macOS))
4619+
@Test(.requireSDKs(.macOS), .requireXcode16())
46204620
func frameworkInstallAPITBDSigningWithBuildVariants() async throws {
46214621
// FIXME: <rdar://problem/42261905> We should do this at the task construction tests layer, once we have good automatic cycle detection there.
46224622
try await checkTBDSigning(useStubify: false, productType: .framework, buildVariants: ["normal", "profile"])
46234623
}
4624-
@Test(.requireSDKs(.macOS))
4624+
@Test(.requireSDKs(.macOS), .requireXcode16())
46254625
func frameworkStubifyTBDSigning() async throws {
46264626
try await checkTBDSigning(useStubify: true, productType: .framework)
46274627
}
4628-
@Test(.requireSDKs(.macOS))
4628+
@Test(.requireSDKs(.macOS), .requireXcode16())
46294629
func staticFrameworkInstallAPITBDSigning() async throws {
46304630
try await checkTBDSigning(useStubify: false, productType: .staticFramework)
46314631
}
4632-
@Test(.requireSDKs(.macOS))
4632+
@Test(.requireSDKs(.macOS), .requireXcode16())
46334633
func staticFrameworkInstallAPITBDSigningWithBuildVariants() async throws {
46344634
try await checkTBDSigning(useStubify: false, productType: .staticFramework, buildVariants: ["normal", "profile"])
46354635
}
4636-
@Test(.requireSDKs(.macOS))
4636+
@Test(.requireSDKs(.macOS), .requireXcode16())
46374637
func staticFrameworkStubifyTBDSigning() async throws {
46384638
try await checkTBDSigning(useStubify: true, productType: .staticFramework)
46394639
}
4640-
@Test(.requireSDKs(.macOS))
4640+
@Test(.requireSDKs(.macOS), .requireXcode16())
46414641
func dylibInstallAPITBDSigning() async throws {
46424642
try await checkTBDSigning(useStubify: false, productType: .dynamicLibrary)
46434643
}
4644-
@Test(.requireSDKs(.macOS))
4644+
@Test(.requireSDKs(.macOS), .requireXcode16())
46454645
func dylibInstallAPITBDSigningWithBuildVariants() async throws {
46464646
try await checkTBDSigning(useStubify: false, productType: .dynamicLibrary, buildVariants: ["normal", "profile"])
46474647
}
4648-
@Test(.requireSDKs(.macOS))
4648+
@Test(.requireSDKs(.macOS), .requireXcode16())
46494649
func dylibStubifyTBDSigning() async throws {
46504650
try await checkTBDSigning(useStubify: true, productType: .dynamicLibrary)
46514651
}
4652-
@Test(.requireSDKs(.macOS))
4652+
@Test(.requireSDKs(.macOS), .requireXcode16())
46534653
func staticlibInstallAPITBDSigning() async throws {
46544654
try await checkTBDSigning(useStubify: false, productType: .staticLibrary)
46554655
}
4656-
@Test(.requireSDKs(.macOS))
4656+
@Test(.requireSDKs(.macOS), .requireXcode16())
46574657
func staticlibInstallAPITBDSigningWithBuildVariants() async throws {
46584658
try await checkTBDSigning(useStubify: false, productType: .staticLibrary, buildVariants: ["normal", "profile"])
46594659
}
4660-
@Test(.requireSDKs(.macOS))
4660+
@Test(.requireSDKs(.macOS), .requireXcode16())
46614661
func staticlibStubifyTBDSigning() async throws {
46624662
try await checkTBDSigning(useStubify: true, productType: .staticLibrary)
46634663
}
46644664

4665-
@Test(.requireSDKs(.macOS))
4665+
@Test(.requireSDKs(.macOS), .requireXcode16())
46664666
func incrementalFwkTAPI() async throws {
46674667
try await withTemporaryDirectory { tmpDirPath async throws -> Void in
46684668
let target = TestStandardTarget(

Tests/SWBBuildSystemTests/ClangExplicitModulesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SWBTestSupport
2020
import SWBUtil
2121
import SWBProtocol
2222

23-
@Suite(.requireDependencyScanner)
23+
@Suite(.requireDependencyScanner, .requireXcode16())
2424
fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
2525
@Test(.requireSDKs(.macOS))
2626
func explicitModulesBasic() async throws {

Tests/SWBBuildSystemTests/GenericTaskCachingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SWBBuildSystem
1818
import SWBCore
1919
import SWBTestSupport
2020

21-
@Suite(.disabled(if: getEnvironmentVariable("CI")?.isEmpty == false, "tests run too slowly in CI"))
21+
@Suite(.disabled(if: getEnvironmentVariable("CI")?.isEmpty == false, "tests run too slowly in CI"), .requireXcode16())
2222
fileprivate struct GenericTaskCachingTests: CoreBasedTests {
2323
@Test(.requireSDKs(.macOS), .requireHostOS(.macOS))
2424
func realityToolCachingBasics() async throws {

0 commit comments

Comments
 (0)