aboutsummaryrefslogtreecommitdiff
path: root/pw_kvs
diff options
context:
space:
mode:
authorWyatt Hepler <hepler@google.com>2020-10-14 10:46:27 -0700
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2020-10-16 19:45:13 +0000
commitae222dc4921064e2c9a044c69f2c36541c811e57 (patch)
treec10fc231c8c6b32abd2296fa2fb16940a67fbf2e /pw_kvs
parentb4f9598bae4e1751544d3264bcb590d9d44629c5 (diff)
downloadpigweed-ae222dc4921064e2c9a044c69f2c36541c811e57.tar.gz
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>
Diffstat (limited to 'pw_kvs')
-rw-r--r--pw_kvs/BUILD.gn41
-rw-r--r--pw_kvs/entry.cc1
-rw-r--r--pw_kvs/entry_cache.cc2
-rw-r--r--pw_kvs/fake_flash_memory.cc2
-rw-r--r--pw_kvs/flash_memory.cc2
-rw-r--r--pw_kvs/flash_partition_with_stats.cc2
-rw-r--r--pw_kvs/key_value_store.cc2
-rw-r--r--pw_kvs/public/pw_kvs/flash_memory.h4
-rw-r--r--pw_kvs/pw_kvs_private/config.h9
-rw-r--r--pw_kvs/sectors.cc3
10 files changed, 55 insertions, 13 deletions
diff --git a/pw_kvs/BUILD.gn b/pw_kvs/BUILD.gn
index aa5bb5c95..e3ef953db 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 @@ pw_source_set("pw_kvs") {
"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 @@ pw_source_set("pw_kvs") {
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("test_key_value_store") {
}
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 @@ pw_source_set("fake_flash") {
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_small_partition") {
}
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_64_aligned_partition") {
}
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_256_aligned_partition") {
}
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("fake_flash_test_key_value_store") {
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_100_iterations") {
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_key_value_store_test") {
}
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 @@ pw_source_set("test_partition") {
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 0fa68da0c..658c7df11 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 b6245a4d5..9fa93a263 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 b64956725..7796a7287 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 1f663c478..93e08d716 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 d6fe2839e..6b2431b2f 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 752590d58..534313eb5 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 0590e56a3..d1864b4f0 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 @@ class FlashMemory {
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 bbff1975d..fb9dc7999 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 @@ static_assert((PW_KVS_MAX_FLASH_ALIGNMENT >= 16UL),
"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 94ff16e0a..e8d91b7e9 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 {