Generate the dir_* build args and lists of modules

- Generate dir_* module variables in modules.gni using the modules.py
  script. This consolidates the various lists of modules into a single
  PIGWEED_MODULES list. It also gives projects a way to include all
  Pigweed code without relying on its top-level BUILD.gn file.
- Generate pw_modules, pw_module_tests, and pw_module_docs lists that
  provide the targets for the top-level pw_modules and pw_modules_tests
  groups and for the docs:module_docs target.
- Display a warning in Pigweed's gn gen if any pw_* directories are
  missing from PIGWEED_MODULES.
- Move the logic for excluding tests under certain conditions into the
  modules.

Change-Id: Ied6f72315159af0d0da04505f8a91438e8b959e4
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/77940
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/modules.gni b/modules.gni
index 42a8e5a..a556fcc 100644
--- a/modules.gni
+++ b/modules.gni
@@ -1,4 +1,4 @@
-# Copyright 2021 The Pigweed Authors
+# Copyright 2022 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
@@ -12,129 +12,29 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
+# Generate a .gni file with a GN arg for each module and lists of modules and
+# tests. Then, import the generated .gni file.
+#
+# To avoid generating it multiple times, the modules list is only generated by
+# the default toolchain. The default toolchain runs before any other toolchains,
+# so the module list will be created before it is used by other toolchains.
+if (current_toolchain == default_toolchain) {
+  exec_script("pw_build/py/pw_build/generate_modules_lists.py",
+              [
+                rebase_path(".", root_build_dir),
+                get_path_info(".", "abspath"),
+                rebase_path("PIGWEED_MODULES", root_build_dir),
+                "pigweed_modules_list.gni",
+              ],
+              "",
+              [ "PIGWEED_MODULES" ])
+}
+
+# This import must follow the exec_script statement above, which generates
+# pigweed_modules_list.gni during gn gen.
+
+import("$root_build_dir/pigweed_modules_list.gni")
+
 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_docker = get_path_info("docker", "abspath")
