Skip to content

Commit f37d935

Browse files
author
David Ungar
authored
Merge pull request #454 from davidungar/add-sdk-incremental
[Incremental] Add sdk arguments to incremental tests
2 parents 34b5ff7 + 708e816 commit f37d935

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

Tests/SwiftDriverTests/Helpers/DriverExtensions.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import SwiftDriver
1414
import SwiftDriverExecution
1515
import TSCBasic
16+
import Foundation
17+
import XCTest
1618

1719
extension Driver {
1820
/// Initializer which creates an executor suitable for use in tests.
@@ -32,4 +34,29 @@ extension Driver {
3234
fileSystem: fileSystem,
3335
executor: executor)
3436
}
37+
38+
// For tests that need to set the sdk path:
39+
static func sdkArgumentsForTesting() throws -> [String] {
40+
["-sdk", try cachedSDKPath.get()]
41+
}
42+
}
43+
44+
private let cachedSDKPath = Result<String, Error> {
45+
if let pathFromEnv = ProcessEnv.vars["SDKROOT"] {
46+
return pathFromEnv
47+
}
48+
#if !os(macOS)
49+
throw XCTSkip("xcrun only available on macOS")
50+
#endif
51+
let process = Process(arguments: ["xcrun", "-sdk", "macosx", "--show-sdk-path"])
52+
try process.launch()
53+
let result = try process.waitUntilExit()
54+
guard result.exitStatus == .terminated(code: EXIT_SUCCESS) else {
55+
enum XCRunFailure: LocalizedError {
56+
case xcrunFailure
57+
}
58+
throw XCRunFailure.xcrunFailure
59+
}
60+
return try XCTUnwrap(String(bytes: try result.output.get(), encoding: .utf8))
61+
.spm_chomp()
3562
}

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ final class IncrementalCompilationTests: XCTestCase {
394394
// FIXME: Expect failure in Linux in CI just as testIncrementalDiagnostics
395395
func testAlwaysRebuildDependents() throws {
396396
#if !os(Linux)
397-
tryInitial(true)
397+
try tryInitial(true)
398398
tryTouchingMainAlwaysRebuildDependents(true)
399399
#endif
400400
}
@@ -406,14 +406,14 @@ final class IncrementalCompilationTests: XCTestCase {
406406
/// Ensure that the mod date of the input comes back exactly the same via the build-record.
407407
/// Otherwise the up-to-date calculation in `IncrementalCompilationState` will fail.
408408
func testBuildRecordDateAccuracy() throws {
409-
tryInitial(false)
409+
try tryInitial(false)
410410
(1...10).forEach { n in
411411
tryNoChange(true)
412412
}
413413
}
414414

415415
func testIncremental(checkDiagnostics: Bool) throws {
416-
tryInitial(checkDiagnostics)
416+
try tryInitial(checkDiagnostics)
417417
#if true // sometimes want to skip for debugging
418418
tryNoChange(checkDiagnostics)
419419
tryTouchingOther(checkDiagnostics)
@@ -423,8 +423,8 @@ final class IncrementalCompilationTests: XCTestCase {
423423
}
424424

425425

426-
func tryInitial(_ checkDiagnostics: Bool) {
427-
try! doABuild(
426+
func tryInitial(_ checkDiagnostics: Bool) throws {
427+
try doABuild(
428428
"initial",
429429
checkDiagnostics: checkDiagnostics,
430430
expectingRemarks: [
@@ -609,7 +609,7 @@ final class IncrementalCompilationTests: XCTestCase {
609609
try? driver.run(jobs: jobs)
610610
}
611611

612-
let allArgs = args + extraArguments
612+
let allArgs = try args + extraArguments + Driver.sdkArgumentsForTesting()
613613
if checkDiagnostics {
614614
try assertDriverDiagnostics(args: allArgs) {driver, verifier in
615615
verifier.forbidUnexpected(.error, .warning, .note, .remark, .ignored)

0 commit comments

Comments
 (0)