From 01dbed91078687f924d9f1c30da839e6565f68c9 Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Sun, 15 Jun 2025 20:28:20 +0100 Subject: [PATCH 1/2] [xcodegen] NFC: Rename `resolvingSymlinks` -> `realPath` --- .../Sources/SwiftXcodeGen/Path/AbsolutePath.swift | 2 +- .../swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/AbsolutePath.swift b/utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/AbsolutePath.swift index 600a8378b0ff5..09738352b1e26 100644 --- a/utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/AbsolutePath.swift +++ b/utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/AbsolutePath.swift @@ -52,7 +52,7 @@ public extension AbsolutePath { (try? FileManager.default.destinationOfSymbolicLink(atPath: rawPath)) != nil } - var resolvingSymlinks: Self { + var realPath: Self { guard let resolved = realpath(rawPath, nil) else { return self } defer { free(resolved) diff --git a/utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift b/utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift index 52e5d0852e703..9609c56bad212 100644 --- a/utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift +++ b/utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift @@ -84,7 +84,7 @@ struct SwiftXcodegen: AsyncParsableCommand, Sendable { // Check to see if we have a separate runnable build dir. let runnableBuildDirPath = - self.runnableBuildDir?.absoluteInWorkingDir.resolvingSymlinks + self.runnableBuildDir?.absoluteInWorkingDir.realPath let runnableBuildDir = try runnableBuildDirPath.map { try NinjaBuildDir(at: $0, projectRootDir: ninja.projectRootDir) .buildDir(for: .swift) @@ -332,7 +332,7 @@ struct SwiftXcodegen: AsyncParsableCommand, Sendable { } func generate() async throws { - let buildDirPath = buildDir.absoluteInWorkingDir.resolvingSymlinks + let buildDirPath = buildDir.absoluteInWorkingDir.realPath log.info("Generating project for '\(buildDirPath)'...") let projectRootDir = self.projectRootDir?.absoluteInWorkingDir From 27ec6e3a4530a5a28f4f740a875f46fb44ab640e Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Sun, 15 Jun 2025 20:28:20 +0100 Subject: [PATCH 2/2] [xcodegen] `realpath` Swift target sources Make sure we call `realpath` for the Swift target sources read from the build settings to ensure we canonicalize their casing. --- .../Sources/SwiftXcodeGen/BuildArgs/SwiftTargets.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/SwiftTargets.swift b/utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/SwiftTargets.swift index d3984edfbd21d..0d7874e421f6c 100644 --- a/utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/SwiftTargets.swift +++ b/utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/SwiftTargets.swift @@ -124,10 +124,14 @@ struct SwiftTargets { // A relative path is for a file in the build directory, it's external. let abs = buildDir.path.appending(r) guard abs.exists else { continue } - sources.externalSources.append(abs) + sources.externalSources.append(abs.realPath) case .absolute(let a): - guard a.exists, let rel = a.removingPrefix(buildDir.repoPath) else { + guard a.exists else { continue } + // Symlinks shouldn't really be a concern here, but we need to realpath + // in order to canonicalize the casing. + let a = a.realPath + guard let rel = a.removingPrefix(buildDir.repoPath) else { sources.externalSources.append(a) continue }