Skip to content

[5.5] [swiftpm] Add derived sources to module compiler arguments #402

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 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ extension SwiftPMWorkspace {
args += ["-parse-as-library"]
}
args += ["-c"]
args += td.target.sources.paths.map { $0.pathString }
args += td.sources.map { $0.pathString }
args += ["-I", buildPath.pathString]
args += td.compileArguments()

Expand Down
35 changes: 35 additions & 0 deletions Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,41 @@ final class SwiftPMWorkspaceTests: XCTestCase {
check(resolveSymlinks(ah).pathString, arguments: argsH ?? [])
}
}

func testSwiftDerivedSources() throws {
// FIXME: should be possible to use InMemoryFileSystem.
let fs = localFileSystem
try! withTemporaryDirectory(removeTreeOnDeinit: true) { tempDir in
try! fs.createFiles(root: tempDir, files: [
"pkg/Sources/lib/a.swift": "",
"pkg/Sources/lib/a.txt": "",
"pkg/Package.swift": """
// swift-tools-version:5.3
import PackageDescription
let package = Package(name: "a", products: [], dependencies: [],
targets: [
.target(
name: "lib",
dependencies: [],
resources: [.copy("a.txt")])])
"""
])
let packageRoot = resolveSymlinks(tempDir.appending(component: "pkg"))
let tr = ToolchainRegistry.shared
let ws = try! SwiftPMWorkspace(
workspacePath: packageRoot,
toolchainRegistry: tr,
fileSystem: fs,
buildSetup: TestSourceKitServer.serverOptions.buildSetup)

let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
let arguments = ws.settings(for: aswift.asURI, .swift)!.compilerArguments
check(aswift.pathString, arguments: arguments)
XCTAssertNotNil(arguments.firstIndex(where: {
$0.hasSuffix(".swift") && $0.contains("DerivedSources")
}), "missing resource_bundle_accessor.swift from \(arguments)")
}
}
}

private func checkNot(
Expand Down