Skip to content

Commit cdceff5

Browse files
track SDK dependencies (rdar://115777026) (#7172)
Compiler commands need to track SDK dependencies to trigger rebuilds when the SDK changes rdar://115777026 ### Motivation: track SDK dependencies to avoid triggering rebuilds when the SDK changes rdar://115777026 --------- Co-authored-by: Max Desiatov <[email protected]>
1 parent 3ef830d commit cdceff5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ public struct SwiftSDK: Equatable {
478478
let sdkPath: AbsolutePath?
479479
#if os(macOS)
480480
// Get the SDK.
481-
if let value = lookupExecutablePath(filename: ProcessEnv.vars["SDKROOT"]) {
482-
sdkPath = value
481+
if let value = ProcessEnv.vars["SDKROOT"] {
482+
sdkPath = try AbsolutePath(validating: value)
483483
} else {
484484
// No value in env, so search for it.
485485
let sdkPathStr = try TSCBasic.Process.checkNonZeroExit(

Tests/BuildTests/IncrementalBuildTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Basics
1414
import PackageModel
1515
import SPMTestSupport
1616
import XCTest
17+
import class TSCBasic.Process
1718

1819
/// Functional tests of incremental builds. These are fairly ad hoc at this
1920
/// point, and because of the time they take, they need to be kept minimal.
@@ -145,4 +146,28 @@ final class IncrementalBuildTests: XCTestCase {
145146
XCTAssertNoMatch(log2, .contains("Planning build"))
146147
}
147148
}
149+
// testing the fix for tracking SDK dependencies to avoid triggering rebuilds when the SDK changes (rdar://115777026)
150+
func testSDKTracking() throws {
151+
#if os(macOS)
152+
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
153+
154+
try fixture(name: "ValidLayouts/SingleModule/Library") { fixturePath in
155+
let dummySwiftcPath = SwiftPM.xctestBinaryPath(for: "dummy-swiftc")
156+
let swiftCompilerPath = try UserToolchain.default.swiftCompilerPath
157+
let environment = [
158+
"SWIFT_EXEC": dummySwiftcPath.pathString,
159+
"SWIFT_ORIGINAL_PATH": swiftCompilerPath.pathString
160+
]
161+
let sdkPathStr = try TSCBasic.Process.checkNonZeroExit(
162+
arguments: ["/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-path"],
163+
environment: environment
164+
).spm_chomp()
165+
166+
let newSdkPathStr = "/tmp/../\(sdkPathStr)"
167+
// Perform a full build again because SDK changed.
168+
let log1 = try executeSwiftBuild(fixturePath, env: ["SDKROOT": newSdkPathStr]).stdout
169+
XCTAssertMatch(log1, .contains("Compiling Library"))
170+
}
171+
#endif
172+
}
148173
}

0 commit comments

Comments
 (0)