Skip to content

Return compiler arguments for invalid package manifests #1846

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
Dec 9, 2024
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