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