Skip to content

Background preparation runs swift build in SourceKit-LSP's working directory instead of the package's #2793

Description

@rgoldberg

Swift version

swift-driver version: 1.168.6 Apple Swift version 6.4 (swiftlang-6.4.0.34.1 clang-2100.3.34.1)

Platform

macOS 27.0.1 (26A434)

Editor

IntelliJ IDEA 2026.2 (SourceKit-LSP from Xcode 27.0 (27A266a))

Description

SwiftPMBuildServer.prepare(singleTarget:) runs swift build with workingDirectory: nil, so the build inherits SourceKit-LSP's working directory, which is whatever directory from which the editor launched it:

Any relative path written during preparation therefore lands outside the scratch directory, & possibly outside the package entirely. In practice, swift-driver writes relative supplementary outputs (from the example from swiftlang/swift-package-manager#10652: MAS+BuildInfo-2.d, MAS+BuildInfo-2.dia, MAS+BuildInfo-2.swiftdeps & MAS+BuildInfo-2.swiftmodule) when an input is missing from SwiftPM's output file map.

For mas, these files appeared both in the package root & in an unrelated sibling clone that happened to be SourceKit-LSP's working directory, while the .d files listed sources from the other package.

Running preparation with a working directory inside the scratch directory (e.g., .build/index-build) would confine any such stray outputs to build artifacts.

Steps to Reproduce

  1. Launch SourceKit-LSP with a working directory other than the package root
  2. Open a package whose swift build writes a relative path during preparation (e.g., via the SwiftPM issue above)
  3. The relative path is resolved against SourceKit-LSP's working directory, not the package or scratch directory

Logging

Not captured; the stray files were found after the fact.

Activity

  1. added theissue type on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions