Skip to content

Commit dcdcab3

Browse files
committed
Fix warning flags filter complexity
1 parent 615d9d4 commit dcdcab3

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

Sources/Build/BuildDescription/ClangModuleBuildDescription.swift

+10-13
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,18 @@ public final class ClangModuleBuildDescription {
363363

364364
// suppress warnings if the package is remote
365365
if self.package.isRemote {
366-
args += ["-w"]
367366
// `-w` (suppress warnings) and the other warning control flags are mutually exclusive
368-
for index in args.indices.reversed() {
369-
let arg = args[index]
370-
if arg.starts(with: "-W"), arg.count > 2 {
371-
// we consider the following flags:
372-
// -Wxxxx
373-
// -Wno-xxxx
374-
// -Werror
375-
// -Werror=xxxx
376-
// -Wno-error
377-
// -Wno-error=xxxx
378-
args.remove(at: index)
379-
}
367+
args = args.filter { arg in
368+
// we consider the following flags:
369+
// -Wxxxx
370+
// -Wno-xxxx
371+
// -Werror
372+
// -Werror=xxxx
373+
// -Wno-error
374+
// -Wno-error=xxxx
375+
arg.count <= 2 || !arg.starts(with: "-W")
380376
}
377+
args += ["-w"]
381378
}
382379

383380
return args

Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift

+14-10
Original file line numberDiff line numberDiff line change
@@ -621,23 +621,27 @@ public final class SwiftModuleBuildDescription {
621621

622622
// suppress warnings if the package is remote
623623
if self.package.isRemote {
624-
args += ["-suppress-warnings"]
625624
// suppress-warnings and the other warning control flags are mutually exclusive
626-
for index in args.indices.reversed() {
627-
let arg = args[index]
625+
var removeNextArg = false
626+
args = args.filter { arg in
627+
if removeNextArg {
628+
removeNextArg = false
629+
return false
630+
}
628631
switch arg {
629632
case "-warnings-as-errors", "-no-warnings-as-errors":
630-
args.remove(at: index)
633+
return false
631634
case "-Wwarning", "-Werror":
632-
guard args.indices.contains(index + 1) else {
633-
throw InternalError("Unexpected '\(arg)' at the end of args")
634-
}
635-
args.remove(at: index + 1)
636-
args.remove(at: index)
635+
removeNextArg = true
636+
return false
637637
default:
638-
break
638+
return true
639639
}
640640
}
641+
guard !removeNextArg else {
642+
throw InternalError("Unexpected '-Wwarning' or '-Werror' at the end of args")
643+
}
644+
args += ["-suppress-warnings"]
641645
}
642646

643647
// Pass `-user-module-version` for versioned packages that aren't pre-releases.

0 commit comments

Comments
 (0)