Skip to content

Commit 750ede6

Browse files
committed
Indexing: include index file entry in supplementary output file map
This is the behavior of the C++ driver and we should preserve it. rdar://74127445
1 parent c94bd6f commit 750ede6

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ extension Driver {
226226
primaryInputs: primaryInputs,
227227
inputsGeneratingCodeCount: inputsGeneratingCodeCount,
228228
inputOutputMap: inputOutputMap,
229-
includeModuleTracePath: emitModuleTrace)
229+
includeModuleTracePath: emitModuleTrace,
230+
indexFilePath: indexFilePath)
230231

231232
// Forward migrator flags.
232233
try commandLine.appendLast(.apiDiffDataFile, from: &parsedOptions)

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ extension Driver {
250250
primaryInputs: [TypedVirtualPath],
251251
inputsGeneratingCodeCount: Int,
252252
inputOutputMap: [TypedVirtualPath: TypedVirtualPath],
253-
includeModuleTracePath: Bool) throws -> [TypedVirtualPath] {
253+
includeModuleTracePath: Bool,
254+
indexFilePath: TypedVirtualPath?) throws -> [TypedVirtualPath] {
254255
var flaggedInputOutputPairs: [(flag: String, input: TypedVirtualPath?, output: TypedVirtualPath)] = []
255256

256257
/// Add output of a particular type, if needed.
@@ -417,6 +418,11 @@ extension Driver {
417418
for flaggedPair in flaggedInputOutputPairs {
418419
addEntry(&entries, input: flaggedPair.input, output: flaggedPair.output)
419420
}
421+
// To match the legacy driver behavior, make sure we add an entry for the
422+
// file under indexing and the primary output file path.
423+
if let indexFilePath = indexFilePath, let idxOutput = inputOutputMap[indexFilePath] {
424+
entries[indexFilePath.file] = [.indexData: idxOutput.file]
425+
}
420426
let outputFileMap = OutputFileMap(entries: entries)
421427
let path = RelativePath(createTemporaryFileName(prefix: "supplementaryOutputs"))
422428
commandLine.appendFlag(.supplementaryOutputFileMap)

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,52 @@ final class SwiftDriverTests: XCTestCase {
15141514
XCTAssertEqual(plannedJobs[1].kind, .link)
15151515
}
15161516

1517+
1518+
func testIndexFileEntryInSupplementaryFileOutputMap() throws {
1519+
var driver1 = try Driver(args: [
1520+
"swiftc", "foo1.swift", "foo2.swift", "foo3.swift", "foo4.swift", "foo5.swift",
1521+
"-index-file", "-index-file-path", "foo5.swift", "-o", "/tmp/t.o",
1522+
"-index-store-path", "/tmp/idx"
1523+
])
1524+
let plannedJobs = try driver1.planBuild().removingAutolinkExtractJobs()
1525+
XCTAssertEqual(plannedJobs.count, 1)
1526+
let suppleArg = "-supplementary-output-file-map"
1527+
// Make sure we are using supplementary file map
1528+
XCTAssert(plannedJobs[0].commandLine.contains(.flag(suppleArg)))
1529+
let args = plannedJobs[0].commandLine
1530+
var fileMapPath: VirtualPath?
1531+
for pair in args.enumerated() {
1532+
if pair.element == .flag(suppleArg) {
1533+
let filemap = args[pair.offset + 1]
1534+
switch filemap {
1535+
case .path(let p):
1536+
fileMapPath = p
1537+
default:
1538+
break
1539+
}
1540+
}
1541+
}
1542+
XCTAssert(fileMapPath != nil)
1543+
switch fileMapPath! {
1544+
case .fileList(_, let list):
1545+
switch list {
1546+
case .outputFileMap(let map):
1547+
// This is to match the legacy driver behavior
1548+
// Make sure the supplementary output map has an entry for the Swift file
1549+
// under indexing and its indexData entry is the primary output file
1550+
let entry = map.entries[VirtualPath.relative(RelativePath("foo5.swift"))]!
1551+
XCTAssert(entry[.indexData]! == .absolute(AbsolutePath("/tmp/t.o")))
1552+
return
1553+
default:
1554+
break
1555+
}
1556+
break
1557+
default:
1558+
break
1559+
}
1560+
XCTAssert(false)
1561+
}
1562+
15171563
func testMultiThreadedWholeModuleOptimizationCompiles() throws {
15181564
do {
15191565
var driver1 = try Driver(args: [

0 commit comments

Comments
 (0)