blob: bf65d47a54125cc10420d274c5a9a087508a0954 [file] [log] [blame]
Keir Mierle3cee8792020-01-22 17:08:13 -08001# Copyright 2020 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
Armando Montanezfb3d3fb2020-06-09 18:12:12 -070015# gn-format disable
16import("//build_overrides/pigweed.gni")
17
Keir Mierle3cee8792020-01-22 17:08:13 -080018import("$dir_pw_build/facade.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_unit_test/test.gni")
Alexei Frolov4c0428a2020-06-10 10:46:04 -070021declare_args() {
22 # Backend for the pw_assert module.
23 pw_assert_BACKEND = ""
24}
25
Keir Mierle3cee8792020-01-22 17:08:13 -080026config("default_config") {
27 include_dirs = [ "public" ]
28}
29
30pw_facade("pw_assert") {
Alexei Frolov4c0428a2020-06-10 10:46:04 -070031 backend = pw_assert_BACKEND
Keir Mierle3cee8792020-01-22 17:08:13 -080032 public_configs = [ ":default_config" ]
Keir Mierled1211ed2020-04-03 13:20:46 -070033 public = [
34 "public/pw_assert/assert.h",
35 "public/pw_assert/internal/assert_impl.h",
36 ]
Keir Mierle854adec2020-09-03 14:07:19 -070037 public_deps = [
38 dir_pw_preprocessor,
39
40 # Also expose light.h to all users of pw_assert.
41 ":light",
42 ]
43}
44
45# Provide a way include "pw_assert/light.h" without depending on the full
46# assert facade. This enables relying on light asserts from low-level headers
47# like polyfill or span that might trigger circular includes due to the
48# backend.
49#
50# See the docs for more discussion around where to use which assert system.
51pw_source_set("light") {
52 public_configs = [ ":default_config" ]
53 public = [
54 "public/pw_assert/light.h",
55
56 # Needed for PW_ASSERT_ENABLE_DEBUG. Note that depending on :pw_assert to
57 # get options.h won't work here since it will trigger the circular include
58 # problem that light asserts are designed to solve.
59 "public/pw_assert/options.h",
60 ]
61}
62
63# Note: While this is technically a test, doesn't verify any of the output and
64# is more of a compile test. The results can be visually verified if desired.
65pw_test("light_test") {
66 configs = [ ":default_config" ]
67 sources = [ "light_test.cc" ]
68 deps = [ ":pw_assert" ]
Keir Mierle3cee8792020-01-22 17:08:13 -080069}
70
71pw_test_group("tests") {
Armando Montanezceb66f52020-06-04 12:56:38 -070072 tests = [
73 ":assert_backend_compile_test",
74 ":assert_facade_test",
Keir Mierle854adec2020-09-03 14:07:19 -070075 ":light_test",
Armando Montanezceb66f52020-06-04 12:56:38 -070076 ]
Keir Mierle3cee8792020-01-22 17:08:13 -080077}
78
Keir Mierle8d2a84f2020-04-14 22:00:00 -070079# The assert facade test doesn't require a backend since a fake one is
Keir Mierle854adec2020-09-03 14:07:19 -070080# provided. However, since this doesn't depend on the backend it re-includes
Keir Mierle8d2a84f2020-04-14 22:00:00 -070081# the facade headers.
82pw_test("assert_facade_test") {
83 configs = [ ":default_config" ] # For internal/assert_impl.h
84 sources = [
85 "assert_facade_test.cc",
86 "fake_backend.cc",
87 "public/pw_assert/internal/assert_impl.h",
88 "pw_assert_test/fake_backend.h",
89 ]
Keir Mierle854adec2020-09-03 14:07:19 -070090 deps = [
91 ":light",
92 dir_pw_status,
93 ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -070094
95 # TODO(frolv): Fix this test on the QEMU target.
Alexei Frolov4c0428a2020-06-10 10:46:04 -070096 enable_if = pw_build_EXECUTABLE_TARGET_TYPE != "lm3s6965evb_executable"
Keir Mierle8d2a84f2020-04-14 22:00:00 -070097}
98
Armando Montanezceb66f52020-06-04 12:56:38 -070099pw_test("assert_backend_compile_test") {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700100 enable_if = pw_assert_BACKEND != ""
Armando Montanezceb66f52020-06-04 12:56:38 -0700101 deps = [
102 ":pw_assert",
Keir Mierle0fa7f7d2020-05-07 12:34:00 -0700103 dir_pw_status,
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700104 pw_assert_BACKEND,
Armando Montanezceb66f52020-06-04 12:56:38 -0700105 ]
106 sources = [
Armando Montanezceb66f52020-06-04 12:56:38 -0700107 "assert_backend_compile_test.cc",
Michael Spanga99220e2020-06-11 20:07:16 -0400108 "assert_backend_compile_test_c.c",
Armando Montanezceb66f52020-06-04 12:56:38 -0700109 ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800110}
111
112pw_doc_group("docs") {
Rob Mohra0ba54f2020-02-27 11:43:49 -0800113 sources = [ "docs.rst" ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800114}