pw_kvs: Apply config pattern; configure log level
- Add PW_KVS_LOG_LEVEL to the pw_kvs config file and update code to
use it.
- Define a pw_kvs:config facade that be used to override configuration
values.
- Set up the empty "$dir_pw_build:empty" target that all modules use as
their default configuration backend via the
pw_build_DEFAULT_MODULE_CONFIGURATION variable.
Change-Id: Idf54d93678ffbd65e9e02a10454df4479f73827a
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/21240
Reviewed-by: David Rogers <davidrogers@google.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_kvs/BUILD.gn b/pw_kvs/BUILD.gn
index aa5bb5c..e3ef953 100644
--- a/pw_kvs/BUILD.gn
+++ b/pw_kvs/BUILD.gn
@@ -14,16 +14,25 @@
import("//build_overrides/pigweed.gni")
+import("$dir_pw_build/module_config.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")
-config("default_config") {
+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_kvs_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
+}
+
+config("public_include_path") {
include_dirs = [ "public" ]
+ visibility = [ ":*" ]
}
pw_source_set("pw_kvs") {
- public_configs = [ ":default_config" ]
+ public_configs = [ ":public_include_path" ]
public = [
"public/pw_kvs/alignment.h",
"public/pw_kvs/checksum.h",
@@ -47,7 +56,6 @@
"public/pw_kvs/internal/key_descriptor.h",
"public/pw_kvs/internal/sectors.h",
"public/pw_kvs/internal/span_traits.h",
- "pw_kvs_private/config.h",
"sectors.cc",
]
public_deps = [
@@ -57,12 +65,19 @@
dir_pw_status,
]
deps = [
+ ":config",
dir_pw_checksum,
dir_pw_log,
]
friend = [ ":*" ]
}
+pw_source_set("config") {
+ public_deps = [ pw_kvs_CONFIG ]
+ public = [ "pw_kvs_private/config.h" ]
+ visibility = [ ":*" ]
+}
+
pw_source_set("crc16") {
public = [ "public/pw_kvs/crc16_checksum.h" ]
public_deps = [
@@ -82,7 +97,7 @@
}
pw_source_set("fake_flash") {
- public_configs = [ ":default_config" ]
+ public_configs = [ ":public_include_path" ]
public = [ "public/pw_kvs/fake_flash_memory.h" ]
sources = [ "fake_flash_memory.cc" ]
public_deps = [
@@ -91,11 +106,14 @@
dir_pw_span,
dir_pw_status,
]
- deps = [ dir_pw_log ]
+ deps = [
+ ":config",
+ dir_pw_log,
+ ]
}
pw_source_set("fake_flash_small_partition") {
- public_configs = [ ":default_config" ]
+ public_configs = [ ":public_include_path" ]
public = [ "public/pw_kvs/flash_test_partition.h" ]
sources = [ "fake_flash_test_partition.cc" ]
public_deps = [ ":flash_test_partition" ]
@@ -106,7 +124,7 @@
}
pw_source_set("fake_flash_64_aligned_partition") {
- public_configs = [ ":default_config" ]
+ public_configs = [ ":public_include_path" ]
public = [ "public/pw_kvs/flash_test_partition.h" ]
sources = [ "fake_flash_test_partition.cc" ]
public_deps = [ ":flash_test_partition" ]
@@ -118,7 +136,7 @@
}
pw_source_set("fake_flash_256_aligned_partition") {
- public_configs = [ ":default_config" ]
+ public_configs = [ ":public_include_path" ]
public = [ "public/pw_kvs/flash_test_partition.h" ]
sources = [ "fake_flash_test_partition.cc" ]
public_deps = [ ":flash_test_partition" ]
@@ -130,7 +148,7 @@
}
pw_source_set("fake_flash_test_key_value_store") {
- public_configs = [ ":default_config" ]
+ public_configs = [ ":public_include_path" ]
sources = [ "fake_flash_test_key_value_store.cc" ]
public_deps = [ ":test_key_value_store" ]
deps = [
@@ -142,6 +160,7 @@
pw_source_set("flash_partition_test_100_iterations") {
deps = [
+ ":config",
":flash_test_partition",
dir_pw_kvs,
dir_pw_log,
@@ -153,6 +172,7 @@
pw_source_set("flash_partition_test_2_iterations") {
deps = [
+ ":config",
":flash_test_partition",
dir_pw_kvs,
dir_pw_log,
@@ -185,7 +205,7 @@
}
pw_source_set("test_partition") {
- public_configs = [ ":default_config" ]
+ public_configs = [ ":public_include_path" ]
public = [ "public/pw_kvs/flash_partition_with_stats.h" ]
sources = [ "flash_partition_with_stats.cc" ]
visibility = [ ":*" ]
@@ -194,6 +214,7 @@
dir_pw_log,
dir_pw_status,
]
+ deps = [ ":config" ]
}
pw_test_group("tests") {
diff --git a/pw_kvs/entry.cc b/pw_kvs/entry.cc
index 0fa68da..658c7df 100644
--- a/pw_kvs/entry.cc
+++ b/pw_kvs/entry.cc
@@ -13,6 +13,7 @@
// the License.
#define PW_LOG_MODULE_NAME "KVS"
+#define PW_LOG_LEVEL PW_KVS_LOG_LEVEL
#include "pw_kvs/internal/entry.h"
diff --git a/pw_kvs/entry_cache.cc b/pw_kvs/entry_cache.cc
index b6245a4..9fa93a2 100644
--- a/pw_kvs/entry_cache.cc
+++ b/pw_kvs/entry_cache.cc
@@ -13,6 +13,7 @@
// the License.
#define PW_LOG_MODULE_NAME "KVS"
+#define PW_LOG_LEVEL PW_KVS_LOG_LEVEL
#include "pw_kvs/internal/entry_cache.h"
@@ -21,6 +22,7 @@
#include "pw_kvs/flash_memory.h"
#include "pw_kvs/internal/entry.h"
#include "pw_kvs/internal/hash.h"
+#include "pw_kvs_private/config.h"
#include "pw_log/log.h"
namespace pw::kvs::internal {
diff --git a/pw_kvs/fake_flash_memory.cc b/pw_kvs/fake_flash_memory.cc
index b649567..7796a72 100644
--- a/pw_kvs/fake_flash_memory.cc
+++ b/pw_kvs/fake_flash_memory.cc
@@ -13,9 +13,11 @@
// the License.
#define PW_LOG_MODULE_NAME "KVS"
+#define PW_LOG_LEVEL PW_KVS_LOG_LEVEL
#include "pw_kvs/fake_flash_memory.h"
+#include "pw_kvs_private/config.h"
#include "pw_log/log.h"
namespace pw::kvs {
diff --git a/pw_kvs/flash_memory.cc b/pw_kvs/flash_memory.cc
index 1f663c4..93e08d7 100644
--- a/pw_kvs/flash_memory.cc
+++ b/pw_kvs/flash_memory.cc
@@ -13,6 +13,7 @@
// the License.
#define PW_LOG_MODULE_NAME "KVS"
+#define PW_LOG_LEVEL PW_KVS_LOG_LEVEL
#include "pw_kvs/flash_memory.h"
@@ -20,6 +21,7 @@
#include <cinttypes>
#include <cstring>
+#include "pw_assert/assert.h"
#include "pw_kvs_private/config.h"
#include "pw_log/log.h"
#include "pw_status/status_with_size.h"
diff --git a/pw_kvs/flash_partition_with_stats.cc b/pw_kvs/flash_partition_with_stats.cc
index d6fe283..6b2431b 100644
--- a/pw_kvs/flash_partition_with_stats.cc
+++ b/pw_kvs/flash_partition_with_stats.cc
@@ -13,12 +13,14 @@
// the License.
#define PW_LOG_MODULE_NAME "KVS"
+#define PW_LOG_LEVEL PW_KVS_LOG_LEVEL
#include "pw_kvs/flash_partition_with_stats.h"
#include <cstdio>
#include "pw_kvs/flash_memory.h"
+#include "pw_kvs_private/config.h"
#include "pw_log/log.h"
namespace pw::kvs {
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index 752590d..534313e 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -13,6 +13,7 @@
// the License.
#define PW_LOG_MODULE_NAME "KVS"
+#define PW_LOG_LEVEL PW_KVS_LOG_LEVEL
#define PW_LOG_USE_ULTRA_SHORT_NAMES 1
#include "pw_kvs/key_value_store.h"
@@ -23,6 +24,7 @@
#include <type_traits>
#include "pw_assert/assert.h"
+#include "pw_kvs_private/config.h"
#include "pw_log/log.h"
#include "pw_status/try.h"
diff --git a/pw_kvs/public/pw_kvs/flash_memory.h b/pw_kvs/public/pw_kvs/flash_memory.h
index 0590e56..d1864b4 100644
--- a/pw_kvs/public/pw_kvs/flash_memory.h
+++ b/pw_kvs/public/pw_kvs/flash_memory.h
@@ -18,7 +18,7 @@
#include <initializer_list>
#include <span>
-#include "pw_assert/assert.h"
+#include "pw_assert/light.h"
#include "pw_kvs/alignment.h"
#include "pw_status/status.h"
#include "pw_status/status_with_size.h"
@@ -48,7 +48,7 @@
start_address_(start_address),
start_sector_(sector_start),
erased_memory_content_(erased_memory_content) {
- PW_DCHECK_UINT_NE(alignment_, 0);
+ PW_ASSERT(alignment_ != 0u);
}
virtual ~FlashMemory() = default;
diff --git a/pw_kvs/pw_kvs_private/config.h b/pw_kvs/pw_kvs_private/config.h
index bbff197..fb9dc79 100644
--- a/pw_kvs/pw_kvs_private/config.h
+++ b/pw_kvs/pw_kvs_private/config.h
@@ -17,7 +17,12 @@
#include <cstddef>
-// The maximum flash alignment supported
+// Which log level to use for pw_kvs logs.
+#ifndef PW_KVS_LOG_LEVEL
+#define PW_KVS_LOG_LEVEL PW_LOG_LEVEL_INFO
+#endif // PW_KVS_LOG_LEVEL
+
+// The maximum flash alignment supported.
#ifndef PW_KVS_MAX_FLASH_ALIGNMENT
#define PW_KVS_MAX_FLASH_ALIGNMENT 256UL
#endif // PW_KVS_MAX_FLASH_ALIGNMENT
@@ -26,5 +31,7 @@
"Max flash alignment is required to be at least 16");
namespace pw::kvs {
+
inline constexpr size_t kMaxFlashAlignment = PW_KVS_MAX_FLASH_ALIGNMENT;
+
} // namespace pw::kvs
diff --git a/pw_kvs/sectors.cc b/pw_kvs/sectors.cc
index 94ff16e..e8d91b7 100644
--- a/pw_kvs/sectors.cc
+++ b/pw_kvs/sectors.cc
@@ -12,10 +12,13 @@
// License for the specific language governing permissions and limitations under
// the License.
+#define PW_LOG_MODULE_NAME "KVS"
+#define PW_LOG_LEVEL PW_KVS_LOG_LEVEL
#define PW_LOG_USE_ULTRA_SHORT_NAMES 1
#include "pw_kvs/internal/sectors.h"
+#include "pw_kvs_private/config.h"
#include "pw_log/log.h"
namespace pw::kvs::internal {