From 531a3fcc1f7d8b92a1f83ddaeb2d336c606c6304 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Mon, 11 Aug 2025 14:43:08 -0700 Subject: [PATCH 1/3] [TEST-ONLY] Try renable compilation caching tests Try again to re-enable caching tests which was marked flaky due to unstable tests on Xcode Cloud. Re-enable compilation caching tests except on Xcode Cloud. --- Sources/SWBTestSupport/SkippedTestSupport.swift | 4 ++++ Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift | 3 +-- Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift | 2 +- Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/SWBTestSupport/SkippedTestSupport.swift b/Sources/SWBTestSupport/SkippedTestSupport.swift index 10decc7a..502fbc4b 100644 --- a/Sources/SWBTestSupport/SkippedTestSupport.swift +++ b/Sources/SWBTestSupport/SkippedTestSupport.swift @@ -175,6 +175,10 @@ extension Trait where Self == Testing.ConditionTrait { return .skipIfEnvironmentVariableSet(key: "GITHUB_ACTIONS") } + package static func skipInXcodeCloud(_ comment: Comment? = nil) -> Self { + return .skipIfEnvironmentVariableSet(key: "CI_XCODE_CLOUD") + } + package static func requireClangFeatures(_ requiredFeatures: DiscoveredClangToolSpecInfo.FeatureFlag...) -> Self { enabled("Clang compiler does not support features: \(requiredFeatures)") { let features = try await ConditionTraitContext.shared.clangFeatures diff --git a/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift b/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift index b9066b22..83b0330e 100644 --- a/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift +++ b/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift @@ -19,8 +19,7 @@ import SWBTestSupport import SWBUtil @Suite(.skipHostOS(.windows, "Windows platform has no CAS support yet"), - .requireDependencyScannerPlusCaching, - .flaky("A handful of Swift Build CAS tests fail when running the entire test suite"), .bug("rdar://146781403")) + .requireDependencyScannerPlusCaching, .skipInXcodeCloud("flaky tests")) fileprivate struct ClangCompilationCachingTests: CoreBasedTests { let canUseCASPlugin: Bool let canUseCASPruning: Bool diff --git a/Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift b/Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift index a05d0662..3a80fbc1 100644 --- a/Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift +++ b/Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift @@ -192,7 +192,7 @@ fileprivate struct ClangModuleVerifierTests: CoreBasedTests { } @Test(.requireSDKs(.macOS), .requireClangFeatures(.wSystemHeadersInModule), .requireDependencyScannerPlusCaching, - .flaky("A handful of Swift Build CAS tests fail when running the entire test suite"), .bug("rdar://146781403")) + .skipInXcodeCloud("flaky tests")) func cachedBuild() async throws { try await withTemporaryDirectory { (tmpDirPath: Path) in let archs = ["arm64", "x86_64"] diff --git a/Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift b/Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift index 3836da8e..1c0aa6b2 100644 --- a/Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift +++ b/Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift @@ -20,7 +20,7 @@ import SWBTaskExecution import SWBProtocol @Suite(.requireSwiftFeatures(.compilationCaching), - .flaky("A handful of Swift Build CAS tests fail when running the entire test suite"), .bug("rdar://146781403")) + .skipInXcodeCloud("flaky tests")) fileprivate struct SwiftCompilationCachingTests: CoreBasedTests { @Test(.requireSDKs(.iOS)) func swiftCachingSimple() async throws { From 1cde17392ea0863e3fb53471d6ff11f18a72cfc3 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Mon, 11 Aug 2025 15:29:59 -0700 Subject: [PATCH 2/3] [TEST-ONLY] Update compilation caching tests for latest compilers Update compilation caching tests to work with latest compiler. This involves relaxing some tests to check for both old and new command-line and also encoding less compiler implementation details in the build system tests. --- .../ClangCompilationCachingTests.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift b/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift index 83b0330e..c00c85e5 100644 --- a/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift +++ b/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift @@ -1579,7 +1579,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests { func checkModuleCommandLine(task: Task, results: BuildOperationTester.BuildResults, name: String) { // The final command-line is only known to the dynamic task, but it's printed to output so we can check that. results.checkTaskOutput(task) { output in - XCTAssertMatch(output.stringValue, .contains(#"\#(name)\=/\^mod"#)) + XCTAssertMatch(output.stringValue, .or(.contains(#"\#(name)\=/\^mod"#), .contains(#"\#(name) /\^mod"#))) checkCommandLineCommon(output: output) } } @@ -1842,6 +1842,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests { "CLANG_ENABLE_COMPILE_CACHE": enableCaching ? "YES" : "NO", "CLANG_ENABLE_MODULES": "NO", "COMPILATION_CACHE_CAS_PATH": casPath.str, + "DSTROOT": tmpDirPath.join("dstroot").str, ] if usePlugin { buildSettings["COMPILATION_CACHE_ENABLE_PLUGIN"] = "YES" @@ -1966,7 +1967,11 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests { // Ignore output for plugin CAS since it may not yet support validation. try await checkBuild("validated successfully\n") // Create an error and trigger revalidation by messing with the validation data. - try tester.fs.move(casPath.join("builtin/v1.1/v8.data"), to: casPath.join("builtin/v1.1/v8.data.moved")) + let dataDir = casPath.join("builtin").join("v1.1") + let dataFile = try #require(tester.fs.listdir(dataDir).first { + $0.hasSuffix(".data") && $0.hasPrefix("v") + }) + try tester.fs.move(dataDir.join(dataFile), to: dataDir.join("moved")) try await tester.fs.writeFileContents(casPath.join("builtin/v1.validation")) { stream in stream <<< "0" } From 86601e263fed5ee07035ef6969b0b82e39859892 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Tue, 12 Aug 2025 11:11:38 -0700 Subject: [PATCH 3/3] [TEST-ONLY] Make caching tests to require Xcode26 Add compilation caching test requirement to be Xcode26 to workaround issues in older compiler versions. --- Sources/SWBTestSupport/SkippedTestSupport.swift | 5 ++++- Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift | 2 +- Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift | 2 +- Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/SWBTestSupport/SkippedTestSupport.swift b/Sources/SWBTestSupport/SkippedTestSupport.swift index 502fbc4b..b526492d 100644 --- a/Sources/SWBTestSupport/SkippedTestSupport.swift +++ b/Sources/SWBTestSupport/SkippedTestSupport.swift @@ -299,7 +299,10 @@ extension Trait where Self == Testing.ConditionTrait { /// Constructs a condition trait that causes a test to be disabled if not running against a version of Xcode within the given range. package static func requireXcodeBuildVersions(in range: @Sendable @autoclosure @escaping () throws -> R, sourceLocation: SourceLocation = #_sourceLocation) -> Self where R.Bound == ProductBuildVersion { enabled("Xcode version is not suitable", sourceLocation: sourceLocation, { - return try await range().contains(InstalledXcode.currentlySelected().productBuildVersion()) + guard let installedVersion = try? await InstalledXcode.currentlySelected().productBuildVersion() else { + return true + } + return try range().contains(installedVersion) }) } diff --git a/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift b/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift index c00c85e5..cd1937f8 100644 --- a/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift +++ b/Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift @@ -19,7 +19,7 @@ import SWBTestSupport import SWBUtil @Suite(.skipHostOS(.windows, "Windows platform has no CAS support yet"), - .requireDependencyScannerPlusCaching, .skipInXcodeCloud("flaky tests")) + .requireDependencyScannerPlusCaching, .skipInXcodeCloud("flaky tests"), .requireXcode26()) fileprivate struct ClangCompilationCachingTests: CoreBasedTests { let canUseCASPlugin: Bool let canUseCASPruning: Bool diff --git a/Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift b/Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift index 3a80fbc1..632dbbf1 100644 --- a/Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift +++ b/Tests/SWBBuildSystemTests/ClangModuleVerifierTests.swift @@ -192,7 +192,7 @@ fileprivate struct ClangModuleVerifierTests: CoreBasedTests { } @Test(.requireSDKs(.macOS), .requireClangFeatures(.wSystemHeadersInModule), .requireDependencyScannerPlusCaching, - .skipInXcodeCloud("flaky tests")) + .skipInXcodeCloud("flaky tests"), .requireXcode26()) func cachedBuild() async throws { try await withTemporaryDirectory { (tmpDirPath: Path) in let archs = ["arm64", "x86_64"] diff --git a/Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift b/Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift index 1c0aa6b2..370d740b 100644 --- a/Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift +++ b/Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift @@ -20,7 +20,7 @@ import SWBTaskExecution import SWBProtocol @Suite(.requireSwiftFeatures(.compilationCaching), - .skipInXcodeCloud("flaky tests")) + .skipInXcodeCloud("flaky tests"), .requireXcode26()) fileprivate struct SwiftCompilationCachingTests: CoreBasedTests { @Test(.requireSDKs(.iOS)) func swiftCachingSimple() async throws {