Skip to content

Commit 3a7f8bd

Browse files
authored
Merge pull request #708 from slavapestov/unavailable-enum-case-warning-5.5
Pass -warn-on-potentially-unavailable-enum-case frontend flag when building a module [5.5]
2 parents 1b03427 + 1b5abaf commit 3a7f8bd

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,20 @@ public struct Driver {
329329
.appending(component: "Frameworks")
330330
} ()
331331

332+
public func isFrontendArgSupported(_ opt: Option) -> Bool {
333+
var current = opt.spelling
334+
while(true) {
335+
if supportedFrontendFlags.contains(current) {
336+
return true
337+
}
338+
if current.starts(with: "-") {
339+
current = String(current.dropFirst())
340+
} else {
341+
return false
342+
}
343+
}
344+
}
345+
332346
/// Handler for emitting diagnostics to stderr.
333347
public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in
334348
stdErrQueue.sync {

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ extension Driver {
8585
commandLine.appendFlag("-aarch64-use-tbi")
8686
}
8787

88+
// Potentially unavailable enum cases are downgraded to a warning when building a
89+
// swiftmodule, to allow building a module (or module interface) for an older
90+
// deployment target than the framework itself.
91+
if isFrontendArgSupported(.warnOnPotentiallyUnavailableEnumCase) {
92+
if compilerOutputType == .swiftModule {
93+
commandLine.appendFlag(.warnOnPotentiallyUnavailableEnumCase)
94+
}
95+
}
96+
8897
// Enable or disable ObjC interop appropriately for the platform
8998
if targetTriple.isDarwin {
9099
commandLine.appendFlag(.enableObjcInterop)

Sources/SwiftOptions/Options.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ extension Option {
510510
public static let warnLongExpressionTypeChecking: Option = Option("-warn-long-expression-type-checking", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<n>", helpText: "Warns when type-checking a function takes longer than <n> ms")
511511
public static let warnLongFunctionBodiesEQ: Option = Option("-warn-long-function-bodies=", .joined, alias: Option.warnLongFunctionBodies, attributes: [.helpHidden, .frontend, .noDriver])
512512
public static let warnLongFunctionBodies: Option = Option("-warn-long-function-bodies", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<n>", helpText: "Warns when type-checking a function takes longer than <n> ms")
513+
public static let warnOnPotentiallyUnavailableEnumCase: Option = Option("-warn-on-potentially-unavailable-enum-case", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Downgrade potential unavailability of enum case to a warning")
513514
public static let warnSwift3ObjcInferenceComplete: Option = Option("-warn-swift3-objc-inference-complete", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Warn about deprecated @objc inference in Swift 3 for every declaration that will no longer be inferred as @objc in Swift 4")
514515
public static let warnSwift3ObjcInferenceMinimal: Option = Option("-warn-swift3-objc-inference-minimal", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Warn about deprecated @objc inference in Swift 3 based on direct uses of the Objective-C entrypoint")
515516
public static let warnSwift3ObjcInference: Option = Option("-warn-swift3-objc-inference", .flag, alias: Option.warnSwift3ObjcInferenceComplete, attributes: [.helpHidden, .frontend, .doesNotAffectIncrementalBuild])

0 commit comments

Comments
 (0)