pw_buid: remove_configs pattern support

Add support for specifying a list of patterns for a target's
remove_configs arg. In addition to absolute names, patterns with
wild-card matching can be passed in.

Fixed: b/266554449
Change-Id: I148b4709a0672f5cc01a1085bfe247ba30837be8
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/126850
Commit-Queue: Shaun Carnegie <shauncarnegie@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_build/cc_executable.gni b/pw_build/cc_executable.gni
index 1f626e6..081f647 100644
--- a/pw_build/cc_executable.gni
+++ b/pw_build/cc_executable.gni
@@ -55,8 +55,9 @@
 # In addition to the arguments supported by a native executable target, this
 # template introduces the following arguments:
 #
-#  remove_configs: (optional) A list of configs to remove from the set of
-#    default configs specified by the current toolchain configuration.
+#  remove_configs: (optional) A list of configs / config patterns to remove from
+#    the set of default configs specified by the current toolchain
+#    configuration.
 #  remove_public_deps: (optional) A list of targets to remove from the set of
 #    default public_deps specified by the current toolchain configuration.
 
diff --git a/pw_build/docs.rst b/pw_build/docs.rst
index 48325b2..d1cea80 100644
--- a/pw_build/docs.rst
+++ b/pw_build/docs.rst
@@ -158,8 +158,9 @@
 
 Additionally, the following arguments are also supported:
 
-* **remove_configs**: (optional) A list of configs to remove from the set of
-  default configs specified by the current toolchain configuration.
+* **remove_configs**: (optional) A list of configs / config patterns to remove
+  from the set of default configs specified by the current toolchain
+  configuration.
 * **remove_public_deps**: (optional) A list of targets to remove from the set of
   default public_deps specified by the current toolchain configuration.
 
diff --git a/pw_build/gn_internal/c_language_build_target.gni b/pw_build/gn_internal/c_language_build_target.gni
index 5c08901..40f0141 100644
--- a/pw_build/gn_internal/c_language_build_target.gni
+++ b/pw_build/gn_internal/c_language_build_target.gni
@@ -106,8 +106,7 @@
       if (remove_configs != [] && remove_configs[0] == "*") {
         configs = []
       } else {
-        configs += remove_configs  # Add configs in case they aren't already
-        configs -= remove_configs  # present, then remove them.
+        configs -= filter_include(configs, remove_configs)
       }
     }
     if (defined(invoker.configs)) {