pw_assert: Use consistent module configuration

Updates pw_assert to use the standard compile time module
configuration mechanism.

Requires: pigweed-internal:17762
Change-Id: I6d1f50e61184065832ec0a2c7a419b7964ac56fa
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/68700
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_assert/BUILD.bazel b/pw_assert/BUILD.bazel
index 0afb80d..a7e3658 100644
--- a/pw_assert/BUILD.bazel
+++ b/pw_assert/BUILD.bazel
@@ -28,8 +28,8 @@
     hdrs = [
         "public/pw_assert/assert.h",
         "public/pw_assert/check.h",
+        "public/pw_assert/config.h",
         "public/pw_assert/internal/check_impl.h",
-        "public/pw_assert/options.h",
         "public/pw_assert/short.h",
     ],
     includes = ["public"],
diff --git a/pw_assert/BUILD.gn b/pw_assert/BUILD.gn
index 258cd13..d73d0ca 100644
--- a/pw_assert/BUILD.gn
+++ b/pw_assert/BUILD.gn
@@ -15,10 +15,16 @@
 import("//build_overrides/pigweed.gni")
 
 import("$dir_pw_build/facade.gni")
+import("$dir_pw_build/module_config.gni")
 import("$dir_pw_docgen/docs.gni")
 import("$dir_pw_unit_test/test.gni")
 
 declare_args() {
+  # The build target that overrides the default configuration options for this
+  # module. This should point to a source set that provides defines through a
+  # public config (which may -include a file or add defines directly).
+  pw_assert_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
+
   # Backend for the pw_assert module.
   pw_assert_BACKEND = ""
 }
@@ -28,11 +34,18 @@
   visibility = [ ":*" ]
 }
 
+pw_source_set("config") {
+  public = [ "public/pw_assert/config.h" ]
+  public_configs = [ ":public_include_path" ]
+  public_deps = [ pw_assert_CONFIG ]
+}
+
 # Depending on dir_pw_assert provides both assert and check.
 group("pw_assert") {
   public_deps = [
     ":assert",
     ":check",
+    ":config",
   ]
 }
 
@@ -56,10 +69,12 @@
   public = [
     "public/pw_assert/check.h",
     "public/pw_assert/internal/check_impl.h",
-    "public/pw_assert/options.h",
     "public/pw_assert/short.h",
   ]
-  public_deps = [ dir_pw_preprocessor ]
+  public_deps = [
+    ":config",
+    dir_pw_preprocessor,
+  ]
 
   require_link_deps = [ ":impl" ]
 }
