Skip to content

Commit b7fbb47

Browse files
ahoppenbnbarham
authored andcommitted
Do not realpath the project root of a SwiftPMBuildSystem
If you have a package located at `/pkg` and a symlink at `/symlink` and you open `/symlink` as a workspace, the SwiftPMBuildSystem’s project root would be `/pkg`. This would mean that it also only knew about build settings for files in `/pkg`, not in `/symlink`. Thus, whenever we were opening a file in `/symlink` we would create an implicit workspace to handle it (but which ended up having a project root at `/symlink` again) – or something close to this. We shouldn’t need to realpath here. If you open `/symlink`, we should view `/symlink` as the project root of your workspace. (cherry picked from commit 8617b8b)
1 parent 351a781 commit b7fbb47

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
169169
private var targetDependencies: [BuildTargetIdentifier: Set<BuildTargetIdentifier>] = [:]
170170

171171
static package func projectRoot(for path: URL, options: SourceKitLSPOptions) -> URL? {
172-
guard var path = orLog("Getting realpath for project root", { try path.realpath }) else {
173-
return nil
174-
}
172+
var path = path
175173
while true {
176174
let packagePath = path.appendingPathComponent("Package.swift")
177175
if (try? String(contentsOf: packagePath, encoding: .utf8))?.contains("PackageDescription") ?? false {

Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -806,28 +806,21 @@ final class SwiftPMBuildSystemTests: XCTestCase {
806806
fallbackAfterTimeout: false
807807
)
808808
).compilerArguments
809-
let argumentsFromReal = try await unwrap(
810-
buildSystemManager.buildSettingsInferredFromMainFile(
811-
for: DocumentURI(aswiftReal),
812-
language: .swift,
813-
fallbackAfterTimeout: false
814-
)
815-
).compilerArguments
816809

817-
// The arguments retrieved from the symlink and the real document should be the same, except that both should
818-
// contain they file the build settings were created.
819-
// FIXME: Or should the build settings always reference the main file?
820-
XCTAssertEqual(
821-
try argumentsFromSymlink.filter { try $0 != aswiftSymlink.filePath && $0 != aswiftReal.filePath },
822-
try argumentsFromReal.filter { try $0 != aswiftSymlink.filePath && $0 != aswiftReal.filePath }
810+
// We opened the project from a symlink. The realpath isn't part of the project and we should thus not receive
811+
// build settings for it.
812+
assertTrue(
813+
try await unwrap(
814+
buildSystemManager.buildSettingsInferredFromMainFile(
815+
for: DocumentURI(aswiftReal),
816+
language: .swift,
817+
fallbackAfterTimeout: false
818+
)
819+
).isFallback
823820
)
824-
825821
assertArgumentsContain(try aswiftSymlink.filePath, arguments: argumentsFromSymlink)
826822
assertArgumentsDoNotContain(try aswiftReal.filePath, arguments: argumentsFromSymlink)
827823

828-
assertArgumentsContain(try aswiftReal.filePath, arguments: argumentsFromReal)
829-
assertArgumentsDoNotContain(try aswiftSymlink.filePath, arguments: argumentsFromReal)
830-
831824
let argsManifest = try await unwrap(
832825
buildSystemManager.buildSettingsInferredFromMainFile(
833826
for: DocumentURI(manifest),

0 commit comments

Comments
 (0)