Skip to content

Commit 165aa9a

Browse files
authored
Merge pull request #1129 from allevato/index-locals-flag
Add support for `-index-include-locals`.
2 parents 2bbf56b + 380b643 commit 165aa9a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ extension Driver {
345345
commandLine.appendFlag(.indexSystemModules)
346346
}
347347
try commandLine.appendLast(.indexIgnoreClangModules, from: &parsedOptions)
348+
try commandLine.appendLast(.indexIncludeLocals, from: &parsedOptions)
348349
}
349350

350351
if parsedOptions.contains(.debugInfoStoreInvocation) ||

Sources/SwiftOptions/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ extension Option {
412412
public static let indexIgnoreClangModules: Option = Option("-index-ignore-clang-modules", .flag, attributes: [.frontend], helpText: "Avoid indexing clang modules (pcms)")
413413
public static let indexIgnoreStdlib: Option = Option("-index-ignore-stdlib", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Avoid emitting index data for the standard library.")
414414
public static let indexIgnoreSystemModules: Option = Option("-index-ignore-system-modules", .flag, attributes: [.noInteractive], helpText: "Avoid indexing system modules")
415+
public static let indexIncludeLocals: Option = Option("-index-include-locals", .flag, attributes: [.frontend], helpText: "Include local definitions/references in the produced index data.")
415416
public static let indexStorePath: Option = Option("-index-store-path", .separate, attributes: [.frontend, .argumentIsPath], metaVar: "<path>", helpText: "Store indexing data to <path>")
416417
public static let indexSystemModules: Option = Option("-index-system-modules", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Emit index data for imported serialized swift system modules")
417418
public static let indexUnitOutputPathFilelist: Option = Option("-index-unit-output-path-filelist", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Specify index unit output paths in a file rather than on the command line")
@@ -1083,6 +1084,7 @@ extension Option {
10831084
Option.indexIgnoreClangModules,
10841085
Option.indexIgnoreStdlib,
10851086
Option.indexIgnoreSystemModules,
1087+
Option.indexIncludeLocals,
10861088
Option.indexStorePath,
10871089
Option.indexSystemModules,
10881090
Option.indexUnitOutputPathFilelist,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,23 @@ final class SwiftDriverTests: XCTestCase {
416416
}
417417
}
418418

419+
func testIndexIncludeLocals() throws {
420+
// Make sure `-index-include-locals` is only passed to the frontend when
421+
// requested, not by default.
422+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-index-store-path", "/tmp/idx") { driver in
423+
let jobs = try driver.planBuild()
424+
let commandLine = jobs[0].commandLine
425+
XCTAssertTrue(commandLine.contains(.flag("-index-store-path")))
426+
XCTAssertFalse(commandLine.contains(.flag("-index-include-locals")))
427+
}
428+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-index-store-path", "/tmp/idx", "-index-include-locals") { driver in
429+
let jobs = try driver.planBuild()
430+
let commandLine = jobs[0].commandLine
431+
XCTAssertTrue(commandLine.contains(.flag("-index-store-path")))
432+
XCTAssertTrue(commandLine.contains(.flag("-index-include-locals")))
433+
}
434+
}
435+
419436
func testMultiThreadingOutputs() throws {
420437
try assertDriverDiagnostics(args: "swiftc", "-c", "foo.swift", "bar.swift", "-o", "bar.ll", "-o", "foo.ll", "-num-threads", "2", "-whole-module-optimization") {
421438
$1.expect(.error("cannot specify -o when generating multiple output files"))

0 commit comments

Comments
 (0)