Skip to content

[PCH][OutputFileMap] GeneratePCH output should use single output entry #1832

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
Mar 7, 2025
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
5 changes: 2 additions & 3 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3133,8 +3133,7 @@ extension Driver {
func computePrecompiledBridgingHeaderDir(
_ parsedOptions: inout ParsedOptions,
compilerMode: CompilerMode) throws -> VirtualPath? {
if let input = originalObjCHeaderFile,
let outputPath = try? outputFileMap?.existingOutput(inputFile: input, outputType: .pch) {
if let outputPath = try? outputFileMap?.existingOutputForSingleInput(outputType: .pch) {
return VirtualPath.lookup(outputPath).parentDirectory
}
if let outputDir = parsedOptions.getLastArgument(.pchOutputDir)?.asSingle {
Expand All @@ -3154,7 +3153,7 @@ extension Driver {
return nil
}

if let outputPath = try? outputFileMap?.existingOutput(inputFile: input, outputType: .pch) {
if let outputPath = try? outputFileMap?.existingOutputForSingleInput(outputType: .pch) {
return outputPath
}

Expand Down
32 changes: 32 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,38 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testEmitPCHWithOutputFileMap() throws {
try withTemporaryDirectory { path in
let outputFileMap = path.appending(component: "outputFileMap.json")
try localFileSystem.writeFileContents(outputFileMap, bytes: """
{
"": {
"pch": "/build/Foo-bridging-header.pch"
}
}
"""
)
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Foo", "-emit-module",
"-serialize-diagnostics", "-experimental-emit-module-separately",
"-import-objc-header", "bridging.h", "-enable-bridging-pch",
"-output-file-map", outputFileMap.description])
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
XCTAssertTrue(driver.diagnosticEngine.diagnostics.isEmpty)

// Test the output path is correct for GeneratePCH job.
XCTAssertEqual(plannedJobs.count, 4)
XCTAssertEqual(plannedJobs[0].kind, .generatePCH)
try XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-o"), .path(.absolute(.init(validating: "/build/Foo-bridging-header.pch"))))

// Plan a build with no bridging header and make sure no diagnostics is emitted (pch in output file map is still accepted)
driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Foo", "-emit-module",
"-serialize-diagnostics", "-experimental-emit-module-separately",
"-output-file-map", outputFileMap.description])
let _ = try driver.planBuild()
XCTAssertTrue(driver.diagnosticEngine.diagnostics.isEmpty)
}
}

func testReferenceDependencies() throws {
var driver = try Driver(args: ["swiftc", "foo.swift", "-incremental"])
let plannedJobs = try driver.planBuild()
Expand Down