Skip to content

Commit c86e00d

Browse files
authored
Merge pull request #478 from nkcsgexi/74127445
Indexing: include index file entry in supplementary output file map
2 parents bad60da + 750ede6 commit c86e00d

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
@@ -1540,6 +1540,52 @@ final class SwiftDriverTests: XCTestCase {
15401540
XCTAssertEqual(plannedJobs[1].kind, .link)
15411541
}
15421542

1543+
1544+
func testIndexFileEntryInSupplementaryFileOutputMap() throws {
1545+
var driver1 = try Driver(args: [
1546+
"swiftc", "foo1.swift", "foo2.swift", "foo3.swift", "foo4.swift", "foo5.swift",
1547+
"-index-file", "-index-file-path", "foo5.swift", "-o", "/tmp/t.o",
1548+
"-index-store-path", "/tmp/idx"
1549+
])
1550+
let plannedJobs = try driver1.planBuild().removingAutolinkExtractJobs()
1551+
XCTAssertEqual(plannedJobs.count, 1)
1552+
let suppleArg = "-supplementary-output-file-map"
1553+
// Make sure we are using supplementary file map
1554+
XCTAssert(plannedJobs[0].commandLine.contains(.flag(suppleArg)))
1555+
let args = plannedJobs[0].commandLine
1556+
var fileMapPath: VirtualPath?
1557+
for pair in args.enumerated() {
1558+
if pair.element == .flag(suppleArg) {
1559+
let filemap = args[pair.offset + 1]
1560+
switch filemap {
1561+
case .path(let p):
1562+
fileMapPath = p
1563+
default:
1564+
break
1565+
}
1566+
}
1567+
}
1568+
XCTAssert(fileMapPath != nil)
1569+
switch fileMapPath! {
1570+
case .fileList(_, let list):
1571+
switch list {
1572+
case .outputFileMap(let map):
1573+
// This is to match the legacy driver behavior
1574+
// Make sure the supplementary output map has an entry for the Swift file
1575+
// under indexing and its indexData entry is the primary output file
1576+
let entry = map.entries[VirtualPath.relative(RelativePath("foo5.swift"))]!
1577+
XCTAssert(entry[.indexData]! == .absolute(AbsolutePath("/tmp/t.o")))
1578+
return
1579+
default:
1580+
break
1581+
}
1582+
break
1583+
default:
1584+
break
1585+
}
1586+
XCTAssert(false)
1587+
}
1588+
15431589
func testMultiThreadedWholeModuleOptimizationCompiles() throws {
15441590
do {
15451591
var driver1 = try Driver(args: [

0 commit comments

Comments
 (0)