Skip to content
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

Return compiler arguments for invalid package manifests #1846

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -756,7 +756,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)
}
}
33 changes: 33 additions & 0 deletions Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,39 @@ final class SwiftPMBuildSystemTests: XCTestCase {
XCTAssertEqual(end.token, begin.token)
XCTAssertEqual(end.value, .end(WorkDoneProgressEnd()))
}

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?

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

private func assertArgumentsDoNotContain(
Expand Down