Skip to content
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/BuildSystemIntegration/SwiftPMBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {

/// Retrieve settings for a package manifest (Package.swift).
private func settings(forPackageManifest path: AbsolutePath) throws -> TextDocumentSourceKitOptionsResponse? {
let compilerArgs = swiftPMWorkspace.interpreterFlags(for: path.parentDirectory) + [path.pathString]
let compilerArgs = try swiftPMWorkspace.interpreterFlags(for: path) + [path.pathString]
return TextDocumentSourceKitOptionsResponse(compilerArguments: compilerArgs)
}
}
Expand Down
33 changes: 33 additions & 0 deletions Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,39 @@ final class SwiftPMBuildSystemTests: XCTestCase {
XCTAssert(compilerArgs.contains(try versionSpecificManifestURL.filePath))
}
}

func testBuildSettingsForInvalidManifest() async throws {
try await withTestScratchDir { tempDir in
try FileManager.default.createFiles(
root: tempDir,
files: [
"pkg/Sources/lib/a.swift": "",
"pkg/Package.swift": """
// swift-tools-version: 4.2
import PackageDescription
""",
]
)
let packageRoot = try tempDir.appendingPathComponent("pkg").realpath
let manifestURL = packageRoot.appendingPathComponent("Package.swift")
let buildSystemManager = await BuildSystemManager(
buildSystemSpec: BuildSystemSpec(kind: .swiftPM, projectRoot: packageRoot),
toolchainRegistry: .forTesting,
options: SourceKitLSPOptions(),
connectionToClient: DummyBuildSystemManagerConnectionToClient(),
buildSystemTestHooks: BuildSystemTestHooks()
)
await buildSystemManager.waitForUpToDateBuildGraph()
let settings = await buildSystemManager.buildSettingsInferredFromMainFile(
for: DocumentURI(manifestURL),
language: .swift,
fallbackAfterTimeout: false
)
let compilerArgs = try XCTUnwrap(settings?.compilerArguments)
XCTAssert(compilerArgs.contains("-package-description-version"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth checking that we get the package version correct since that's still well-formed in this case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1885

XCTAssert(compilerArgs.contains(try manifestURL.filePath))
}
}
}

private func assertArgumentsDoNotContain(
Expand Down