Skip to content

Commit

Permalink
pw_assert: Rename assert_lite_backend.h to assert_backend.h
Browse files Browse the repository at this point in the history
PW_ASSERT originally used assert_lite_backend.h for its backend since
the assert_backend.h header was used for PW_CHECK's backend. PW_CHECK
moved to check_backend.h, so now PW_ASSERT can use assert_backend.h.

Update some target names and paths to match the new assert/check split.

Change-Id: I4efc3a90251585c4c5932eb38bfa5f3096d5cd5e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/96741
Commit-Queue: Auto-Submit <[email protected]>
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Reviewed-by: Ewout van Bekkum <[email protected]>
  • Loading branch information
255 authored and CQ Bot Account committed Jun 6, 2022
1 parent 29f0526 commit e072181
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 68 deletions.
18 changes: 10 additions & 8 deletions pw_assert/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ licenses(["notice"])
pw_cc_facade(
name = "facade",
hdrs = [
"assert_lite_public_overrides/pw_assert_backend/assert_lite_backend.h",
"assert_compatibility_public_overrides/pw_assert_backend/assert_backend.h",
"public/pw_assert/assert.h",
"public/pw_assert/check.h",
"public/pw_assert/internal/check_impl.h",
"public/pw_assert/short.h",
],
includes = [
"assert_lite_public_overrides",
"assert_compatibility_public_overrides",
"public",
],
deps = [
Expand Down Expand Up @@ -64,27 +64,29 @@ pw_cc_library(
)

pw_cc_library(
name = "print_and_abort_lite_backend",
hdrs = ["print_and_abort_lite_public_overrides/pw_assert_backend/assert_lite_backend.h"],
includes = ["print_and_abort_lite_public_overrides"],
name = "print_and_abort_assert_backend",
hdrs = ["print_and_abort_assert_public_overrides/pw_assert_backend/assert_backend.h"],
includes = ["print_and_abort_assert_public_overrides"],
deps = [
":config",
":print_and_abort",
],
)

pw_cc_library(
name = "print_and_abort_backend",
name = "print_and_abort_check_backend",
hdrs =
["print_and_abort_public_overrides/pw_assert_backend/check_backend.h"],
["print_and_abort_check_public_overrides/pw_assert_backend/check_backend.h"],
includes = ["print_and_abort_public_overrides"],
deps = [":print_and_abort"],
)

pw_cc_library(
name = "backend_multiplexer",
visibility = ["@pigweed_config//:__pkg__"],
deps = ["@pigweed//pw_assert_basic"],
deps = [
"@pigweed//pw_assert_basic",
],
)

pw_cc_test(
Expand Down
49 changes: 24 additions & 25 deletions pw_assert/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ config("public_include_path") {
visibility = [ ":*" ]
}

config("lite_backend_overrides") {
include_dirs = [ "assert_lite_public_overrides" ]
config("assert_backend_overrides") {
include_dirs = [ "assert_compatibility_public_overrides" ]
visibility = [ ":*" ]
}

config("print_and_abort_backend_overrides") {
include_dirs = [ "print_and_abort_public_overrides" ]
config("print_and_abort_check_backend_overrides") {
include_dirs = [ "print_and_abort_check_public_overrides" ]
visibility = [ ":*" ]
}

config("print_and_abort_lite_backend_overrides") {
include_dirs = [ "print_and_abort_lite_public_overrides" ]
config("print_and_abort_assert_backend_overrides") {
include_dirs = [ "print_and_abort_assert_public_overrides" ]
visibility = [ ":*" ]
}

Expand Down Expand Up @@ -104,16 +104,17 @@ pw_facade("assert") {
# This backend to pw_assert's PW_ASSERT()/PW_DASSERT() macros provides backwards
# compatibility with pw_assert's previous C-symbol based API.
#
# Warning: The "lite" naming is transitional. assert_lite_backend.h headers
# will be renamed as the pw_assert API is reassessed. (pwbug/246)
pw_source_set("lite_compatibility_backend") {
public_configs = [ ":lite_backend_overrides" ]
# Warning: The assert facade is in a transitional state, and this target is
# likely to be removed as the pw_assert API is reassessed. (pwbug/246)
pw_source_set("assert_compatibility_backend") {
public_configs = [ ":assert_backend_overrides" ]
public_deps = [ dir_pw_preprocessor ]
public =
[ "assert_lite_public_overrides/pw_assert_backend/assert_lite_backend.h" ]
public = [
"assert_compatibility_public_overrides/pw_assert_backend/assert_backend.h",
]
}

group("lite_compatibility_backend.impl") {
group("assert_compatibility_backend.impl") {
}

pw_source_set("print_and_abort") {
Expand All @@ -126,32 +127,30 @@ pw_source_set("print_and_abort") {
# This backend to pw_assert's PW_CHECK()/PW_DCHECK() macros prints the assert
# expression, evaluated expression, file/line number, function, and user message
# with printf, then aborts. It is intended for use with host builds.
pw_source_set("print_and_abort_backend") {
public_configs = [ ":print_and_abort_backend_overrides" ]
pw_source_set("print_and_abort_check_backend") {
public_configs = [ ":print_and_abort_check_backend_overrides" ]
public_deps = [ ":print_and_abort" ]
public =
[ "print_and_abort_public_overrides/pw_assert_backend/check_backend.h" ]
public = [
"print_and_abort_check_public_overrides/pw_assert_backend/check_backend.h",
]
}

group("print_and_abort_backend.impl") {
group("print_and_abort_check_backend.impl") {
}

# This backend to pw_assert's PW_ASSERT()/PW_DASSERT() macros prints the assert
# expression, file/line number, and function with printf, then aborts. It is
# intended for use with host builds.
#
# Warning: The "lite" naming is transitional. assert_lite_backend.h headers
# will be renamed as the pw_assert API is reassessed. (pwbug/246)
pw_source_set("print_and_abort_lite_backend") {
public_configs = [ ":print_and_abort_lite_backend_overrides" ]
pw_source_set("print_and_abort_assert_backend") {
public_configs = [ ":print_and_abort_assert_backend_overrides" ]
public_deps = [
":config",
":print_and_abort",
]
public = [ "print_and_abort_lite_public_overrides/pw_assert_backend/assert_lite_backend.h" ]
public = [ "print_and_abort_assert_public_overrides/pw_assert_backend/assert_backend.h" ]
}

group("print_and_abort_lite_backend.impl") {
group("print_and_abort_assert_backend.impl") {
}

# pw_assert is low-level and ubiquitous. Because of this, it can often cause
Expand Down
5 changes: 4 additions & 1 deletion pw_assert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ pw_add_facade(pw_assert
pw_preprocessor
${pw_assert_CONFIG}
)
target_include_directories(pw_assert INTERFACE assert_lite_public_overrides)
target_include_directories(pw_assert
INTERFACE
assert_compatibility_public_overrides
)
2 changes: 1 addition & 1 deletion pw_assert/backend.gni
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ declare_args() {
#
# Warning: This naming is transitional. Modifying this build argument WILL
# result in future breakages. (pwbug/246)
pw_assert_LITE_BACKEND = "${dir_pw_assert}:lite_compatibility_backend"
pw_assert_LITE_BACKEND = "${dir_pw_assert}:assert_compatibility_backend"
}
2 changes: 1 addition & 1 deletion pw_assert/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ is providing a macro-based backend API for the ``PW_ASSERT()`` and
are extremely confusingly similar and are NOT interchangeable.

A macro-based backend for the ``PW_ASSERT()`` macros must provide the following
macro in a header at ``pw_assert_backend/assert_lite_backend.h``.
macro in a header at ``pw_assert_backend/assert_backend.h``.

.. cpp:function:: PW_ASSERT_HANDLE_FAILURE(expression)

Expand Down
2 changes: 1 addition & 1 deletion pw_assert/public/pw_assert/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#pragma once

#include "pw_assert/config.h" // For PW_ASSERT_ENABLE_DEBUG
#include "pw_assert_backend/assert_lite_backend.h"
#include "pw_assert_backend/assert_backend.h"

// A header- and constexpr-safe version of PW_CHECK().
//
Expand Down
3 changes: 3 additions & 0 deletions pw_assert_basic/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pw_facade("handler") {
public = [ "public/pw_assert_basic/handler.h" ]
}

# TODO(pwbug/246): This backend implements pw_assert's check backend and the
# temporary compatibility C ABI (pw_assert_HandleFailure()).
#
# pw_assert_basic only provides the backend's interface. The implementation is
# pulled in through pw_build_LINK_DEPS.
pw_source_set("pw_assert_basic") {
Expand Down
13 changes: 6 additions & 7 deletions pw_assert_log/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ package(default_visibility = ["//visibility:public"])
licenses(["notice"])

pw_cc_library(
name = "pw_assert_log",
name = "check_backend",
srcs = [
"assert_log.cc",
],
hdrs = [
"check_backend_public_overrides/pw_assert_backend/check_backend.h",
"public/pw_assert_log/assert_log.h",
"public_overrides/pw_assert_backend/check_backend.h",
],
includes = [
"check_backend_public_overrides",
"public",
"public_overrides",
],
deps = [
"//pw_assert:facade",
Expand All @@ -42,13 +42,12 @@ pw_cc_library(
)

pw_cc_library(
name = "lite_backend",
name = "assert_backend",
hdrs = [
"assert_lite_public_overrides/pw_assert_backend/assert_lite_backend.h",
"public/pw_assert_log/assert_lite_log.h",
"assert_backend_public_overrides/pw_assert_backend/assert_backend.h",
],
includes = [
"assert_lite_public_overrides",
"assert_backend_public_overrides",
"public",
],
deps = [
Expand Down
44 changes: 25 additions & 19 deletions pw_assert_log/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,64 @@ import("//build_overrides/pigweed.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")

config("default_config") {
config("public_include_path") {
include_dirs = [ "public" ]
}

config("backend_config") {
include_dirs = [ "public_overrides" ]
config("check_backend_overrides") {
include_dirs = [ "check_backend_public_overrides" ]
}

config("lite_backend_overrides") {
include_dirs = [ "assert_lite_public_overrides" ]
config("assert_backend_overrides") {
include_dirs = [ "assert_backend_public_overrides" ]
}

# This backend to pw_assert's PW_CHECK()/PW_CRASH() macros via PW_LOG.
pw_source_set("pw_assert_log") {
# This target provides a backend to pw_assert's check facade
# (PW_CHECK()/PW_CRASH() macros) and assert compatibility C ABI
# (the pw_assert_HandleFailure() function) via PW_LOG.
pw_source_set("check_backend") {
public_configs = [
":backend_config",
":default_config",
":check_backend_overrides",
":public_include_path",
]
public_deps = [ "$dir_pw_log" ]
public = [ "public_overrides/pw_assert_backend/check_backend.h" ]
public =
[ "check_backend_public_overrides/pw_assert_backend/check_backend.h" ]
deps = [
"$dir_pw_assert:config",
"$dir_pw_assert:facade",
"$dir_pw_preprocessor",
]
sources = [
# TODO(pwbug/246): assert_log.cc implements the assert compatibility
# backend, but nothing for check_backend.
"assert_log.cc",
"public/pw_assert_log/assert_log.h",
]
}

# TODO(pwbug/246): Remove this deprecated alias.
group("pw_assert_log") {
public_deps = [ ":check_backend" ]
}

# This backend to pw_assert's PW_ASSERT() macros via PW_LOG. It is intended only
# for use with PW_LOG backends which are constexpr compatible such as
# pw_log_android.
#
# Warning: The "lite" naming is transitional. assert_lite_backend.h headers
# will be renamed as the pw_assert API is reassessed. (pwbug/246)
pw_source_set("lite_backend") {
pw_source_set("assert_backend") {
public_configs = [
":lite_backend_overrides",
":default_config",
":assert_backend_overrides",
":public_include_path",
]
public_deps = [
"$dir_pw_log",
"$dir_pw_preprocessor",
]
public =
[ "assert_lite_public_overrides/pw_assert_backend/assert_lite_backend.h" ]
sources = [ "public/pw_assert_log/assert_lite_log.h" ]
[ "assert_backend_public_overrides/pw_assert_backend/assert_backend.h" ]
}

group("lite_backend.impl") {
group("assert_backend.impl") {
}

# pw_assert_log doesn't have deps with potential circular dependencies, so this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@
// (though only pw_assert/check.h can only point to 1 backend).
#pragma once

#include "pw_assert_log/assert_lite_log.h"
#include "pw_log/levels.h"
#include "pw_log/log.h"
#include "pw_log/options.h"
#include "pw_preprocessor/compiler.h"

#define PW_ASSERT_HANDLE_FAILURE(condition_string) \
do { \
PW_LOG( \
PW_LOG_LEVEL_FATAL, PW_LOG_FLAGS, "Assert failed: " condition_string); \
PW_UNREACHABLE; \
} while (0)
2 changes: 1 addition & 1 deletion pw_assert_tokenized/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pw_cc_library(
"log_handler.cc",
],
hdrs = [
"assert_public_overrides/pw_assert_backend/assert_lite_backend.h",
"assert_public_overrides/pw_assert_backend/assert_backend.h",
"check_public_overrides/pw_assert_backend/check_backend.h",
"public/pw_assert_tokenized/assert_tokenized.h",
"public/pw_assert_tokenized/check_tokenized.h",
Expand Down
2 changes: 1 addition & 1 deletion pw_assert_tokenized/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pw_source_set("assert_backend") {
"$dir_pw_tokenizer",
]
public = [
"assert_public_overrides/pw_assert_backend/assert_lite_backend.h",
"assert_public_overrides/pw_assert_backend/assert_backend.h",
"public/pw_assert_tokenized/assert_tokenized.h",
]
}
Expand Down
2 changes: 2 additions & 0 deletions pw_assert_zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ if(NOT CONFIG_PIGWEED_ASSERT)
return()
endif()

# TODO(pwbug/246): This backend implements pw_assert's check backend and the
# temporary compatibility C ABI (pw_assert_HandleFailure()).
pw_auto_add_simple_module(pw_assert_zephyr
IMPLEMENTS_FACADE
pw_assert
Expand Down
4 changes: 2 additions & 2 deletions targets/host/target_toolchains.gni
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _host_common = {

# Configure backend for assert facade.
pw_assert_BACKEND = "$dir_pw_assert_basic"
pw_assert_LITE_BACKEND = "$dir_pw_assert:print_and_abort_lite_backend"
pw_assert_LITE_BACKEND = "$dir_pw_assert:print_and_abort_assert_backend"

# Configure backend for logging facade.
pw_log_BACKEND = "$dir_pw_log_basic"
Expand Down Expand Up @@ -389,7 +389,7 @@ pw_internal_host_toolchains = [
default_configs += _clang_default_configs
default_configs += [ "$dir_pw_build:cpp14" ]

pw_assert_BACKEND = "$dir_pw_assert:print_and_abort_backend"
pw_assert_BACKEND = "$dir_pw_assert:print_and_abort_check_backend"
pw_log_BACKEND = "$dir_pw_log_null"
pw_unit_test_MAIN = "$dir_pw_unit_test:printf_main"
}
Expand Down

0 comments on commit e072181

Please sign in to comment.