• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("@rules_cc//cc:cc_library.bzl", "cc_library")
16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
17load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
18load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
19
20package(default_visibility = ["//visibility:public"])
21
22licenses(["notice"])
23
24cc_library(
25    name = "config",
26    hdrs = ["public/pw_assert_trap/config.h"],
27    strip_include_prefix = "public",
28)
29
30cc_library(
31    name = "handler",
32    hdrs = [
33        "public/pw_assert_trap/handler.h",
34    ],
35    strip_include_prefix = "public",
36    deps = [
37        "//pw_preprocessor",
38    ],
39)
40
41cc_library(
42    name = "message",
43    hdrs = [
44        "public/pw_assert_trap/message.h",
45    ],
46    strip_include_prefix = "public",
47    deps = [
48        "//pw_string:string",
49    ],
50)
51
52cc_library(
53    name = "impl",
54    srcs = [
55        "trap_handler.cc",
56    ],
57    copts = ["-Wno-thread-safety-analysis"],
58    deps = [
59        ":config",
60        ":handler",
61        ":message",
62        "//pw_string:builder",
63        "//pw_sync:interrupt_spin_lock",
64    ],
65    # Other libraries may not always depend on this library, even if it is
66    # necessary at link time.
67    alwayslink = 1,
68)
69
70cc_library(
71    name = "assert_backend",
72    hdrs = [
73        "assert_public_overrides/pw_assert_backend/assert_backend.h",
74    ],
75    strip_include_prefix = "assert_public_overrides",
76    deps = [
77        ":assert_backend_private",
78    ],
79)
80
81cc_library(
82    name = "assert_backend_private",
83    hdrs = [
84        "public/pw_assert_trap/assert_trap.h",
85    ],
86    strip_include_prefix = "public",
87    visibility = ["//visibility:private"],
88    deps = [
89        ":handler",
90    ],
91)
92
93cc_library(
94    name = "check_backend",
95    hdrs = [
96        "check_public_overrides/pw_assert_backend/check_backend.h",
97    ],
98    strip_include_prefix = "check_public_overrides",
99    deps = [
100        ":check_backend_private",
101    ],
102)
103
104cc_library(
105    name = "check_backend_private",
106    hdrs = [
107        "public/pw_assert_trap/check_trap.h",
108    ],
109    strip_include_prefix = "public",
110    visibility = ["//visibility:private"],
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 test will fail to build on any
146    # platform that sets the pw_assert backend to //pw_assert_trap. To be safe,
147    # disable it for any MCU platform. But run it on the host, where the assert
148    # backend is pw_assert_basic.
149    target_compatible_with = incompatible_with_mcu(),
150    deps = [
151        ":check_backend_private",
152        ":impl_test",
153        ":message",
154    ],
155)
156
157sphinx_docs_library(
158    name = "docs",
159    srcs = [
160        "docs.rst",
161    ],
162    prefix = "pw_assert_trap/",
163    target_compatible_with = incompatible_with_mcu(),
164)
165