1# Copyright 2021 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("@rules_cc//cc:cc_library.bzl", "cc_library") 16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 17load("//pw_build:compatibility.bzl", "host_backend_alias", "incompatible_with_mcu") 18load("//pw_build:pw_facade.bzl", "pw_facade") 19load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 20 21package(default_visibility = ["//visibility:public"]) 22 23licenses(["notice"]) 24 25# TODO: pwbug.dev/328679085 - Remove this alias. 26cc_library( 27 name = "facade", 28 deps = [ 29 ":assert.facade", 30 ":check.facade", 31 ], 32) 33 34# A target exposing the interfaces of both "check" and "assert". We re-expose 35# the headers here instead of just putting "check" and "assert" in the deps to 36# avoid a layering check violation. 37cc_library( 38 name = "pw_assert", 39 hdrs = [ 40 "public/pw_assert/assert.h", 41 "public/pw_assert/check.h", 42 "public/pw_assert/internal/check_impl.h", 43 "public/pw_assert/short.h", 44 ], 45 deprecation = "This target will be removed soon; depend on //pw_assert:assert and/or //pw_assert:check instead.", 46 strip_include_prefix = "public", 47 tags = [ 48 "manual", 49 "noclangtidy", 50 ], 51 deps = [ 52 ":assert_backend", 53 ":check", 54 ":check_backend", 55 ":config", 56 "//pw_preprocessor", 57 ], 58) 59 60label_flag( 61 name = "backend", 62 build_setting_default = ":unspecified_backend", 63 deprecation = "This label flag is no longer depended on by anything and will be removed soon.", 64) 65 66host_backend_alias( 67 name = "unspecified_backend", 68 backend = "//pw_assert_basic", 69) 70 71label_flag( 72 name = "backend_impl", 73 build_setting_default = "//pw_assert_basic:impl", 74 # For internal tooling: go/build-cleaner/troubleshooting-faq#keep-dep 75 tags = ["keep_dep"], 76) 77 78pw_facade( 79 name = "check", 80 hdrs = [ 81 "public/pw_assert/check.h", 82 "public/pw_assert/internal/check_impl.h", 83 "public/pw_assert/short.h", 84 ], 85 backend = ":check_backend", 86 strip_include_prefix = "public", 87 tags = ["noclangtidy"], 88 deps = [ 89 ":config", 90 "//pw_preprocessor", 91 ], 92) 93 94label_flag( 95 name = "check_backend", 96 build_setting_default = ":unspecified_check_backend", 97) 98 99host_backend_alias( 100 name = "unspecified_check_backend", 101 backend = ":print_and_abort_check_backend", 102) 103 104label_flag( 105 name = "check_backend_impl", 106 build_setting_default = ":unspecified_check_backend_impl", 107) 108 109host_backend_alias( 110 name = "unspecified_check_backend_impl", 111 backend = "//pw_build:empty_cc_library", 112) 113 114pw_facade( 115 name = "assert", 116 hdrs = [ 117 "public/pw_assert/assert.h", 118 ], 119 backend = ":assert_backend", 120 strip_include_prefix = "public", 121 tags = ["noclangtidy"], 122 deps = [":config"], 123) 124 125label_flag( 126 name = "assert_backend", 127 build_setting_default = ":unspecified_assert_backend", 128) 129 130alias( 131 name = "unspecified_assert_backend", 132 actual = select({ 133 # Default backend for MCU build. 134 "@platforms//os:none": ":assert_compatibility_backend", 135 # Default backend for host build. 136 "//conditions:default": ":print_and_abort_assert_backend", 137 }), 138) 139 140label_flag( 141 name = "assert_backend_impl", 142 build_setting_default = "//pw_build:empty_cc_library", 143) 144 145cc_library( 146 name = "config", 147 hdrs = ["public/pw_assert/config.h"], 148 strip_include_prefix = "public", 149 deps = [":config_override"], 150) 151 152label_flag( 153 name = "config_override", 154 build_setting_default = "//pw_build:default_module_config", 155) 156 157cc_library( 158 name = "libc_assert", 159 hdrs = [ 160 "libc_assert_public_overrides/assert.h", 161 "libc_assert_public_overrides/cassert", 162 ], 163 strip_include_prefix = "libc_assert_public_overrides", 164 deps = [ 165 ":libc_assert_impl", 166 ], 167) 168 169cc_library( 170 name = "libc_assert_impl", 171 hdrs = [ 172 "public/pw_assert/internal/libc_assert.h", 173 ], 174 strip_include_prefix = "public", 175 visibility = ["//visibility:private"], 176 deps = [ 177 ":assert", 178 "//pw_preprocessor", 179 ], 180) 181 182cc_library( 183 name = "assert_compatibility_backend", 184 hdrs = [ 185 "assert_compatibility_public_overrides/pw_assert_backend/assert_backend.h", 186 ], 187 strip_include_prefix = "assert_compatibility_public_overrides", 188 deps = ["//pw_preprocessor"], 189) 190 191cc_library( 192 name = "print_and_abort", 193 hdrs = ["public/pw_assert/internal/print_and_abort.h"], 194 strip_include_prefix = "public", 195 visibility = ["//visibility:private"], 196 deps = [":config"], 197) 198 199cc_library( 200 name = "print_and_abort_assert_backend", 201 hdrs = ["print_and_abort_assert_public_overrides/pw_assert_backend/assert_backend.h"], 202 strip_include_prefix = "print_and_abort_assert_public_overrides", 203 deps = [ 204 ":config", 205 ":print_and_abort", 206 ], 207) 208 209cc_library( 210 name = "print_and_abort_check_backend", 211 hdrs = ["print_and_abort_check_public_overrides/pw_assert_backend/check_backend.h"], 212 strip_include_prefix = "print_and_abort_check_public_overrides", 213 deps = [":print_and_abort"], 214) 215 216cc_library( 217 name = "print_and_abort_assert_and_check_backend", 218 deps = [ 219 ":print_and_abort_assert_backend", 220 ":print_and_abort_check_backend", 221 ], 222) 223 224pw_cc_test( 225 name = "assert_facade_test", 226 srcs = [ 227 "assert_facade_test.cc", 228 "assert_test.cc", 229 "fake_backend.cc", 230 "public/pw_assert/internal/check_impl.h", 231 "pw_assert_test/fake_backend.h", 232 ], 233 tags = ["noclangtidy"], 234 deps = [ 235 ":assert", 236 ":config", 237 ":facade", 238 "//pw_compilation_testing:negative_compilation_testing", 239 "//pw_preprocessor", 240 "//pw_result", 241 "//pw_span", 242 "//pw_status", 243 "//pw_string:builder", 244 ], 245) 246 247pw_cc_test( 248 name = "assert_backend_compile_test", 249 srcs = [ 250 "assert_backend_compile_test.cc", 251 "assert_backend_compile_test_c.c", 252 ], 253 deps = [ 254 ":assert", 255 ":check", 256 "//pw_status", 257 ], 258) 259 260sphinx_docs_library( 261 name = "docs", 262 srcs = [ 263 "assert_test.cc", 264 "backends.rst", 265 "docs.rst", 266 ], 267 prefix = "pw_assert/", 268 target_compatible_with = incompatible_with_mcu(), 269) 270