1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 16 17package(default_visibility = ["//visibility:public"]) 18 19licenses(["notice"]) 20 21cc_library( 22 name = "config", 23 hdrs = ["public/pw_assert_trap/config.h"], 24 strip_include_prefix = "public", 25) 26 27# Note: to avoid circular dependencies, this target only includes the headers 28# for pw_assert_trap. The source file and its dependencies are in the separate 29# ":impl" target. 30# 31# If you point //pw_assert:check_backend and //pw_assert:assert_backend to 32# //pw_assert_trap, then //pw_assert:check_backend_impl and 33# //pw_assert:assert_backend_impl should point to //pw_assert_trap:impl. 34cc_library( 35 name = "pw_assert_trap", 36 hdrs = [ 37 "assert_public_overrides/pw_assert_backend/assert_backend.h", 38 "check_public_overrides/pw_assert_backend/check_backend.h", 39 "public/pw_assert_trap/assert_trap.h", 40 "public/pw_assert_trap/check_trap.h", 41 ], 42 includes = [ 43 "assert_public_overrides", 44 "check_public_overrides", 45 "public", 46 ], 47 deps = [ 48 ":handler", 49 "//pw_assert:check.facade", 50 "//pw_preprocessor", 51 ], 52) 53 54cc_library( 55 name = "handler", 56 hdrs = [ 57 "public/pw_assert_trap/handler.h", 58 ], 59 strip_include_prefix = "public", 60 deps = [ 61 "//pw_preprocessor", 62 ], 63) 64 65cc_library( 66 name = "message", 67 hdrs = [ 68 "public/pw_assert_trap/message.h", 69 ], 70 strip_include_prefix = "public", 71 deps = [ 72 "//pw_string:string", 73 ], 74) 75 76cc_library( 77 name = "impl", 78 srcs = [ 79 "trap_handler.cc", 80 ], 81 copts = ["-Wno-thread-safety-analysis"], 82 deps = [ 83 ":config", 84 ":handler", 85 ":message", 86 "//pw_string:builder", 87 "//pw_sync:interrupt_spin_lock", 88 ], 89 # Other libraries may not always depend on this library, even if it is 90 # necessary at link time. 91 alwayslink = 1, 92) 93 94cc_library( 95 name = "assert_backend", 96 hdrs = [ 97 "assert_public_overrides/pw_assert_backend/assert_backend.h", 98 "public/pw_assert_trap/assert_tokenized.h", 99 ], 100 deps = [ 101 ":handler", 102 ], 103) 104 105cc_library( 106 name = "check_backend", 107 hdrs = [ 108 "check_public_overrides/pw_assert_backend/check_backend.h", 109 "public/pw_assert_trap/check_tokenized.h", 110 ], 111 deps = [ 112 ":handler", 113 ], 114) 115 116# provide a test implementation which is compiled with a different set of 117# defines to allow unittesting. 118cc_library( 119 name = "impl_test", 120 srcs = [ 121 "trap_handler.cc", 122 ], 123 copts = ["-Wno-thread-safety-analysis"], 124 defines = [ 125 # Disable the trap to allow testing to continue 126 "_PW_ASSERT_TRAP_DISABLE_TRAP_FOR_TESTING=1", 127 # Disable the capture of location info to ensure tests are portable 128 "PW_ASSERT_TRAP_DISABLE_LOCATION_CAPTURE=1", 129 ], 130 visibility = ["//visibility:private"], 131 deps = [ 132 ":config", 133 ":handler", 134 ":message", 135 "//pw_string:builder", 136 "//pw_sync:interrupt_spin_lock", 137 ], 138) 139 140pw_cc_test( 141 name = "handler_test", 142 srcs = [ 143 "trap_handler_test.cc", 144 ], 145 # TODO: https://pwbug.dev/351889230 - this fails when trap is the used 146 # as the system assert backend, so disable and only run manually. 147 tags = ["manual"], 148 deps = [ 149 ":impl_test", 150 ":pw_assert_trap", 151 ], 152) 153