pw_build, pw_toolchain: Add default configs

This CL reworks toolchains to be defined as scopes composing configs and
toolchain args. This allows individual targets to add configs to or
remove configs from the defaults.

Change-Id: I105a231f3e2de35499e1617241f3eeb42ef3248d
diff --git a/pw_build/defaults.gni b/pw_build/defaults.gni
new file mode 100644
index 0000000..2b20cc2
--- /dev/null
+++ b/pw_build/defaults.gni
@@ -0,0 +1,59 @@
+# Copyright 2020 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+# Importing this file provides the $pw_build_defaults scope.
+# This includes target-agnostic default variables. It may also includes
+# target-specific default variables if $pw_target_toolchain or
+# $pw_target_defaults is set (and recognized).
+
+import("$dir_pigweed/modules.gni")
+
+declare_args() {
+  # Default configs and dependencies targets provided by the toolchain. These
+  # are applied to all of the pw_* target types. They are set from a toolchain's
+  # toolchain_args for cross-toolchain deps, e.g. for
+  #
+  #   `deps = [ //pw_some_module(//pw_toolchain:not_default) ]`
+  #
+  # The default toolchain is never used.
+  default_configs = []
+  default_public_deps = []
+}
+
+# Combine target-specifc and target-agnostic default variables.
+_pw_build_defaults = {
+  configs = default_configs
+  public_deps = default_public_deps
+
+  # The target-agnostic defaults.
+  configs += [
+    "$dir_pw_build:colorize_output",
+    "$dir_pw_build:debugging",
+    "$dir_pw_build:reduced_size",
+    "$dir_pw_build:strict_warnings",
+    "$dir_pw_build:cpp17",
+  ]
+  public_deps = [ "$dir_pw_polyfill:overrides" ]
+}
+
+# One more pass, to remove configs
+pw_build_defaults = {
+  configs = []
+  forward_variables_from(_pw_build_defaults, "*", [ "remove_configs" ])
+  if (defined(_pw_build_defaults.remove_configs)) {
+    # Add them first to ensure they are present to be removed.
+    configs += _pw_build_defaults.remove_configs
+    configs -= _pw_build_defaults.remove_configs
+  }
+}