Update Pigweed presubmit

Updates the upstream presubmit to play nicely with The Great GN
Refactor.

Change-Id: I2296db592b4c8e3c2d5592410b9846e7435ac1fc
diff --git a/BUILD.gn b/BUILD.gn
index 2742f25..1d86400 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -103,7 +103,7 @@
         deps += [ ":pw_module_tests_run" ]
       }
     }
-    if (pw_IS_HOST_TOOLCHAIN) {
+    if (pw_IS_HOST_TOOLCHAIN && pw_build_HOST_TOOLS) {
       deps += [ ":host_tools" ]
     }
   }
@@ -192,7 +192,7 @@
       group_deps += [ "$dir_pw_cpu_exception_armv7m:tests" ]
     }
 
-    if (pw_build_HOST_TOOLS) {
+    if (pw_IS_HOST_TOOLCHAIN) {
       # TODO(pwbug/196): KVS tests are not compatible with device builds as they
       # use features such as std::map and are computationally expensive. Solving
       # this requires a more complex capabilities-based build and configuration
diff --git a/docs/BUILD.gn b/docs/BUILD.gn
index d13db7e..c700ecd 100644
--- a/docs/BUILD.gn
+++ b/docs/BUILD.gn
@@ -58,6 +58,7 @@
   deps = [
     ":core_docs",
     ":target_docs",
+    "$dir_pw_allocator:docs",
     "$dir_pw_assert:docs",
     "$dir_pw_assert_basic:docs",
     "$dir_pw_base64:docs",
diff --git a/pw_allocator/docs.rst b/pw_allocator/docs.rst
index ae31c55..9604377 100644
--- a/pw_allocator/docs.rst
+++ b/pw_allocator/docs.rst
@@ -9,10 +9,10 @@
 This module provides various building blocks
 for a dynamic allocator. This is composed of the following parts:
 
-- ``block`` - An implementation of a linked list of memory blocks, supporting
-  splitting and merging of blocks.
-- ``freelist`` - A freelist, suitable for fast lookups of available memory
-  chunks (i.e. ``block``s)
+ - ``block``: An implementation of a linked list of memory blocks, supporting
+   splitting and merging of blocks.
+ - ``freelist``: A freelist, suitable for fast lookups of available memory
+   chunks (i.e. ``block`` s).
 
 Note, this module, and its documentation, is currently incomplete and
 experimental.
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index b46df18..8ef7136 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -54,70 +54,46 @@
 #
 # Build presubmit checks
 #
-_CLANG_GEN_ARGS = build.gn_args(
-    pw_target_config='"//targets/host/target_config.gni"',
-    pw_target_toolchain='"//pw_toolchain:host_clang_os"')
-
-_DOCS_GEN_ARGS = build.gn_args(
-    pw_target_config='"//targets/docs/target_config.gni"')
-
-
 def gn_clang_build(ctx: PresubmitContext):
-    build.gn_gen(ctx.root, ctx.output_dir, _CLANG_GEN_ARGS)
-    build.ninja(ctx.output_dir)
+    build.gn_gen(ctx.root, ctx.output_dir)
+    build.ninja(ctx.output_dir, "host_clang")
 
 
 @filter_paths(endswith=format_code.C_FORMAT.extensions)
 def gn_gcc_build(ctx: PresubmitContext):
-    build.gn_gen(
-        ctx.root, ctx.output_dir,
-        build.gn_args(pw_target_config='"//targets/host/target_config.gni"',
-                      pw_target_toolchain='"//pw_toolchain:host_gcc_os"'))
-    build.ninja(ctx.output_dir)
-
-
-_ARM_GEN_ARGS = build.gn_args(
-    pw_target_config='"//targets/stm32f429i-disc1/target_config.gni"')
+    build.gn_gen(ctx.root, ctx.output_dir)
+    build.ninja(ctx.output_dir, "host_gcc")
 
 
 @filter_paths(endswith=format_code.C_FORMAT.extensions)
 def gn_arm_build(ctx: PresubmitContext):
-    build.gn_gen(ctx.root, ctx.output_dir, _ARM_GEN_ARGS)
-    build.ninja(ctx.output_dir)
-
-
-_QEMU_GEN_ARGS = build.gn_args(
-    pw_target_config='"//targets/lm3s6965evb-qemu/target_config.gni"')
+    build.gn_gen(ctx.root, ctx.output_dir)
+    build.ninja(ctx.output_dir, "stm32f429i")
 
 
 @filter_paths(endswith=format_code.C_FORMAT.extensions)
 def gn_qemu_build(ctx: PresubmitContext):
-    build.gn_gen(ctx.root, ctx.output_dir, _QEMU_GEN_ARGS)
-    build.ninja(ctx.output_dir)
+    build.gn_gen(ctx.root, ctx.output_dir)
+    build.ninja(ctx.output_dir, "qemu")
 
 
 def gn_docs_build(ctx: PresubmitContext):
-    build.gn_gen(ctx.root, ctx.output_dir, _DOCS_GEN_ARGS)
-    build.ninja(ctx.output_dir, 'docs:docs')
+    build.gn_gen(ctx.root, ctx.output_dir)
+    build.ninja(ctx.output_dir, 'docs')
 
 
 def gn_host_tools(ctx: PresubmitContext):
-    build.gn_gen(ctx.root,
-                 ctx.output_dir,
-                 pw_target_config='"//targets/host/target_config.gni"',
-                 pw_target_toolchain='"//pw_toolchain:host_clang_os"',
-                 pw_build_host_tools='true')
-    build.ninja(ctx.output_dir, 'host_tools')
+    build.gn_gen(ctx.root, ctx.output_dir, pw_build_HOST_TOOLS='true')
+    build.ninja(ctx.output_dir)
 
 
 @filter_paths(endswith=format_code.C_FORMAT.extensions)
 def oss_fuzz_build(ctx: PresubmitContext):
     build.gn_gen(ctx.root,
                  ctx.output_dir,
-                 oss_fuzz_enabled='true',
-                 pw_target_toolchain='"//pw_toolchain:host_clang_og"',
-                 pw_sanitizer='"address"')
-    build.ninja(ctx.output_dir)
+                 pw_toolchain_OSS_FUZZ_ENABLED='true',
+                 pw_toolchain_SANITIZER='"address"')
+    build.ninja(ctx.output_dir, "host_clang")
 
 
 @filter_paths(endswith=(*format_code.C_FORMAT.extensions, '.cmake',
@@ -157,8 +133,7 @@
 
 @filter_paths(endswith=format_code.C_FORMAT.extensions)
 def clang_tidy(ctx: PresubmitContext):
-    build.gn_gen(ctx.root, ctx.output_dir, '--export-compile-commands',
-                 _CLANG_GEN_ARGS)
+    build.gn_gen(ctx.root, ctx.output_dir, '--export-compile-commands')
     build.ninja(ctx.output_dir)
     build.ninja(ctx.output_dir, '-t', 'compdb', 'objcxx', 'cxx')
 
@@ -276,23 +251,13 @@
 @filter_paths(endswith=(*_SOURCES_IN_BUILD, 'BUILD', '.bzl', '.gn', '.gni'))
 def source_is_in_build_files(ctx: PresubmitContext):
     """Checks that source files are in the GN and Bazel builds."""
-    gn_gens_to_run = (
-        (ctx.output_dir.joinpath('arm'), _ARM_GEN_ARGS),
-        (ctx.output_dir.joinpath('clang'), _CLANG_GEN_ARGS),
-        (ctx.output_dir.joinpath('docs'), _DOCS_GEN_ARGS),
-        (ctx.output_dir.joinpath('qemu'), _QEMU_GEN_ARGS),
-    )
-
-    for directory, args in gn_gens_to_run:
-        build.gn_gen(ctx.root, directory, args)
+    gn_path = ctx.output_dir.joinpath('default')
+    build.gn_gen(ctx.root, gn_path, pw_build_HOST_TOOLS='true')
 
     missing = build.check_builds_for_files(_SOURCES_IN_BUILD,
                                            ctx.paths,
                                            bazel_dirs=[ctx.root],
-                                           gn_dirs=[
-                                               (ctx.root, path)
-                                               for path, _ in gn_gens_to_run
-                                           ])
+                                           gn_dirs=[(ctx.root, gn_path)])
 
     if missing:
         _LOG.warning(
diff --git a/pw_tokenizer/CMakeLists.txt b/pw_tokenizer/CMakeLists.txt
index 3e25685..00fbe75 100644
--- a/pw_tokenizer/CMakeLists.txt
+++ b/pw_tokenizer/CMakeLists.txt
@@ -92,7 +92,7 @@
 
 pw_add_test(pw_tokenizer.argument_types_test
   SOURCES
-    argument_types_test.c
+    argument_types_test_c.c
     argument_types_test.cc
   DEPS
     pw_tokenizer
@@ -134,7 +134,7 @@
 
 pw_add_test(pw_tokenizer.global_handlers_test
   SOURCES
-    global_handlers_test.c
+    global_handlers_test_c.c
     global_handlers_test.cc
   DEPS
     pw_tokenizer.global_handler
@@ -166,7 +166,7 @@
 
 pw_add_test(pw_tokenizer.tokenize_test
   SOURCES
-    tokenize_test.c
+    tokenize_test_c.c
     tokenize_test.cc
   DEPS
     pw_varint
diff --git a/pw_toolchain/generate_toolchain.gni b/pw_toolchain/generate_toolchain.gni
index a3e4dcd..2aea684 100644
--- a/pw_toolchain/generate_toolchain.gni
+++ b/pw_toolchain/generate_toolchain.gni
@@ -110,8 +110,9 @@
       tool("alink") {
         command = "rm -f {{output}} && ${invoker.ar} rcs {{output}} {{inputs}}"
         description = "ar {{target_output_name}}{{output_extension}}"
-        outputs =
-            [ "{{target_out_dir}}/lib/{{target_output_name}}{{output_extension}}" ]
+        outputs = [
+          "{{target_out_dir}}/lib/{{target_output_name}}{{output_extension}}",
+        ]
         default_output_extension = ".a"
       }
 
diff --git a/pw_trace/BUILD.gn b/pw_trace/BUILD.gn
index cd246f6..8f3b42d 100644
--- a/pw_trace/BUILD.gn
+++ b/pw_trace/BUILD.gn
@@ -68,8 +68,8 @@
   ]
 
   sources = [
-    "trace_backend_compile_test.c",
     "trace_backend_compile_test.cc",
+    "trace_backend_compile_test_c.c",
   ]
 }
 
diff --git a/pw_watch/py/pw_watch/watch.py b/pw_watch/py/pw_watch/watch.py
index 0687208..41a0d49 100755
--- a/pw_watch/py/pw_watch/watch.py
+++ b/pw_watch/py/pw_watch/watch.py
@@ -478,7 +478,7 @@
         _LOG.info('Searching for GN build dirs...')
         gn_args_files = []
         if os.path.isfile('out/args.gn'):
-          gn_args_files += ['out/args.gn']
+            gn_args_files += ['out/args.gn']
         gn_args_files += glob.glob('out/*/args.gn')
 
         for gn_args_file in gn_args_files:
diff --git a/targets/host/target_toolchains.gni b/targets/host/target_toolchains.gni
index 4a6a233..aeee7a2 100644
--- a/targets/host/target_toolchains.gni
+++ b/targets/host/target_toolchains.gni
@@ -15,6 +15,8 @@
 # gn-format disable
 import("//build_overrides/pigweed.gni")
 
+import("$dir_pw_protobuf_compiler/nanopb.gni")
+import("$dir_pw_protobuf_compiler/proto.gni")
 import("$dir_pw_toolchain/host_clang/toolchains.gni")
 import("$dir_pw_toolchain/host_gcc/toolchains.gni")
 _host_common = {
@@ -29,6 +31,13 @@
 
   # Configure backend for pw_sys_io facade.
   pw_sys_io_BACKEND = "$dir_pw_sys_io_stdio"
+
+  # Allow nanopb to be toggled via a build arg on host for easy testing.
+  if (dir_pw_third_party_nanopb != "") {
+    pw_protobuf_GENERATORS += [ "nanopb" ]
+  }
+
+  pw_IS_HOST_TOOLCHAIN = true
 }
 
 # Linux-specific target configuration.