Skip to content

Commit 603c5c6

Browse files
Merge pull request #1508 from cachemeifyoucan/eng/PR-1507
2 parents 89c80d8 + fdc22a9 commit 603c5c6

File tree

2 files changed

+82
-82
lines changed

2 files changed

+82
-82
lines changed

Tests/SwiftDriverTests/CachingBuildTests.swift

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ private func checkCachingBuildJobDependencies(job: Job,
205205

206206

207207
final class CachingBuildTests: XCTestCase {
208+
override func setUpWithError() throws {
209+
try super.setUpWithError()
210+
211+
// If the toolchain doesn't support caching, skip directly.
212+
let driver = try Driver(args: ["swiftc", "-v"])
213+
#if os(Windows)
214+
throw XCTSkip("caching not supported on windows")
215+
#else
216+
guard driver.isFeatureSupported(.cache_compile_job) else {
217+
throw XCTSkip("caching not supported")
218+
}
219+
#endif
220+
}
221+
208222
private func pathMatchesSwiftModule(path: VirtualPath, _ name: String) -> Bool {
209223
return path.basenameWithoutExt.starts(with: "\(name)-") &&
210224
path.extension! == FileType.swiftModule.rawValue
@@ -234,9 +248,6 @@ final class CachingBuildTests: XCTestCase {
234248
"-cache-compile-job", "-cas-path", casPath.nativePathString(escaped: true),
235249
"-import-objc-header", bridgingHeaderpath.nativePathString(escaped: true),
236250
main.nativePathString(escaped: true)] + sdkArgumentsForTesting)
237-
guard driver.isFeatureSupported(.cache_compile_job) else {
238-
throw XCTSkip("toolchain does not support caching.")
239-
}
240251

241252
let jobs = try driver.planBuild()
242253
let dependencyGraph = try driver.gatherModuleDependencies()
@@ -361,9 +372,6 @@ final class CachingBuildTests: XCTestCase {
361372
guard driver.supportExplicitModuleVerifyInterface() else {
362373
throw XCTSkip("-typecheck-module-from-interface doesn't support explicit build.")
363374
}
364-
guard driver.isFeatureSupported(.cache_compile_job) else {
365-
throw XCTSkip("toolchain does not support caching.")
366-
}
367375

368376
let jobs = try driver.planBuild()
369377
// Figure out which Triples to use.
@@ -492,9 +500,6 @@ final class CachingBuildTests: XCTestCase {
492500
"-working-directory", path.nativePathString(escaped: true),
493501
main.nativePathString(escaped: true)] + sdkArgumentsForTesting,
494502
env: ProcessEnv.vars)
495-
guard driver.isFeatureSupported(.cache_compile_job) else {
496-
throw XCTSkip("toolchain does not support caching.")
497-
}
498503
let jobs = try driver.planBuild()
499504
try driver.run(jobs: jobs)
500505
XCTAssertFalse(driver.diagnosticEngine.hasErrors)
@@ -553,10 +558,6 @@ final class CachingBuildTests: XCTestCase {
553558
+ sdkArgumentsForTesting,
554559
env: ProcessEnv.vars)
555560

556-
// Ensure this tooling supports this functionality
557-
guard fooBuildDriver.isFeatureSupported(.cache_compile_job) else {
558-
throw XCTSkip("toolchain does not support caching.")
559-
}
560561
let dependencyOracle = InterModuleDependencyOracle()
561562
let scanLibPath = try XCTUnwrap(fooBuildDriver.toolchain.lookupSwiftScanLib())
562563
guard try dependencyOracle
@@ -623,9 +624,6 @@ final class CachingBuildTests: XCTestCase {
623624
"-disable-clang-target",
624625
main.nativePathString(escaped: true)] + sdkArgumentsForTesting,
625626
env: ProcessEnv.vars)
626-
guard driver.isFeatureSupported(.cache_compile_job) else {
627-
throw XCTSkip("toolchain does not support caching.")
628-
}
629627
let dependencyOracle = InterModuleDependencyOracle()
630628
let scanLibPath = try XCTUnwrap(driver.toolchain.lookupSwiftScanLib())
631629
guard try dependencyOracle
@@ -674,38 +672,42 @@ final class CachingBuildTests: XCTestCase {
674672
// FIXME: We need to differentiate the scanning action hash,
675673
// though the module-name above should be sufficient.
676674
"-I/tmp/foo/bar/\(index)"]
677-
let dependencyGraph =
678-
try! dependencyOracle.getDependencies(workingDirectory: path,
679-
commandLine: iterationCommand)
680-
681-
// The _Concurrency and _StringProcessing modules are automatically
682-
// imported in newer versions of the Swift compiler. If they happened to
683-
// be provided, adjust our expectations accordingly.
684-
let hasConcurrencyModule = dependencyGraph.modules.keys.contains {
685-
$0.moduleName == "_Concurrency"
686-
}
687-
let hasConcurrencyShimsModule = dependencyGraph.modules.keys.contains {
688-
$0.moduleName == "_SwiftConcurrencyShims"
689-
}
690-
let hasStringProcessingModule = dependencyGraph.modules.keys.contains {
691-
$0.moduleName == "_StringProcessing"
692-
}
693-
let adjustedExpectedNumberOfDependencies =
694-
expectedNumberOfDependencies +
695-
(hasConcurrencyModule ? 1 : 0) +
696-
(hasConcurrencyShimsModule ? 1 : 0) +
697-
(hasStringProcessingModule ? 1 : 0)
698-
699-
if (dependencyGraph.modules.count != adjustedExpectedNumberOfDependencies) {
700-
lock.lock()
701-
print("Unexpected Dependency Scanning Result (\(dependencyGraph.modules.count) modules):")
702-
dependencyGraph.modules.forEach {
703-
print($0.key.moduleName)
675+
do {
676+
let dependencyGraph =
677+
try dependencyOracle.getDependencies(workingDirectory: path,
678+
commandLine: iterationCommand)
679+
680+
// The _Concurrency and _StringProcessing modules are automatically
681+
// imported in newer versions of the Swift compiler. If they happened to
682+
// be provided, adjust our expectations accordingly.
683+
let hasConcurrencyModule = dependencyGraph.modules.keys.contains {
684+
$0.moduleName == "_Concurrency"
685+
}
686+
let hasConcurrencyShimsModule = dependencyGraph.modules.keys.contains {
687+
$0.moduleName == "_SwiftConcurrencyShims"
704688
}
705-
lock.unlock()
689+
let hasStringProcessingModule = dependencyGraph.modules.keys.contains {
690+
$0.moduleName == "_StringProcessing"
691+
}
692+
let adjustedExpectedNumberOfDependencies =
693+
expectedNumberOfDependencies +
694+
(hasConcurrencyModule ? 1 : 0) +
695+
(hasConcurrencyShimsModule ? 1 : 0) +
696+
(hasStringProcessingModule ? 1 : 0)
697+
698+
if (dependencyGraph.modules.count != adjustedExpectedNumberOfDependencies) {
699+
lock.lock()
700+
print("Unexpected Dependency Scanning Result (\(dependencyGraph.modules.count) modules):")
701+
dependencyGraph.modules.forEach {
702+
print($0.key.moduleName)
703+
}
704+
lock.unlock()
705+
}
706+
XCTAssertTrue(dependencyGraph.modules.count ==
707+
adjustedExpectedNumberOfDependencies)
708+
} catch {
709+
XCTFail("Unexpected error: \(error)")
706710
}
707-
XCTAssertTrue(dependencyGraph.modules.count ==
708-
adjustedExpectedNumberOfDependencies)
709711
}
710712

711713
// Change CAS path is an error.
@@ -759,9 +761,6 @@ final class CachingBuildTests: XCTestCase {
759761
"-scanner-prefix-map", path.description + "=/^tmp",
760762
main.nativePathString(escaped: true)] + sdkArgumentsForTesting,
761763
env: ProcessEnv.vars)
762-
guard driver.isFeatureSupported(.cache_compile_job) else {
763-
throw XCTSkip("toolchain does not support caching.")
764-
}
765764
guard driver.isFrontendArgSupported(.scannerPrefixMap) else {
766765
throw XCTSkip("frontend doesn't support prefix map")
767766
}
@@ -832,9 +831,6 @@ final class CachingBuildTests: XCTestCase {
832831
"-working-directory", path.nativePathString(escaped: true),
833832
main.nativePathString(escaped: true)] + sdkArgumentsForTesting,
834833
env: ProcessEnv.vars)
835-
guard driver.isFeatureSupported(.cache_compile_job) else {
836-
throw XCTSkip("toolchain does not support caching.")
837-
}
838834
let jobs = try driver.planBuild()
839835
try driver.run(jobs: jobs)
840836
XCTAssertFalse(driver.diagnosticEngine.hasErrors)

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,38 +1441,42 @@ final class ExplicitModuleBuildTests: XCTestCase {
14411441
// FIXME: We need to differentiate the scanning action hash,
14421442
// though the module-name above should be sufficient.
14431443
"-I/tmp/foo/bar/\(index)"]
1444-
let dependencyGraph =
1445-
try! dependencyOracle.getDependencies(workingDirectory: path,
1446-
commandLine: iterationCommand)
1447-
1448-
// The _Concurrency and _StringProcessing modules are automatically
1449-
// imported in newer versions of the Swift compiler. If they happened to
1450-
// be provided, adjust our expectations accordingly.
1451-
let hasConcurrencyModule = dependencyGraph.modules.keys.contains {
1452-
$0.moduleName == "_Concurrency"
1453-
}
1454-
let hasConcurrencyShimsModule = dependencyGraph.modules.keys.contains {
1455-
$0.moduleName == "_SwiftConcurrencyShims"
1456-
}
1457-
let hasStringProcessingModule = dependencyGraph.modules.keys.contains {
1458-
$0.moduleName == "_StringProcessing"
1459-
}
1460-
let adjustedExpectedNumberOfDependencies =
1461-
expectedNumberOfDependencies +
1462-
(hasConcurrencyModule ? 1 : 0) +
1463-
(hasConcurrencyShimsModule ? 1 : 0) +
1464-
(hasStringProcessingModule ? 1 : 0)
1465-
1466-
if (dependencyGraph.modules.count != adjustedExpectedNumberOfDependencies) {
1467-
lock.lock()
1468-
print("Unexpected Dependency Scanning Result (\(dependencyGraph.modules.count) modules):")
1469-
dependencyGraph.modules.forEach {
1470-
print($0.key.moduleName)
1444+
do {
1445+
let dependencyGraph =
1446+
try dependencyOracle.getDependencies(workingDirectory: path,
1447+
commandLine: iterationCommand)
1448+
1449+
// The _Concurrency and _StringProcessing modules are automatically
1450+
// imported in newer versions of the Swift compiler. If they happened to
1451+
// be provided, adjust our expectations accordingly.
1452+
let hasConcurrencyModule = dependencyGraph.modules.keys.contains {
1453+
$0.moduleName == "_Concurrency"
1454+
}
1455+
let hasConcurrencyShimsModule = dependencyGraph.modules.keys.contains {
1456+
$0.moduleName == "_SwiftConcurrencyShims"
1457+
}
1458+
let hasStringProcessingModule = dependencyGraph.modules.keys.contains {
1459+
$0.moduleName == "_StringProcessing"
1460+
}
1461+
let adjustedExpectedNumberOfDependencies =
1462+
expectedNumberOfDependencies +
1463+
(hasConcurrencyModule ? 1 : 0) +
1464+
(hasConcurrencyShimsModule ? 1 : 0) +
1465+
(hasStringProcessingModule ? 1 : 0)
1466+
1467+
if (dependencyGraph.modules.count != adjustedExpectedNumberOfDependencies) {
1468+
lock.lock()
1469+
print("Unexpected Dependency Scanning Result (\(dependencyGraph.modules.count) modules):")
1470+
dependencyGraph.modules.forEach {
1471+
print($0.key.moduleName)
1472+
}
1473+
lock.unlock()
14711474
}
1472-
lock.unlock()
1475+
XCTAssertTrue(dependencyGraph.modules.count ==
1476+
adjustedExpectedNumberOfDependencies)
1477+
} catch {
1478+
XCTFail("Unexpected error: \(error)")
14731479
}
1474-
XCTAssertTrue(dependencyGraph.modules.count ==
1475-
adjustedExpectedNumberOfDependencies)
14761480
}
14771481
}
14781482
}

0 commit comments

Comments
 (0)