Skip to content

Commit c6da47b

Browse files
committed
track SDK dependencies rdar://115777026
1 parent 60ee80d commit c6da47b

File tree

7 files changed

+41
-2
lines changed

7 files changed

+41
-2
lines changed

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,12 @@ public final class SwiftTargetBuildDescription {
645645
}
646646
}
647647

648+
// rdar://115777026
649+
// Compiler commands need to track SDK dependencies to trigger rebuilds when the SDK changes
650+
if let sdkPath = self.buildParameters.sdkPath, self.buildParameters.targetTriple.isDarwin() {
651+
args += ["-sdk", sdkPath.pathString]
652+
}
653+
648654
return args
649655
}
650656

Sources/CoreCommands/SwiftTool.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ public final class SwiftTool {
695695

696696
return try BuildParameters(
697697
dataPath: dataPath,
698+
sdkPath: toolchain.sdkRootPath,
698699
configuration: options.build.configuration,
699700
toolchain: toolchain,
700701
triple: triple,

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(

Sources/SPMBuildCore/BuildParameters/BuildParameters.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public struct BuildParameters: Encodable {
2929
/// The path to the data directory.
3030
public var dataPath: AbsolutePath
3131

32+
/// The path to the SDKROOT directory.
33+
public var sdkPath: AbsolutePath?
34+
3235
/// The build configuration.
3336
public var configuration: BuildConfiguration
3437

@@ -119,6 +122,7 @@ public struct BuildParameters: Encodable {
119122

120123
public init(
121124
dataPath: AbsolutePath,
125+
sdkPath: AbsolutePath?,
122126
configuration: BuildConfiguration,
123127
toolchain: Toolchain,
124128
triple: Triple? = nil,
@@ -145,6 +149,7 @@ public struct BuildParameters: Encodable {
145149
)
146150

147151
self.dataPath = dataPath
152+
self.sdkPath = toolchain.sdkRootPath
148153
self.configuration = configuration
149154
self._toolchain = _Toolchain(toolchain: toolchain)
150155
self.triple = triple

Sources/SPMTestSupport/MockBuildTestHelper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public func mockBuildParameters(
8585
) -> BuildParameters {
8686
try! BuildParameters(
8787
dataPath: buildPath,
88+
sdkPath: toolchain.sdkRootPath,
8889
configuration: config,
8990
toolchain: toolchain,
9091
triple: targetTriple,

Sources/swift-bootstrap/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
279279

280280
let buildParameters = try BuildParameters(
281281
dataPath: dataPath,
282+
sdkPath: self.targetToolchain.sdkRootPath,
282283
configuration: configuration,
283284
toolchain: self.targetToolchain,
284285
triple: self.hostToolchain.targetTriple,

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)