@@ -74,15 +89,11 @@
 # time. It is linked by the pw_assert:pw_assert (or pw_assert:check) targets.
 pw_source_set("assert") {
   public_configs = [ ":public_include_path" ]
-  public = [
-    "public/pw_assert/assert.h",
-
-    # Needed for PW_ASSERT_ENABLE_DEBUG. Note that depending on :pw_assert to
-    # get options.h won't work here since it will trigger the circular include
-    # problem that the :assert target is intended solve.
-    "public/pw_assert/options.h",
+  public = [ "public/pw_assert/assert.h" ]
+  public_deps = [
+    ":config",
+    dir_pw_preprocessor,
   ]
-  public_deps = [ dir_pw_preprocessor ]
 }
 
 # pw_assert is low-level and ubiquitous. Because of this, it can often cause
diff --git a/pw_assert/docs.rst b/pw_assert/docs.rst
index 82a0b99..41ea1ca 100644
--- a/pw_assert/docs.rst
+++ b/pw_assert/docs.rst
@@ -66,7 +66,7 @@
     // This assert is always enabled, even in production.
     PW_CHECK_INT_LE(ItemCount(), 100);
 
-    // This assert disabled for release builds, where NDEBUG is defined.
+    // This assert is enabled based on ``PW_ASSERT_ENABLE_DEBUG``.
     // The functions ItemCount() and GetStateStr() are never called.
     PW_DCHECK_INT_LE(ItemCount(), 100, "System state: %s", GetStateStr());
 
@@ -124,8 +124,8 @@
   Assert that a condition is true, optionally including a message with
   arguments to report if the codition is false.
 
-  The ``DCHECK`` variants only run if ``NDEBUG`` is defined; otherwise, the
-  entire statement is removed (and the expression not evaluated).
+  The ``DCHECK`` variants only run if ``PW_ASSERT_ENABLE_DEBUG`` is enabled;
+  otherwise, the entire statement is removed (and the expression not evaluated).
 
   Example:
 
@@ -169,8 +169,8 @@
   Assert that the given pointer is not ``NULL``, optionally including a message
   with arguments to report if the pointer is ``NULL``.
 
-  The ``DCHECK`` variants only run if ``NDEBUG`` is defined; otherwise, the
-  entire statement is removed (and the expression not evaluated).
+  The ``DCHECK`` variants only run if ``PW_ASSERT_ENABLE_DEBUG`` is enabled;
+  otherwise, the entire statement is removed (and the expression not evaluated).
 
   .. code-block:: cpp
 
@@ -191,8 +191,8 @@
   If present, the optional format message is reported on failure. Depending on
   the backend, values of ``a`` and ``b`` will also be reported.
 
-  The ``DCHECK`` variants only run if ``NDEBUG`` is defined; otherwise, the
-  entire statement is removed (and the expression not evaluated).
+  The ``DCHECK`` variants only run if ``PW_ASSERT_ENABLE_DEBUG`` is enabled;
+  otherwise, the entire statement is removed (and the expression not evaluated).
 
   Example, with no message:
 
@@ -265,7 +265,8 @@
   +-------------------------+--------------+-----------+-----------------------+
 
   The above ``CHECK_*_*()`` are also available in DCHECK variants, which will
-  only evaluate their arguments and trigger if the ``NDEBUG`` macro is defined.
+  only evaluate their arguments and trigger if the ``PW_ASSERT_ENABLE_DEBUG``
+  macro is enabled.
 
   +--------------------------+--------------+-----------+----------------------+
   | Macro                    | a, b type    | condition | a, b format          |
@@ -340,8 +341,8 @@
   .. note::
     This also asserts that ``abs_tolerance >= 0``.
 
-  The ``DCHECK`` variants only run if ``NDEBUG`` is defined; otherwise, the
-  entire statement is removed (and the expression not evaluated).
+  The ``DCHECK`` variants only run if ``PW_ASSERT_ENABLE_DEBUG`` is enabled;
+  otherwise, the entire statement is removed (and the expression not evaluated).
 
   Example, with no message:
 
@@ -365,8 +366,8 @@
   ``PW_STATUS_OK`` (in C). Optionally include a message with arguments to
   report.
 
-  The ``DCHECK`` variants only run if ``NDEBUG`` is defined; otherwise, the
-  entire statement is removed (and the expression not evaluated).
+  The ``DCHECK`` variants only run if ``PW_ASSERT_ENABLE_DEBUG`` is defined;
+  otherwise, the entire statement is removed (and the expression not evaluated).
 
   .. code-block:: cpp
 
@@ -451,7 +452,7 @@
 
   A header- and constexpr-safe version of ``PW_DCHECK()``.
 
-  Same as ``PW_ASSERT()``, except that if ``PW_ASSERT_ENABLE_DEBUG == 1``, the
+  Same as ``PW_ASSERT()``, except that if ``PW_ASSERT_ENABLE_DEBUG == 0``, the
   assert is disabled and condition is not evaluated.
 
 .. attention::
@@ -700,6 +701,21 @@
 ``b``, so unfortunately having a separate macro for each of the types commonly
 asserted on is necessary.
 
+----------------------------
+Module Configuration Options
+----------------------------
+The following configurations can be adjusted via compile-time configuration of
+this module, see the
+:ref:`module documentation <module-structure-compile-time-configuration>` for
+more details.
+
+.. c:macro:: PW_ASSERT_ENABLE_DEBUG
+
+  Controls whether ``DCHECK`` and ``DASSERT`` are enabled.
+
+  This defaults to being disabled if ``NDEBUG`` is defined, else it is enabled
+  by default.
+
 -------------
 Compatibility
 -------------
diff --git a/pw_assert/public/pw_assert/assert.h b/pw_assert/public/pw_assert/assert.h
index 3b54529..53b0f15 100644
--- a/pw_assert/public/pw_assert/assert.h
+++ b/pw_assert/public/pw_assert/assert.h
@@ -13,7 +13,7 @@
 // the License.
 #pragma once
 
-#include "pw_assert/options.h"  // For PW_ASSERT_ENABLE_DEBUG
+#include "pw_assert/config.h"  // For PW_ASSERT_ENABLE_DEBUG
 #include "pw_preprocessor/compiler.h"
 #include "pw_preprocessor/util.h"
 
diff --git a/pw_assert/public/pw_assert/options.h b/pw_assert/public/pw_assert/config.h
similarity index 96%
rename from pw_assert/public/pw_assert/options.h
rename to pw_assert/public/pw_assert/config.h
index e7ea02f..d2feebb 100644
--- a/pw_assert/public/pw_assert/options.h
+++ b/pw_assert/public/pw_assert/config.h
@@ -1,4 +1,4 @@
-// Copyright 2020 The Pigweed Authors
+// Copyright 2021 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
diff --git a/pw_assert/public/pw_assert/internal/check_impl.h b/pw_assert/public/pw_assert/internal/check_impl.h
index 7159eb0..5dba292 100644
--- a/pw_assert/public/pw_assert/internal/check_impl.h
+++ b/pw_assert/public/pw_assert/internal/check_impl.h
@@ -19,7 +19,7 @@
 
 // Note: This file depends on the backend header already being included.
 
-#include "pw_assert/options.h"
+#include "pw_assert/config.h"
 #include "pw_preprocessor/arguments.h"
 #include "pw_preprocessor/compiler.h"
 
diff --git a/pw_assert_basic/BUILD.gn b/pw_assert_basic/BUILD.gn
index 3bb9023..72c22f1 100644
--- a/pw_assert_basic/BUILD.gn
+++ b/pw_assert_basic/BUILD.gn
@@ -61,6 +61,7 @@
   ]
   deps = [
     ":pw_assert_basic",
+    "$dir_pw_assert:config",
     "$dir_pw_assert:facade",
     "$dir_pw_preprocessor",
     pw_assert_basic_HANDLER_BACKEND,
@@ -81,6 +82,7 @@
   ]
   deps = [
     ":handler.facade",
+    "$dir_pw_assert:config",
     "$dir_pw_assert:facade",
     "$dir_pw_preprocessor",
     "$dir_pw_sys_io:facade",  # Only pull in the facade to avoid circular deps
diff --git a/pw_assert_basic/assert_basic.cc b/pw_assert_basic/assert_basic.cc
index 72f2e8c..fcc20cc 100644
--- a/pw_assert_basic/assert_basic.cc
+++ b/pw_assert_basic/assert_basic.cc
@@ -12,7 +12,7 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-#include "pw_assert/options.h"
+#include "pw_assert/config.h"
 #include "pw_assert_basic/handler.h"
 
 extern "C" void pw_assert_HandleFailure(void) {
diff --git a/pw_assert_basic/basic_handler.cc b/pw_assert_basic/basic_handler.cc
index cbb0b07..6a6e734 100644
--- a/pw_assert_basic/basic_handler.cc
+++ b/pw_assert_basic/basic_handler.cc
@@ -20,7 +20,7 @@
 #include <cstdio>
 #include <cstring>
 
-#include "pw_assert/options.h"
+#include "pw_assert/config.h"
 #include "pw_assert_basic/handler.h"
 #include "pw_preprocessor/util.h"
 #include "pw_string/string_builder.h"
diff --git a/pw_assert_log/BUILD.gn b/pw_assert_log/BUILD.gn
index 5ecd0c1..f1ace46 100644
--- a/pw_assert_log/BUILD.gn
+++ b/pw_assert_log/BUILD.gn
@@ -41,6 +41,7 @@
   public_configs = [ ":default_config" ]
   public_deps = [ "$dir_pw_log" ]
   deps = [
+    "$dir_pw_assert:config",
     "$dir_pw_assert:facade",
     "$dir_pw_preprocessor",
   ]
diff --git a/pw_assert_log/assert_log.cc b/pw_assert_log/assert_log.cc
index 611f126..9b31c91 100644
--- a/pw_assert_log/assert_log.cc
+++ b/pw_assert_log/assert_log.cc
@@ -14,7 +14,7 @@
 
 #include "pw_assert_log/assert_log.h"
 
-#include "pw_assert/options.h"
+#include "pw_assert/config.h"
 
 extern "C" void pw_assert_HandleFailure(void) {
 #if PW_ASSERT_ENABLE_DEBUG