Skip to content

Commit edb14e7

Browse files
committed
[5.5] [swiftpm] Add derived sources to module compiler arguments
Now that swiftpm has derived sources, for example the resource bundle accessor generated for `Bundle.module`, we need to ensure they get added to compiler arguments for the module as seen by sourcekit-lsp. Luckily there is now a convenient ".sources" property on the target description. https://bugs.swift.org/browse/SR-14658 (cherry picked from commit 8a65006)
1 parent 6bfa17e commit edb14e7

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ extension SwiftPMWorkspace {
355355
args += ["-parse-as-library"]
356356
}
357357
args += ["-c"]
358-
args += td.target.sources.paths.map { $0.pathString }
358+
args += td.sources.map { $0.pathString }
359359
args += ["-I", buildPath.pathString]
360360
args += td.compileArguments()
361361

Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,41 @@ final class SwiftPMWorkspaceTests: XCTestCase {
530530
check(resolveSymlinks(ah).pathString, arguments: argsH ?? [])
531531
}
532532
}
533+
534+
func testSwiftDerivedSources() throws {
535+
// FIXME: should be possible to use InMemoryFileSystem.
536+
let fs = localFileSystem
537+
try! withTemporaryDirectory(removeTreeOnDeinit: true) { tempDir in
538+
try! fs.createFiles(root: tempDir, files: [
539+
"pkg/Sources/lib/a.swift": "",
540+
"pkg/Sources/lib/a.txt": "",
541+
"pkg/Package.swift": """
542+
// swift-tools-version:5.3
543+
import PackageDescription
544+
let package = Package(name: "a", products: [], dependencies: [],
545+
targets: [
546+
.target(
547+
name: "lib",
548+
dependencies: [],
549+
resources: [.copy("a.txt")])])
550+
"""
551+
])
552+
let packageRoot = resolveSymlinks(tempDir.appending(component: "pkg"))
553+
let tr = ToolchainRegistry.shared
554+
let ws = try! SwiftPMWorkspace(
555+
workspacePath: packageRoot,
556+
toolchainRegistry: tr,
557+
fileSystem: fs,
558+
buildSetup: TestSourceKitServer.serverOptions.buildSetup)
559+
560+
let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
561+
let arguments = ws.settings(for: aswift.asURI, .swift)!.compilerArguments
562+
check(aswift.pathString, arguments: arguments)
563+
XCTAssertNotNil(arguments.firstIndex(where: {
564+
$0.hasSuffix(".swift") && $0.contains("DerivedSources")
565+
}), "missing resource_bundle_accessor.swift from \(arguments)")
566+
}
567+
}
533568
}
534569

535570
private func checkNot(

0 commit comments

Comments
 (0)