Skip to content

Commit 916d857

Browse files
[PCH][OutputFileMap] GeneratePCH output should use single output entry
The build system has been emitting the output path of generating PCH job in the module level entry in the output file map, while swift-driver is expecting the entry in an entry that accosiated with imported bridging header. This patch unifies the behavior by picking the implementation of the swift-build, where it is a module level entry. This works better for future when bridging header can be chained, thus creating PCH job even there isn't a imported objc header explicitly provided. rdar://146395316
1 parent a9afe15 commit 916d857

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

Sources/SwiftDriver/Driver/Driver.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -3133,8 +3133,7 @@ extension Driver {
31333133
func computePrecompiledBridgingHeaderDir(
31343134
_ parsedOptions: inout ParsedOptions,
31353135
compilerMode: CompilerMode) throws -> VirtualPath? {
3136-
if let input = originalObjCHeaderFile,
3137-
let outputPath = try? outputFileMap?.existingOutput(inputFile: input, outputType: .pch) {
3136+
if let outputPath = try? outputFileMap?.existingOutputForSingleInput(outputType: .pch) {
31383137
return VirtualPath.lookup(outputPath).parentDirectory
31393138
}
31403139
if let outputDir = parsedOptions.getLastArgument(.pchOutputDir)?.asSingle {
@@ -3154,7 +3153,7 @@ extension Driver {
31543153
return nil
31553154
}
31563155

3157-
if let outputPath = try? outputFileMap?.existingOutput(inputFile: input, outputType: .pch) {
3156+
if let outputPath = try? outputFileMap?.existingOutputForSingleInput(outputType: .pch) {
31583157
return outputPath
31593158
}
31603159

Tests/SwiftDriverTests/SwiftDriverTests.swift

+32
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,38 @@ final class SwiftDriverTests: XCTestCase {
14331433
}
14341434
}
14351435

1436+
func testEmitPCHWithOutputFileMap() throws {
1437+
try withTemporaryDirectory { path in
1438+
let outputFileMap = path.appending(component: "outputFileMap.json")
1439+
try localFileSystem.writeFileContents(outputFileMap, bytes: """
1440+
{
1441+
"": {
1442+
"pch": "/build/Foo-bridging-header.pch"
1443+
}
1444+
}
1445+
"""
1446+
)
1447+
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Foo", "-emit-module",
1448+
"-serialize-diagnostics", "-experimental-emit-module-separately",
1449+
"-import-objc-header", "bridging.h", "-enable-bridging-pch",
1450+
"-output-file-map", outputFileMap.description])
1451+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
1452+
XCTAssertTrue(driver.diagnosticEngine.diagnostics.isEmpty)
1453+
1454+
// Test the output path is correct for GeneratePCH job.
1455+
XCTAssertEqual(plannedJobs.count, 4)
1456+
XCTAssertEqual(plannedJobs[0].kind, .generatePCH)
1457+
try XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-o"), .path(.absolute(.init(validating: "/build/Foo-bridging-header.pch"))))
1458+
1459+
// Plan a build with no bridging header and make sure no diagnostics is emitted (pch in output file map is still accepted)
1460+
driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Foo", "-emit-module",
1461+
"-serialize-diagnostics", "-experimental-emit-module-separately",
1462+
"-output-file-map", outputFileMap.description])
1463+
let _ = try driver.planBuild()
1464+
XCTAssertTrue(driver.diagnosticEngine.diagnostics.isEmpty)
1465+
}
1466+
}
1467+
14361468
func testReferenceDependencies() throws {
14371469
var driver = try Driver(args: ["swiftc", "foo.swift", "-incremental"])
14381470
let plannedJobs = try driver.planBuild()

0 commit comments

Comments
 (0)