-  dir_pw_analog = get_path_info("pw_analog", "abspath")
-  dir_pw_allocator = get_path_info("pw_allocator", "abspath")
-  dir_pw_android_toolchain = get_path_info("pw_android_toolchain", "abspath")
-  dir_pw_arduino_build = get_path_info("pw_arduino_build", "abspath")
-  dir_pw_assert = get_path_info("pw_assert", "abspath")
-  dir_pw_assert_basic = get_path_info("pw_assert_basic", "abspath")
-  dir_pw_assert_log = get_path_info("pw_assert_log", "abspath")
-  dir_pw_assert_tokenized = get_path_info("pw_assert_tokenized", "abspath")
-  dir_pw_assert_zephyr = get_path_info("pw_assert_zephyr", "abspath")
-  dir_pw_base64 = get_path_info("pw_base64", "abspath")
-  dir_pw_bloat = get_path_info("pw_bloat", "abspath")
-  dir_pw_blob_store = get_path_info("pw_blob_store", "abspath")
-  dir_pw_boot = get_path_info("pw_boot", "abspath")
-  dir_pw_boot_cortex_m = get_path_info("pw_boot_cortex_m", "abspath")
-  dir_pw_build = get_path_info("pw_build", "abspath")
-  dir_pw_build_info = get_path_info("pw_build_info", "abspath")
-  dir_pw_build_mcuxpresso = get_path_info("pw_build_mcuxpresso", "abspath")
-  dir_pw_bytes = get_path_info("pw_bytes", "abspath")
-  dir_pw_checksum = get_path_info("pw_checksum", "abspath")
-  dir_pw_chrono = get_path_info("pw_chrono", "abspath")
-  dir_pw_chrono_embos = get_path_info("pw_chrono_embos", "abspath")
-  dir_pw_chrono_freertos = get_path_info("pw_chrono_freertos", "abspath")
-  dir_pw_chrono_stl = get_path_info("pw_chrono_stl", "abspath")
-  dir_pw_chrono_threadx = get_path_info("pw_chrono_threadx", "abspath")
-  dir_pw_chrono_zephyr = get_path_info("pw_chrono_zephyr", "abspath")
-  dir_pw_cli = get_path_info("pw_cli", "abspath")
-  dir_pw_console = get_path_info("pw_console", "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_cortex_m =
-      get_path_info("pw_cpu_exception_cortex_m", "abspath")
-  dir_pw_crypto = get_path_info("pw_crypto", "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_file = get_path_info("pw_file", "abspath")
-  dir_pw_function = get_path_info("pw_function", "abspath")
-  dir_pw_fuzzer = get_path_info("pw_fuzzer", "abspath")
-  dir_pw_bluetooth_hci = get_path_info("pw_bluetooth_hci", "abspath")
-  dir_pw_hex_dump = get_path_info("pw_hex_dump", "abspath")
-  dir_pw_hdlc = get_path_info("pw_hdlc", "abspath")
-  dir_pw_i2c = get_path_info("pw_i2c", "abspath")
-  dir_pw_interrupt = get_path_info("pw_interrupt", "abspath")
-  dir_pw_interrupt_cortex_m = get_path_info("pw_interrupt_cortex_m", "abspath")
-  dir_pw_interrupt_zephyr = get_path_info("pw_interrupt_zephyr", "abspath")
-  dir_pw_kvs = get_path_info("pw_kvs", "abspath")
-  dir_pw_libc = get_path_info("pw_libc", "abspath")
-  dir_pw_log = get_path_info("pw_log", "abspath")
-  dir_pw_log_basic = get_path_info("pw_log_basic", "abspath")
-  dir_pw_log_null = get_path_info("pw_log_null", "abspath")
-  dir_pw_log_rpc = get_path_info("pw_log_rpc", "abspath")
-  dir_pw_log_string = get_path_info("pw_log_string", "abspath")
-  dir_pw_log_tokenized = get_path_info("pw_log_tokenized", "abspath")
-  dir_pw_malloc = get_path_info("pw_malloc", "abspath")
-  dir_pw_malloc_freelist = get_path_info("pw_malloc_freelist", "abspath")
-  dir_pw_metric = get_path_info("pw_metric", "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_multisink = get_path_info("pw_multisink", "abspath")
-  dir_pw_package = get_path_info("pw_package", "abspath")
-  dir_pw_persistent_ram = get_path_info("pw_persistent_ram", "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_random = get_path_info("pw_random", "abspath")
-  dir_pw_result = get_path_info("pw_result", "abspath")
-  dir_pw_ring_buffer = get_path_info("pw_ring_buffer", "abspath")
-  dir_pw_router = get_path_info("pw_router", "abspath")
-  dir_pw_rpc = get_path_info("pw_rpc", "abspath")
-  dir_pw_snapshot = get_path_info("pw_snapshot", "abspath")
-  dir_pw_software_update = get_path_info("pw_software_update", "abspath")
-  dir_pw_span = get_path_info("pw_span", "abspath")
-  dir_pw_spi = get_path_info("pw_spi", "abspath")
-  dir_pw_status = get_path_info("pw_status", "abspath")
-  dir_pw_stm32cube_build = get_path_info("pw_stm32cube_build", "abspath")
-  dir_pw_stream = get_path_info("pw_stream", "abspath")
-  dir_pw_string = get_path_info("pw_string", "abspath")
-  dir_pw_symbolizer = get_path_info("pw_symbolizer", "abspath")
-  dir_pw_sync = get_path_info("pw_sync", "abspath")
-  dir_pw_sync_embos = get_path_info("pw_sync_embos", "abspath")
-  dir_pw_sync_freertos = get_path_info("pw_sync_freertos", "abspath")
-  dir_pw_sync_baremetal = get_path_info("pw_sync_baremetal", "abspath")
-  dir_pw_sync_stl = get_path_info("pw_sync_stl", "abspath")
-  dir_pw_sync_threadx = get_path_info("pw_sync_threadx", "abspath")
-  dir_pw_sync_zephyr = get_path_info("pw_sync_zephyr", "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_arduino = get_path_info("pw_sys_io_arduino", "abspath")
-  dir_pw_sys_io_mcuxpresso = get_path_info("pw_sys_io_mcuxpresso", "abspath")
-  dir_pw_sys_io_stdio = get_path_info("pw_sys_io_stdio", "abspath")
-  dir_pw_sys_io_stm32cube = get_path_info("pw_sys_io_stm32cube", "abspath")
-  dir_pw_sys_io_zephyr = get_path_info("pw_sys_io_zephyr", "abspath")
-  dir_pw_system = get_path_info("pw_system", "abspath")
-  dir_pw_target_runner = get_path_info("pw_target_runner", "abspath")
-  dir_pw_thread = get_path_info("pw_thread", "abspath")
-  dir_pw_thread_stl = get_path_info("pw_thread_stl", "abspath")
-  dir_pw_thread_embos = get_path_info("pw_thread_embos", "abspath")
-  dir_pw_thread_freertos = get_path_info("pw_thread_freertos", "abspath")
-  dir_pw_thread_threadx = get_path_info("pw_thread_threadx", "abspath")
   dir_pw_third_party = get_path_info("third_party", "abspath")
-  dir_pw_tls_client = get_path_info("pw_tls_client", "abspath")
-  dir_pw_tls_client_boringssl =
-      get_path_info("pw_tls_client_boringssl", "abspath")
-  dir_pw_tls_client_mbedtls = get_path_info("pw_tls_client_mbedtls", "abspath")
-  dir_pw_tokenizer = get_path_info("pw_tokenizer", "abspath")
-  dir_pw_tool = get_path_info("pw_tool", "abspath")
-  dir_pw_toolchain = get_path_info("pw_toolchain", "abspath")
-  dir_pw_trace = get_path_info("pw_trace", "abspath")
-  dir_pw_trace_tokenized = get_path_info("pw_trace_tokenized", "abspath")
-  dir_pw_transfer = get_path_info("pw_transfer", "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")
-  dir_pw_work_queue = get_path_info("pw_work_queue", "abspath")
 }