Skip to content

Commit 75d4a30

Browse files
authored
Merge pull request #239 from owenv/warn-nused-opts
Add a -driver-warn-unused-options flag for debugging
2 parents db02120 + 425475e commit 75d4a30

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,12 @@ extension Driver {
638638
}
639639
}
640640

641+
extension Diagnostic.Message {
642+
static func warn_unused_option(_ option: ParsedOption) -> Diagnostic.Message {
643+
.warning("Unused option: \(option)")
644+
}
645+
}
646+
641647
extension Driver {
642648
/// Determine the driver kind based on the command-line arguments, consuming the arguments
643649
/// conveying this information.
@@ -719,6 +725,13 @@ extension Driver {
719725
numParallelJobs: numParallelJobs ?? 1,
720726
forceResponseFiles: forceResponseFiles,
721727
recordedInputModificationDates: recordedInputModificationDates)
728+
729+
// If requested, warn for options that weren't used by the driver after the build is finished.
730+
if parsedOptions.hasArgument(.driverWarnUnusedOptions) {
731+
for option in parsedOptions.unconsumedOptions {
732+
diagnosticEngine.emit(.warn_unused_option(option))
733+
}
734+
}
722735
}
723736

724737
public mutating func createToolExecutionDelegate() -> ToolExecutionDelegate {

Sources/SwiftOptions/ExtraOptions.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ extension Option {
1313
public static let driverPrintGraphviz: Option = Option("-driver-print-graphviz", .flag, attributes: [.helpHidden, .doesNotAffectIncrementalBuild], helpText: "Write the job graph as a graphviz file", group: .internalDebug)
1414
public static let driverExplicitModuleBuild: Option = Option("-experimental-explicit-module-build", .flag, attributes: [.helpHidden], helpText: "Prebuild module dependencies to make them explicit")
1515
public static let driverPrintModuleDependenciesJobs: Option = Option("-driver-print-module-dependencies-jobs", .flag, attributes: [.helpHidden], helpText: "Print commands to explicitly build module dependencies")
16+
public static let driverWarnUnusedOptions: Option = Option("-driver-warn-unused-options", .flag, attributes: [.helpHidden], helpText: "Emit warnings for any provided options which are unused by the driver.")
1617

1718
public static var extraOptions: [Option] {
1819
return [
1920
Option.driverPrintGraphviz,
2021
Option.driverExplicitModuleBuild,
21-
Option.driverPrintModuleDependenciesJobs
22+
Option.driverPrintModuleDependenciesJobs,
23+
Option.driverWarnUnusedOptions
2224
]
2325
}
2426
}

Sources/SwiftOptions/ParsedOptions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,8 @@ extension ParsedOptions {
318318
groupIndex[group]?.removeAll { $0.option == option }
319319
}
320320
}
321+
322+
public var unconsumedOptions: [ParsedOption] {
323+
zip(parsedOptions, consumed).filter { !$0.1 }.map(\.0)
324+
}
321325
}

0 commit comments

Comments
 (0)