Skip to content

track SDK dependencies (rdar://115777026) #7172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,12 @@ public final class SwiftTargetBuildDescription {
}
}

// rdar://115777026
// Compiler commands need to track SDK dependencies to trigger rebuilds when the SDK changes
if let sdkPath = self.buildParameters.toolchain.sdkRootPath, self.buildParameters.triple.isDarwin() {
args += ["-sdk", sdkPath.pathString]
}

return args
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ public struct SwiftSDK: Equatable {
let sdkPath: AbsolutePath?
#if os(macOS)
// Get the SDK.
if let value = lookupExecutablePath(filename: ProcessEnv.vars["SDKROOT"]) {
sdkPath = value
if let value = ProcessEnv.vars["SDKROOT"] {
sdkPath = try AbsolutePath(validating: value)
} else {
// No value in env, so search for it.
let sdkPathStr = try TSCBasic.Process.checkNonZeroExit(
Expand Down
25 changes: 25 additions & 0 deletions Tests/BuildTests/IncrementalBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Basics
import PackageModel
import SPMTestSupport
import XCTest
import class TSCBasic.Process

/// Functional tests of incremental builds. These are fairly ad hoc at this
/// point, and because of the time they take, they need to be kept minimal.
Expand Down Expand Up @@ -145,4 +146,28 @@ final class IncrementalBuildTests: XCTestCase {
XCTAssertNoMatch(log2, .contains("Planning build"))
}
}
// testing the fix for tracking SDK dependencies to avoid triggering rebuilds when the SDK changes (rdar://115777026)
func testSDKTracking() throws {
#if os(macOS)
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")

try fixture(name: "ValidLayouts/SingleModule/Library") { fixturePath in
let dummySwiftcPath = SwiftPM.xctestBinaryPath(for: "dummy-swiftc")
let swiftCompilerPath = try UserToolchain.default.swiftCompilerPath
let environment = [
"SWIFT_EXEC": dummySwiftcPath.pathString,
"SWIFT_ORIGINAL_PATH": swiftCompilerPath.pathString
]
let sdkPathStr = try TSCBasic.Process.checkNonZeroExit(
arguments: ["/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-path"],
environment: environment
).spm_chomp()

let newSdkPathStr = "/tmp/../\(sdkPathStr)"
// Perform a full build again because SDK changed.
let log1 = try executeSwiftBuild(fixturePath, env: ["SDKROOT": newSdkPathStr]).stdout
XCTAssertMatch(log1, .contains("Compiling Library"))
}
#endif
}
}