Don't declare pigweed variables as globals

Require targets to explicitly import pigweed variable definitions. This
moves out some necessary logic from the BUILDCONFIG.gn file.

Change-Id: If9c9fe5a680cc9d897a0e8a55889873be618ed84
diff --git a/BUILD.gn b/BUILD.gn
index ab3b21a..f469597 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_unit_test/test.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_unit_test/test.gni")
 group("default") {
   deps = [ ":pigweed_default($pw_target_toolchain)" ]
 }
@@ -28,7 +31,8 @@
       # Without a test runner defined, build the tests but don't run them.
       deps += [ ":pw_module_tests" ]
     } else {
-      # With a test runner, depend on the run targets so they run with the build.
+      # With a test runner, depend on the run targets so they run with the
+      # build.
       deps += [ ":pw_module_tests_run" ]
     }
   }
diff --git a/BUILDCONFIG.gn b/BUILDCONFIG.gn
index 306ce8c..42640b0 100644
--- a/BUILDCONFIG.gn
+++ b/BUILDCONFIG.gn
@@ -21,35 +21,25 @@
 # alphabetically sort imports unless they're separated by comments. For this
 # file, import order matters (modules.gni MUST be imported first).
 
-declare_args() {
-  # Location of the Pigweed modules directory (defaults to the directory of
-  # this file). When copying this buildconfig into a new project, this should
-  # be modified to point to the location of the Pigweed repository.
-  dir_pigweed = get_path_info(get_path_info("BUILDCONFIG.gn", "abspath"), "dir")
-
-  # Path to the Pigweed variables config file for the build target.
-  #
-  # When this is changed, you must run `ninja -t clean` to remove any files from
-  # the previous target's build before building again.
-  pw_target_config = "$dir_pigweed/targets/host/target_config.gni"
+# This is imported into a scope so as not to pollute the global variable space.
+_pigweed_directory = {
+  import("//build_overrides/pigweed.gni")
 }
 
-# Import variables that provide paths to modules. Pigweed's GN build requires
-# that this file is imported, and it MUST be imported before any other Pigweed
-# .gni files (as they depend on the dir_[module] variables).
-import("$dir_pigweed/modules.gni")
-
-# Import target configuration. This is what "completes" a Pigweed configuration.
-# This file should set a default toolchain, configure pw_executable, select
-# backends to build against, and provide target-specific build arguments.
-import(pw_target_config)
+_pigweed_modules = {
+  # Import target configuration. This is what "completes" a Pigweed
+  # configuration. This file should set a default toolchain, configure
+  # pw_executable, select backends to build against, and provide target-specific
+  # build arguments.
+  import("${_pigweed_directory.dir_pigweed}/legacy_target.gni")
+}
 
 # Ensure some sort of default toolchain was provided by the target, and then
 # set the default toolchain.
-assert(pw_target_toolchain != "",
+assert(_pigweed_modules.pw_target_toolchain != "",
        "Build target must provide its own toolchain.")
 
 # The default toolchain is not used in Pigweed builds, so it is set to a dummy
 # toolchain. The top-level BUILD.gn should stamp a group with all of the build
 # targets and their toolchains.
-set_default_toolchain("$dir_pw_toolchain/dummy")
+set_default_toolchain("${_pigweed_modules.dir_pw_toolchain}/dummy")
diff --git a/build_overrides/pigweed.gni b/build_overrides/pigweed.gni
new file mode 100644
index 0000000..2c05787
--- /dev/null
+++ b/build_overrides/pigweed.gni
@@ -0,0 +1,20 @@
+# 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.
+
+declare_args() {
+  # Location of the Pigweed repository.
+  dir_pigweed = "//"
+}
+
+import("$dir_pigweed/modules.gni")
diff --git a/docs/BUILD.gn b/docs/BUILD.gn
index a5ce2bb..d89dc6c 100644
--- a/docs/BUILD.gn
+++ b/docs/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("core_docs") {
   inputs = [
     "images/pw_env_setup_demo.gif",
diff --git a/legacy_target.gni b/legacy_target.gni
new file mode 100644
index 0000000..7347af6
--- /dev/null
+++ b/legacy_target.gni
@@ -0,0 +1,29 @@
+# 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.
+
+import("//build_overrides/pigweed.gni")
+
+# This file uses the old method of declaring targets via global defines in a
+# .gni file. We're transitioning to declaring all target config options as
+# individual build args that toolchains can manage.
+
+declare_args() {
+  # Path to the Pigweed variables config file for the build target.
+  #
+  # When this is changed, you must run `ninja -t clean` to remove any files from
+  # the previous target's build before building again.
+  pw_target_config = "$dir_pigweed/targets/host/target_config.gni"
+}
+
+import(pw_target_config)
diff --git a/modules.gni b/modules.gni
index 48b7338..338d5fe 100644
--- a/modules.gni
+++ b/modules.gni
@@ -12,54 +12,57 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-# This file defines a directory variable for each of Pigweed's modules. This
-# allows modules to be moved or swapped out without breaking existing builds.
-# All module variables are prefixed with dir_.
-
-dir_pw_allocator = "$dir_pigweed/pw_allocator"
-dir_pw_assert = "$dir_pigweed/pw_assert"
-dir_pw_assert_basic = "$dir_pigweed/pw_assert_basic"
-dir_pw_base64 = "$dir_pigweed/pw_base64"
-dir_pw_bloat = "$dir_pigweed/pw_bloat"
-dir_pw_boot_armv7m = "$dir_pigweed/pw_boot_armv7m"
-dir_pw_build = "$dir_pigweed/pw_build"
-dir_pw_checksum = "$dir_pigweed/pw_checksum"
-dir_pw_cli = "$dir_pigweed/pw_cli"
-dir_pw_containers = "$dir_pigweed/pw_containers"
-dir_pw_cpu_exception = "$dir_pigweed/pw_cpu_exception"
-dir_pw_cpu_exception_armv7m = "$dir_pigweed/pw_cpu_exception_armv7m"
-dir_pw_docgen = "$dir_pigweed/pw_docgen"
-dir_pw_doctor = "$dir_pigweed/pw_doctor"
-dir_pw_env_setup = "$dir_pigweed/pw_env_setup"
-dir_pw_kvs = "$dir_pigweed/pw_kvs"
-dir_pw_log = "$dir_pigweed/pw_log"
-dir_pw_log_basic = "$dir_pigweed/pw_log_basic"
-dir_pw_log_tokenized = "$dir_pigweed/pw_log_tokenized"
-dir_pw_minimal_cpp_stdlib = "$dir_pigweed/pw_minimal_cpp_stdlib"
-dir_pw_module = "$dir_pigweed/pw_module"
-dir_pw_fuzzer = "$dir_pigweed/pw_fuzzer"
-dir_pw_polyfill = "$dir_pigweed/pw_polyfill"
-dir_pw_preprocessor = "$dir_pigweed/pw_preprocessor"
-dir_pw_presubmit = "$dir_pigweed/pw_presubmit"
-dir_pw_protobuf = "$dir_pigweed/pw_protobuf"
-dir_pw_protobuf_compiler = "$dir_pigweed/pw_protobuf_compiler"
-dir_pw_result = "$dir_pigweed/pw_result"
-dir_pw_ring_buffer = "$dir_pigweed/pw_ring_buffer"
-dir_pw_rpc = "$dir_pigweed/pw_rpc"
-dir_pw_span = "$dir_pigweed/pw_span"
-dir_pw_status = "$dir_pigweed/pw_status"
-dir_pw_stream = "$dir_pigweed/pw_stream"
-dir_pw_string = "$dir_pigweed/pw_string"
-dir_pw_sys_io = "$dir_pigweed/pw_sys_io"
-dir_pw_sys_io_baremetal_lm3s6965evb =
-    "$dir_pigweed/pw_sys_io_baremetal_lm3s6965evb"
-dir_pw_sys_io_baremetal_stm32f429 = "$dir_pigweed/pw_sys_io_baremetal_stm32f429"
-dir_pw_sys_io_stdio = "$dir_pigweed/pw_sys_io_stdio"
-dir_pw_target_runner = "$dir_pigweed/pw_target_runner"
-dir_pw_tokenizer = "$dir_pigweed/pw_tokenizer"
-dir_pw_toolchain = "$dir_pigweed/pw_toolchain"
-dir_pw_trace = "$dir_pigweed/pw_trace"
-dir_pw_unit_test = "$dir_pigweed/pw_unit_test"
-dir_pw_varint = "$dir_pigweed/pw_varint"
-dir_pw_watch = "$dir_pigweed/pw_watch"
-dir_pw_web_ui = "$dir_pigweed/pw_web_ui"
+declare_args() {
+  # This file defines a directory variable for each of Pigweed's modules. This
+  # allows modules to be moved or swapped out without breaking existing builds.
+  # All module variables are prefixed with dir_.
+  dir_pw_allocator = get_path_info("pw_allocator", "abspath")
+  dir_pw_assert = get_path_info("pw_assert", "abspath")
+  dir_pw_assert_basic = get_path_info("pw_assert_basic", "abspath")
+  dir_pw_base64 = get_path_info("pw_base64", "abspath")
+  dir_pw_bloat = get_path_info("pw_bloat", "abspath")
+  dir_pw_boot_armv7m = get_path_info("pw_boot_armv7m", "abspath")
+  dir_pw_build = get_path_info("pw_build", "abspath")
+  dir_pw_checksum = get_path_info("pw_checksum", "abspath")
+  dir_pw_cli = get_path_info("pw_cli", "abspath")
+  dir_pw_containers = get_path_info("pw_containers", "abspath")
+  dir_pw_cpu_exception = get_path_info("pw_cpu_exception", "abspath")
+  dir_pw_cpu_exception_armv7m =
+      get_path_info("pw_cpu_exception_armv7m", "abspath")
+  dir_pw_docgen = get_path_info("pw_docgen", "abspath")
+  dir_pw_doctor = get_path_info("pw_doctor", "abspath")
+  dir_pw_env_setup = get_path_info("pw_env_setup", "abspath")
+  dir_pw_kvs = get_path_info("pw_kvs", "abspath")
+  dir_pw_log = get_path_info("pw_log", "abspath")
+  dir_pw_log_basic = get_path_info("pw_log_basic", "abspath")
+  dir_pw_log_tokenized = get_path_info("pw_log_tokenized", "abspath")
+  dir_pw_minimal_cpp_stdlib = get_path_info("pw_minimal_cpp_stdlib", "abspath")
+  dir_pw_module = get_path_info("pw_module", "abspath")
+  dir_pw_fuzzer = get_path_info("pw_fuzzer", "abspath")
+  dir_pw_polyfill = get_path_info("pw_polyfill", "abspath")
+  dir_pw_preprocessor = get_path_info("pw_preprocessor", "abspath")
+  dir_pw_presubmit = get_path_info("pw_presubmit", "abspath")
+  dir_pw_protobuf = get_path_info("pw_protobuf", "abspath")
+  dir_pw_protobuf_compiler = get_path_info("pw_protobuf_compiler", "abspath")
+  dir_pw_result = get_path_info("pw_result", "abspath")
+  dir_pw_ring_buffer = get_path_info("pw_ring_buffer", "abspath")
+  dir_pw_rpc = get_path_info("pw_rpc", "abspath")
+  dir_pw_span = get_path_info("pw_span", "abspath")
+  dir_pw_status = get_path_info("pw_status", "abspath")
+  dir_pw_stream = get_path_info("pw_stream", "abspath")
+  dir_pw_string = get_path_info("pw_string", "abspath")
+  dir_pw_sys_io = get_path_info("pw_sys_io", "abspath")
+  dir_pw_sys_io_baremetal_lm3s6965evb =
+      get_path_info("pw_sys_io_baremetal_lm3s6965evb", "abspath")
+  dir_pw_sys_io_baremetal_stm32f429 =
+      get_path_info("pw_sys_io_baremetal_stm32f429", "abspath")
+  dir_pw_sys_io_stdio = get_path_info("pw_sys_io_stdio", "abspath")
+  dir_pw_target_runner = get_path_info("pw_target_runner", "abspath")
+  dir_pw_tokenizer = get_path_info("pw_tokenizer", "abspath")
+  dir_pw_toolchain = get_path_info("pw_toolchain", "abspath")
+  dir_pw_trace = get_path_info("pw_trace", "abspath")
+  dir_pw_unit_test = get_path_info("pw_unit_test", "abspath")
+  dir_pw_varint = get_path_info("pw_varint", "abspath")
+  dir_pw_watch = get_path_info("pw_watch", "abspath")
+  dir_pw_web_ui = get_path_info("pw_web_ui", "abspath")
+}
diff --git a/pw_allocator/BUILD.gn b/pw_allocator/BUILD.gn
index 18be387..c826322 100644
--- a/pw_allocator/BUILD.gn
+++ b/pw_allocator/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_assert/BUILD.gn b/pw_assert/BUILD.gn
index ea05d38..db3c184 100644
--- a/pw_assert/BUILD.gn
+++ b/pw_assert/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/facade.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_assert_basic/BUILD.gn b/pw_assert_basic/BUILD.gn
index a77c2b9..311ab19 100644
--- a/pw_assert_basic/BUILD.gn
+++ b/pw_assert_basic/BUILD.gn
@@ -12,9 +12,12 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_base64/BUILD.gn b/pw_base64/BUILD.gn
index 3c9a909..b421afb 100644
--- a/pw_base64/BUILD.gn
+++ b/pw_base64/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_bloat/BUILD.gn b/pw_bloat/BUILD.gn
index 480aa3e..db76014 100644
--- a/pw_bloat/BUILD.gn
+++ b/pw_bloat/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("bloat.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_bloat/bloat.gni b/pw_bloat/bloat.gni
index b94e1d8..6443c3c 100644
--- a/pw_bloat/bloat.gni
+++ b/pw_bloat/bloat.gni
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/python_script.gni")
 
 # Creates a target which runs a size report diff on a set of executables.
diff --git a/pw_bloat/examples/BUILD.gn b/pw_bloat/examples/BUILD.gn
index 4b289ec..4d2c3d3 100644
--- a/pw_bloat/examples/BUILD.gn
+++ b/pw_bloat/examples/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("../bloat.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("../bloat.gni")
 pw_toolchain_size_report("simple_bloat_loop") {
   base_executable = {
     sources = [ "simple_base.cc" ]
diff --git a/pw_boot_armv7m/BUILD.gn b/pw_boot_armv7m/BUILD.gn
index 27a496d..01bbc1d 100644
--- a/pw_boot_armv7m/BUILD.gn
+++ b/pw_boot_armv7m/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/linker_script.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
-
 if (dir_pw_boot_backend == dir_pw_boot_armv7m) {
   config("default_config") {
     include_dirs = [ "public" ]
diff --git a/pw_build/BUILD.gn b/pw_build/BUILD.gn
index c2566d2..7e9ec54 100644
--- a/pw_build/BUILD.gn
+++ b/pw_build/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 config("colorize_output") {
   cflags = [
     # Colorize output. Ninja's Clang invocation disables color by default.
diff --git a/pw_build/defaults.gni b/pw_build/defaults.gni
index 2b20cc2..936015e 100644
--- a/pw_build/defaults.gni
+++ b/pw_build/defaults.gni
@@ -12,13 +12,10 @@
 # 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).
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
-import("$dir_pigweed/modules.gni")
-
+import("$dir_pigweed/legacy_target.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
diff --git a/pw_build/facade.gni b/pw_build/facade.gni
index 12a0fa0..06a77bf 100644
--- a/pw_build/facade.gni
+++ b/pw_build/facade.gni
@@ -11,7 +11,10 @@
 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 # License for the specific language governing permissions and limitations under
 # the License.
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/python_script.gni")
 import("$dir_pw_build/target_types.gni")
 
diff --git a/pw_build/linker_script.gni b/pw_build/linker_script.gni
index 4b208bf..3ab0527 100644
--- a/pw_build/linker_script.gni
+++ b/pw_build/linker_script.gni
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/exec.gni")
 import("$dir_pw_build/target_types.gni")
 
diff --git a/pw_build/python_script.gni b/pw_build/python_script.gni
index 7c9c932..1500cc4 100644
--- a/pw_build/python_script.gni
+++ b/pw_build/python_script.gni
@@ -12,6 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
+
 # Defines an action to run a Python script.
 #
 # This wraps a regular Python script action with an invocation of a script-
diff --git a/pw_build/target_types.gni b/pw_build/target_types.gni
index 9797763..98b6aca 100644
--- a/pw_build/target_types.gni
+++ b/pw_build/target_types.gni
@@ -12,6 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
+
 # TODO(frolv): The code in all of the templates below is duplicated, with the
 # exception of the target type. This file could be auto-generated with Python.
 
diff --git a/pw_checksum/BUILD.gn b/pw_checksum/BUILD.gn
index e17803b..b04494d 100644
--- a/pw_checksum/BUILD.gn
+++ b/pw_checksum/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_cli/BUILD.gn b/pw_cli/BUILD.gn
index 31d536d..956e5f7 100644
--- a/pw_cli/BUILD.gn
+++ b/pw_cli/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
 }
diff --git a/pw_containers/BUILD.gn b/pw_containers/BUILD.gn
index b1a3e49..09a9cb4 100644
--- a/pw_containers/BUILD.gn
+++ b/pw_containers/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_cpu_exception/BUILD.gn b/pw_cpu_exception/BUILD.gn
index bec142e..839c6f1 100644
--- a/pw_cpu_exception/BUILD.gn
+++ b/pw_cpu_exception/BUILD.gn
@@ -12,9 +12,12 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/facade.gni")
 import("$dir_pw_docgen/docs.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_cpu_exception_armv7m/BUILD.gn b/pw_cpu_exception_armv7m/BUILD.gn
index bf79bc0..7c45e0e 100644
--- a/pw_cpu_exception_armv7m/BUILD.gn
+++ b/pw_cpu_exception_armv7m/BUILD.gn
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
diff --git a/pw_docgen/BUILD.gn b/pw_docgen/BUILD.gn
index c93b7a8..2784482 100644
--- a/pw_docgen/BUILD.gn
+++ b/pw_docgen/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("docs.gni")
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
 }
diff --git a/pw_docgen/docs.gni b/pw_docgen/docs.gni
index ea6dc32..a840f47 100644
--- a/pw_docgen/docs.gni
+++ b/pw_docgen/docs.gni
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/input_group.gni")
 import("$dir_pw_build/python_script.gni")
 
diff --git a/pw_doctor/BUILD.gn b/pw_doctor/BUILD.gn
index 57493ab..c7e5cf3 100644
--- a/pw_doctor/BUILD.gn
+++ b/pw_doctor/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
 }
diff --git a/pw_env_setup/BUILD.gn b/pw_env_setup/BUILD.gn
index 31d536d..956e5f7 100644
--- a/pw_env_setup/BUILD.gn
+++ b/pw_env_setup/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
 }
diff --git a/pw_fuzzer/BUILD.gn b/pw_fuzzer/BUILD.gn
index 4db5247..4d8d4ec 100644
--- a/pw_fuzzer/BUILD.gn
+++ b/pw_fuzzer/BUILD.gn
@@ -12,11 +12,14 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_fuzzer/fuzzer.gni")
 import("$dir_pw_fuzzer/oss_fuzz.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_fuzzer/fuzzer.gni b/pw_fuzzer/fuzzer.gni
index 6ab0ddb..42dbed9 100644
--- a/pw_fuzzer/fuzzer.gni
+++ b/pw_fuzzer/fuzzer.gni
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_toolchain/host_clang/toolchains.gni")
 import("$dir_pw_unit_test/test.gni")
 
diff --git a/pw_kvs/BUILD.gn b/pw_kvs/BUILD.gn
index 3656384..df0020d 100644
--- a/pw_kvs/BUILD.gn
+++ b/pw_kvs/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_log/BUILD.gn b/pw_log/BUILD.gn
index 1e16612..10c5cd7 100644
--- a/pw_log/BUILD.gn
+++ b/pw_log/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/facade.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_log_basic/BUILD.gn b/pw_log_basic/BUILD.gn
index a4f3e52..e04bd5c 100644
--- a/pw_log_basic/BUILD.gn
+++ b/pw_log_basic/BUILD.gn
@@ -12,9 +12,12 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_log_tokenized/BUILD.gn b/pw_log_tokenized/BUILD.gn
index 325450f..b5b0acd 100644
--- a/pw_log_tokenized/BUILD.gn
+++ b/pw_log_tokenized/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_minimal_cpp_stdlib/BUILD.gn b/pw_minimal_cpp_stdlib/BUILD.gn
index 8e80e8f..eb4a97d 100644
--- a/pw_minimal_cpp_stdlib/BUILD.gn
+++ b/pw_minimal_cpp_stdlib/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("include_dirs") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_module/BUILD.gn b/pw_module/BUILD.gn
index 57493ab..c7e5cf3 100644
--- a/pw_module/BUILD.gn
+++ b/pw_module/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
 }
diff --git a/pw_polyfill/BUILD.gn b/pw_polyfill/BUILD.gn
index a9d6340..743c47c 100644
--- a/pw_polyfill/BUILD.gn
+++ b/pw_polyfill/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("public") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_preprocessor/BUILD.gn b/pw_preprocessor/BUILD.gn
index 8e5c1cc..6bf9dec 100644
--- a/pw_preprocessor/BUILD.gn
+++ b/pw_preprocessor/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_presubmit/BUILD.gn b/pw_presubmit/BUILD.gn
index 1875615..e655a38 100644
--- a/pw_presubmit/BUILD.gn
+++ b/pw_presubmit/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
   inputs = [
diff --git a/pw_protobuf/BUILD.gn b/pw_protobuf/BUILD.gn
index 1871afc..029203b 100644
--- a/pw_protobuf/BUILD.gn
+++ b/pw_protobuf/BUILD.gn
@@ -12,13 +12,16 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/input_group.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_fuzzer/fuzzer.gni")
 import("$dir_pw_protobuf_compiler/proto.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_protobuf/size_report/BUILD.gn b/pw_protobuf/size_report/BUILD.gn
index 4df99f6..1cf45b2 100644
--- a/pw_protobuf/size_report/BUILD.gn
+++ b/pw_protobuf/size_report/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_bloat/bloat.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_bloat/bloat.gni")
 _decoder_full = {
   deps = [
     "$dir_pw_bloat:bloat_this_binary",
diff --git a/pw_protobuf_compiler/BUILD.gn b/pw_protobuf_compiler/BUILD.gn
index b409546..e36c286 100644
--- a/pw_protobuf_compiler/BUILD.gn
+++ b/pw_protobuf_compiler/BUILD.gn
@@ -12,11 +12,14 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/input_group.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_protobuf_compiler/proto.gni")
 import("$dir_pw_unit_test/test.gni")
-
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
 }
diff --git a/pw_protobuf_compiler/proto.gni b/pw_protobuf_compiler/proto.gni
index 92b49d4..58ed4e7 100644
--- a/pw_protobuf_compiler/proto.gni
+++ b/pw_protobuf_compiler/proto.gni
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/input_group.gni")
 import("$dir_pw_build/python_script.gni")
 import("$dir_pw_build/target_types.gni")
diff --git a/pw_result/BUILD.gn b/pw_result/BUILD.gn
index c1b4370..c14c939 100644
--- a/pw_result/BUILD.gn
+++ b/pw_result/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_ring_buffer/BUILD.gn b/pw_ring_buffer/BUILD.gn
index 26cb89f..037bc2e 100644
--- a/pw_ring_buffer/BUILD.gn
+++ b/pw_ring_buffer/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_rpc/BUILD.gn b/pw_rpc/BUILD.gn
index 404429c..cc65316 100644
--- a/pw_rpc/BUILD.gn
+++ b/pw_rpc/BUILD.gn
@@ -12,11 +12,14 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_protobuf_compiler/proto.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
   visibility = [ ":*" ]
diff --git a/pw_rpc/nanopb/BUILD.gn b/pw_rpc/nanopb/BUILD.gn
index 998fd4e..5c02676 100644
--- a/pw_rpc/nanopb/BUILD.gn
+++ b/pw_rpc/nanopb/BUILD.gn
@@ -12,9 +12,12 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("config") {
   include_dirs = [ "public_overrides" ]
   visibility = [ ":*" ]
diff --git a/pw_rpc/test_impl/BUILD.gn b/pw_rpc/test_impl/BUILD.gn
index faf7325..7c044cb 100644
--- a/pw_rpc/test_impl/BUILD.gn
+++ b/pw_rpc/test_impl/BUILD.gn
@@ -12,9 +12,12 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("config") {
   include_dirs = [ "public_overrides" ]
   visibility = [ ":*" ]
diff --git a/pw_span/BUILD.gn b/pw_span/BUILD.gn
index 725b842..859cb48 100644
--- a/pw_span/BUILD.gn
+++ b/pw_span/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_status/BUILD.gn b/pw_status/BUILD.gn
index 129b993..9ce40c8 100644
--- a/pw_status/BUILD.gn
+++ b/pw_status/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_stream/BUILD.gn b/pw_stream/BUILD.gn
index 34ffe40..d510781 100644
--- a/pw_stream/BUILD.gn
+++ b/pw_stream/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_string/BUILD.gn b/pw_string/BUILD.gn
index 6bf9cce..0e1165f 100644
--- a/pw_string/BUILD.gn
+++ b/pw_string/BUILD.gn
@@ -12,11 +12,14 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_bloat/bloat.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_string/size_report/BUILD.gn b/pw_string/size_report/BUILD.gn
index 9a63744..7fcce7a 100644
--- a/pw_string/size_report/BUILD.gn
+++ b/pw_string/size_report/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_build/target_types.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_build/target_types.gni")
 pw_executable("single_write_snprintf") {
   sources = [ "format_single.cc" ]
   deps = [
diff --git a/pw_sys_io/BUILD.gn b/pw_sys_io/BUILD.gn
index b7afcc5..aeb8eb5 100644
--- a/pw_sys_io/BUILD.gn
+++ b/pw_sys_io/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/facade.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_sys_io_baremetal_lm3s6965evb/BUILD.gn b/pw_sys_io_baremetal_lm3s6965evb/BUILD.gn
index 47219ae..8abfbf1 100644
--- a/pw_sys_io_baremetal_lm3s6965evb/BUILD.gn
+++ b/pw_sys_io_baremetal_lm3s6965evb/BUILD.gn
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 
diff --git a/pw_sys_io_baremetal_stm32f429/BUILD.gn b/pw_sys_io_baremetal_stm32f429/BUILD.gn
index f2f4bcc..f1d9466 100644
--- a/pw_sys_io_baremetal_stm32f429/BUILD.gn
+++ b/pw_sys_io_baremetal_stm32f429/BUILD.gn
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 
diff --git a/pw_sys_io_stdio/BUILD.gn b/pw_sys_io_stdio/BUILD.gn
index 48a1824..f9b8d4a 100644
--- a/pw_sys_io_stdio/BUILD.gn
+++ b/pw_sys_io_stdio/BUILD.gn
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 
diff --git a/pw_target_runner/BUILD.gn b/pw_target_runner/BUILD.gn
index b48c146..b06d0cd 100644
--- a/pw_target_runner/BUILD.gn
+++ b/pw_target_runner/BUILD.gn
@@ -12,9 +12,12 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_protobuf_compiler/proto.gni")
-
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
   group_deps = [ "go:docs" ]
diff --git a/pw_target_runner/go/BUILD.gn b/pw_target_runner/go/BUILD.gn
index 65a2802..f2f780a 100644
--- a/pw_target_runner/go/BUILD.gn
+++ b/pw_target_runner/go/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/go.gni")
 import("$dir_pw_build/host_tool.gni")
 import("$dir_pw_docgen/docs.gni")
-
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
 }
diff --git a/pw_target_runner/go/src/pigweed.dev/pw_target_runner/BUILD.gn b/pw_target_runner/go/src/pigweed.dev/pw_target_runner/BUILD.gn
index 5395a9e..946f356 100644
--- a/pw_target_runner/go/src/pigweed.dev/pw_target_runner/BUILD.gn
+++ b/pw_target_runner/go/src/pigweed.dev/pw_target_runner/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_build/go.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_build/go.gni")
 pw_go_package("pw_target_runner") {
   sources = [
     "exec_runner.go",
diff --git a/pw_target_runner/go/src/pigweed.dev/pw_target_runner_client/BUILD.gn b/pw_target_runner/go/src/pigweed.dev/pw_target_runner_client/BUILD.gn
index 4ed3a5d..6c2fbfa 100644
--- a/pw_target_runner/go/src/pigweed.dev/pw_target_runner_client/BUILD.gn
+++ b/pw_target_runner/go/src/pigweed.dev/pw_target_runner_client/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_build/go.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_build/go.gni")
 pw_go_package("pw_target_runner_client") {
   sources = [ "main.go" ]
   deps = [ "$dir_pw_target_runner:target_runner_proto_go" ]
diff --git a/pw_target_runner/go/src/pigweed.dev/pw_target_runner_server/BUILD.gn b/pw_target_runner/go/src/pigweed.dev/pw_target_runner_server/BUILD.gn
index c646269..87f1940 100644
--- a/pw_target_runner/go/src/pigweed.dev/pw_target_runner_server/BUILD.gn
+++ b/pw_target_runner/go/src/pigweed.dev/pw_target_runner_server/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_build/go.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_build/go.gni")
 pw_go_package("pw_target_runner_server") {
   sources = [ "main.go" ]
   deps = [
diff --git a/pw_tokenizer/BUILD.gn b/pw_tokenizer/BUILD.gn
index 0b9e612..60af352 100644
--- a/pw_tokenizer/BUILD.gn
+++ b/pw_tokenizer/BUILD.gn
@@ -12,12 +12,15 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/facade.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_fuzzer/fuzzer.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_toolchain/BUILD.gn b/pw_toolchain/BUILD.gn
index 3f42f2f..0ae0893 100644
--- a/pw_toolchain/BUILD.gn
+++ b/pw_toolchain/BUILD.gn
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_docgen/docs.gni")
 import("arm_gcc/toolchains.gni")
 import("generate_toolchain.gni")
diff --git a/pw_toolchain/arm_gcc/BUILD.gn b/pw_toolchain/arm_gcc/BUILD.gn
index 4725dd2..6e686ed 100644
--- a/pw_toolchain/arm_gcc/BUILD.gn
+++ b/pw_toolchain/arm_gcc/BUILD.gn
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pigweed/modules.gni")
 
 # Disable obnoxious ABI warning.
diff --git a/pw_toolchain/arm_gcc/toolchains.gni b/pw_toolchain/arm_gcc/toolchains.gni
index a2f3dcf..90a26e4 100644
--- a/pw_toolchain/arm_gcc/toolchains.gni
+++ b/pw_toolchain/arm_gcc/toolchains.gni
@@ -12,8 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pigweed/modules.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
 # Specifies the tools used by ARM GCC toolchains.
 arm_gcc_toolchain_tools = {
   _tool_name_root = "arm-none-eabi-"
diff --git a/pw_toolchain/dummy/BUILD.gn b/pw_toolchain/dummy/BUILD.gn
index 89781f5..ea9d683 100644
--- a/pw_toolchain/dummy/BUILD.gn
+++ b/pw_toolchain/dummy/BUILD.gn
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_toolchain/generate_toolchain.gni")
 
 # A dummy toolchain which is set as the default for Pigweed. This is never used;
diff --git a/pw_toolchain/generate_toolchain.gni b/pw_toolchain/generate_toolchain.gni
index abf8e9b..3445212 100644
--- a/pw_toolchain/generate_toolchain.gni
+++ b/pw_toolchain/generate_toolchain.gni
@@ -12,8 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pigweed/modules.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
 declare_args() {
   # Scope defining the current toolchain. Contains all of the arguments required
   # by the generate_toolchain template.
diff --git a/pw_toolchain/host_clang/BUILD.gn b/pw_toolchain/host_clang/BUILD.gn
index 5b1eae9..7fc2200 100644
--- a/pw_toolchain/host_clang/BUILD.gn
+++ b/pw_toolchain/host_clang/BUILD.gn
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pigweed/modules.gni")
 
 # See https://github.com/google/sanitizers
diff --git a/pw_toolchain/host_clang/toolchains.gni b/pw_toolchain/host_clang/toolchains.gni
index ceda466..7d850e9 100644
--- a/pw_toolchain/host_clang/toolchains.gni
+++ b/pw_toolchain/host_clang/toolchains.gni
@@ -12,8 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pigweed/modules.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
 declare_args() {
   # Sets the sanitizer to pass to clang. Valid values are those for "-fsanitize"
   # listed in https://clang.llvm.org/docs/UsersManual.html#id9.
diff --git a/pw_toolchain/host_gcc/BUILD.gn b/pw_toolchain/host_gcc/BUILD.gn
index 5bb456e..166cbed 100644
--- a/pw_toolchain/host_gcc/BUILD.gn
+++ b/pw_toolchain/host_gcc/BUILD.gn
@@ -12,6 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
+
 # Disable obnoxious ABI warning.
 #
 # GCC 7.1 adds an over-zealous ABI warning with little useful information
diff --git a/pw_toolchain/host_gcc/toolchains.gni b/pw_toolchain/host_gcc/toolchains.gni
index b1b3504..e60ada7 100644
--- a/pw_toolchain/host_gcc/toolchains.gni
+++ b/pw_toolchain/host_gcc/toolchains.gni
@@ -12,8 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pigweed/modules.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
 # Specifies the tools used by host GCC toolchains.
 _host_gcc_toolchain = {
   ar = "ar"
diff --git a/pw_trace/BUILD.gn b/pw_trace/BUILD.gn
index a6d873b..6be9ebc 100644
--- a/pw_trace/BUILD.gn
+++ b/pw_trace/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/facade.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_unit_test/BUILD.gn b/pw_unit_test/BUILD.gn
index f0b3c39..2da4cd7 100644
--- a/pw_unit_test/BUILD.gn
+++ b/pw_unit_test/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [
     "public",
diff --git a/pw_unit_test/test.gni b/pw_unit_test/test.gni
index f988a65..182d1f5 100644
--- a/pw_unit_test/test.gni
+++ b/pw_unit_test/test.gni
@@ -12,6 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/python_script.gni")
 import("$dir_pw_build/target_types.gni")
 
diff --git a/pw_varint/BUILD.gn b/pw_varint/BUILD.gn
index 2b80ea4..4425e1f 100644
--- a/pw_varint/BUILD.gn
+++ b/pw_varint/BUILD.gn
@@ -12,10 +12,13 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# gn-format disable
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pigweed/legacy_target.gni")
 import("$dir_pw_build/target_types.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
-
 config("default_config") {
   include_dirs = [ "public" ]
 }
diff --git a/pw_vars_default.gni b/pw_vars_default.gni
index e0ae163..20930f8 100644
--- a/pw_vars_default.gni
+++ b/pw_vars_default.gni
@@ -12,6 +12,8 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+import("//build_overrides/pigweed.gni")
+
 # This file defines default values for all of the build variables used by
 # Pigweed.
 #
diff --git a/pw_watch/BUILD.gn b/pw_watch/BUILD.gn
index d807aed..6c14ff7 100644
--- a/pw_watch/BUILD.gn
+++ b/pw_watch/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("docs") {
   inputs = [ "doc_resources/pw_watch_on_device_demo.gif" ]
   sources = [ "docs.rst" ]
diff --git a/pw_web_ui/BUILD.gn b/pw_web_ui/BUILD.gn
index 31d536d..956e5f7 100644
--- a/pw_web_ui/BUILD.gn
+++ b/pw_web_ui/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("docs") {
   sources = [ "docs.rst" ]
 }
diff --git a/targets/docs/BUILD.gn b/targets/docs/BUILD.gn
index 1c9c16e..82d2f30 100644
--- a/targets/docs/BUILD.gn
+++ b/targets/docs/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("target_docs") {
   sources = [ "target_docs.rst" ]
 }
diff --git a/targets/docs/target_config.gni b/targets/docs/target_config.gni
index e869532..2405726 100644
--- a/targets/docs/target_config.gni
+++ b/targets/docs/target_config.gni
@@ -12,8 +12,10 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pigweed/pw_vars_default.gni")
+# Get location of dir_pigweed.
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/pw_vars_default.gni")
 _arm_bloaty_config = "$dir_pw_boot_armv7m/bloaty_config.bloaty"
 
 # Targets are required to set a default toolchain. Use the Cortex M4 ARM
diff --git a/targets/host/BUILD.gn b/targets/host/BUILD.gn
index 1c9c16e..82d2f30 100644
--- a/targets/host/BUILD.gn
+++ b/targets/host/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("target_docs") {
   sources = [ "target_docs.rst" ]
 }
diff --git a/targets/host/host_common.gni b/targets/host/host_common.gni
index c78f6b2..b7f925d 100644
--- a/targets/host/host_common.gni
+++ b/targets/host/host_common.gni
@@ -12,6 +12,8 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+import("//build_overrides/pigweed.gni")
+
 import("$dir_pigweed/pw_vars_default.gni")
 
 declare_args() {
diff --git a/targets/lm3s6965evb-qemu/BUILD.gn b/targets/lm3s6965evb-qemu/BUILD.gn
index 1c9c16e..82d2f30 100644
--- a/targets/lm3s6965evb-qemu/BUILD.gn
+++ b/targets/lm3s6965evb-qemu/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("target_docs") {
   sources = [ "target_docs.rst" ]
 }
diff --git a/targets/lm3s6965evb-qemu/target_config.gni b/targets/lm3s6965evb-qemu/target_config.gni
index df93305..fd83ea3 100644
--- a/targets/lm3s6965evb-qemu/target_config.gni
+++ b/targets/lm3s6965evb-qemu/target_config.gni
@@ -19,8 +19,10 @@
 # testing/development and should eventually point to something more
 # sophisticated.
 
-import("$dir_pigweed/pw_vars_default.gni")
+# Get location of dir_pigweed.
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/pw_vars_default.gni")
 declare_args() {
   # Specifies the toolchain to use for this build.
   pw_target_toolchain = "$dir_pw_toolchain:arm_gcc_cortex_m3_og"
diff --git a/targets/stm32f429i-disc1/BUILD.gn b/targets/stm32f429i-disc1/BUILD.gn
index c129d8c..4e2507c 100644
--- a/targets/stm32f429i-disc1/BUILD.gn
+++ b/targets/stm32f429i-disc1/BUILD.gn
@@ -12,8 +12,11 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-import("$dir_pw_docgen/docs.gni")
+# gn-format disable
+import("//build_overrides/pigweed.gni")
 
+import("$dir_pigweed/legacy_target.gni")
+import("$dir_pw_docgen/docs.gni")
 pw_doc_group("target_docs") {
   sources = [ "target_docs.rst" ]
 }
diff --git a/targets/stm32f429i-disc1/target_config.gni b/targets/stm32f429i-disc1/target_config.gni
index 582f18d..2d03d00 100644
--- a/targets/stm32f429i-disc1/target_config.gni
+++ b/targets/stm32f429i-disc1/target_config.gni
@@ -19,8 +19,9 @@
 # testing/development and should eventually point to something more
 # sophisticated.
 
+# Get location of dir_pigweed.
+import("//build_overrides/pigweed.gni")
 import("$dir_pigweed/pw_vars_default.gni")
-
 declare_args() {
   # Specifies the toolchain to use for this build.
   pw_target_toolchain = "$dir_pw_toolchain:arm_gcc_cortex_m4f_og"