From 3168b15a9b2b0a961fdff2f89129c679aa3d94f1 Mon Sep 17 00:00:00 2001 From: Chaitanya Kumar Date: Fri, 26 Sep 2025 21:35:00 +0200 Subject: [PATCH 1/2] fix: remove preceding `-Xcc` instead of the argument following `-Werror` or `-Wwarning` https://github.com/swiftlang/swift-package-manager/issues/9192 --- .../Build/BuildDescription/SwiftModuleBuildDescription.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift b/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift index b6b6c20fffa..6e7e2283158 100644 --- a/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift +++ b/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift @@ -612,7 +612,7 @@ public final class SwiftModuleBuildDescription { if self.package.isRemote { // suppress-warnings and the other warning control flags are mutually exclusive var removeNextArg = false - args = args.filter { arg in + args = Array(args.lazy.reversed().filter { arg in if removeNextArg { removeNextArg = false return false @@ -626,7 +626,7 @@ public final class SwiftModuleBuildDescription { default: return true } - } + }.reversed()) guard !removeNextArg else { throw InternalError("Unexpected '-Wwarning' or '-Werror' at the end of args") } From 91f258748af95167eb3cf351d842d0419309ffcc Mon Sep 17 00:00:00 2001 From: Chaitanya Kumar Date: Mon, 29 Sep 2025 22:46:33 +0200 Subject: [PATCH 2/2] refactor: use simple for loop instead of filter with side-effect closure --- .../SwiftModuleBuildDescription.swift | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift b/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift index 6e7e2283158..8e227186daf 100644 --- a/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift +++ b/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift @@ -611,26 +611,21 @@ public final class SwiftModuleBuildDescription { // suppress warnings if the package is remote if self.package.isRemote { // suppress-warnings and the other warning control flags are mutually exclusive - var removeNextArg = false - args = Array(args.lazy.reversed().filter { arg in - if removeNextArg { - removeNextArg = false - return false - } + var filteredArgs = [String]() + for arg in args { switch arg { case "-warnings-as-errors", "-no-warnings-as-errors": - return false + // Skip this flag + continue case "-Wwarning", "-Werror": - removeNextArg = true - return false + // Remove preceding -Xcc and skip this flag + filteredArgs.removeLast() default: - return true + filteredArgs.append(arg) } - }.reversed()) - guard !removeNextArg else { - throw InternalError("Unexpected '-Wwarning' or '-Werror' at the end of args") } - args += ["-suppress-warnings"] + args = filteredArgs + args.append("-suppress-warnings") } // Pass `-user-module-version` for versioned packages that aren't pre-releases.