blob: 2b78c00a30ce23a9bf0128517c51af52fe0c745e [file] [log] [blame]
Wyatt Hepler3d0e3152021-04-29 17:08:31 -07001# Copyright 2021 The Pigweed Authors
Keir Mierle3cee8792020-01-22 17:08:13 -08002#
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 -070015import("//build_overrides/pigweed.gni")
16
Keir Mierle3cee8792020-01-22 17:08:13 -080017import("$dir_pw_build/facade.gni")
18import("$dir_pw_docgen/docs.gni")
19import("$dir_pw_unit_test/test.gni")
Wyatt Heplerd49f8fe2020-10-15 10:13:47 -070020
Alexei Frolov4c0428a2020-06-10 10:46:04 -070021declare_args() {
22 # Backend for the pw_assert module.
23 pw_assert_BACKEND = ""
24}
25
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070026config("public_include_path") {
Keir Mierle3cee8792020-01-22 17:08:13 -080027 include_dirs = [ "public" ]
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070028 visibility = [ ":*" ]
Keir Mierle3cee8792020-01-22 17:08:13 -080029}
30
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070031# Depending on dir_pw_assert provides both assert and check.
32group("pw_assert") {
33 public_deps = [
34 ":assert",
35 ":check",
36 ]
37}
38
39# Wrap :pw_assert with facade-style targets, so it can be used as if it were
40# created with pw_facade.
41group("facade") {
42 public_deps = [
43 ":assert",
44 ":check.facade",
45 ]
46}
47
48group("pw_assert.facade") {
49 public_deps = [ ":facade" ]
50}
51
52# Provides the rich PW_CHECK macros.
53pw_facade("check") {
Alexei Frolov4c0428a2020-06-10 10:46:04 -070054 backend = pw_assert_BACKEND
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070055 public_configs = [ ":public_include_path" ]
Keir Mierled1211ed2020-04-03 13:20:46 -070056 public = [
Wyatt Heplera59998f2021-03-19 14:35:10 -070057 "public/pw_assert/check.h",
58 "public/pw_assert/internal/check_impl.h",
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070059 "public/pw_assert/options.h",
Wyatt Heplera59998f2021-03-19 14:35:10 -070060 "public/pw_assert/short.h",
Keir Mierled1211ed2020-04-03 13:20:46 -070061 ]
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070062 public_deps = [ dir_pw_preprocessor ]
Keir Mierle854adec2020-09-03 14:07:19 -070063}
64
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070065# Provide "pw_assert/assert.h" in its own source set, so it can be used without
66# depending on pw_assert_BACKEND. This makes it possible to use PW_ASSERT in
67# situations that might result in circular dependencies, such as in low-level
68# headers like polyfill or span. See the docs for more discussion around where
69# to use which assert headers.
Keir Mierle854adec2020-09-03 14:07:19 -070070#
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070071# The implementation function pw_assert_HandleFailure() must be provided at link
72# time. It is linked by the pw_assert:pw_assert (or pw_assert:check) targets.
73pw_source_set("assert") {
74 public_configs = [ ":public_include_path" ]
Keir Mierle854adec2020-09-03 14:07:19 -070075 public = [
Wyatt Heplera59998f2021-03-19 14:35:10 -070076 "public/pw_assert/assert.h",
Keir Mierle854adec2020-09-03 14:07:19 -070077
78 # Needed for PW_ASSERT_ENABLE_DEBUG. Note that depending on :pw_assert to
79 # get options.h won't work here since it will trigger the circular include
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070080 # problem that the :assert target is intended solve.
Keir Mierle854adec2020-09-03 14:07:19 -070081 "public/pw_assert/options.h",
82 ]
Wyatt Heplerdd3e8812020-09-29 11:14:28 -070083 public_deps = [ dir_pw_preprocessor ]
Keir Mierle854adec2020-09-03 14:07:19 -070084}
85
86# Note: While this is technically a test, doesn't verify any of the output and
87# is more of a compile test. The results can be visually verified if desired.
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070088pw_test("assert_test") {
89 configs = [ ":public_include_path" ]
90 sources = [ "assert_test.cc" ]
Keir Mierle854adec2020-09-03 14:07:19 -070091 deps = [ ":pw_assert" ]
Keir Mierle3cee8792020-01-22 17:08:13 -080092}
93
94pw_test_group("tests") {
Armando Montanezceb66f52020-06-04 12:56:38 -070095 tests = [
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070096 ":assert_test",
Armando Montanezceb66f52020-06-04 12:56:38 -070097 ":assert_backend_compile_test",
98 ":assert_facade_test",
99 ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800100}
101
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700102# The assert facade test doesn't require a backend since a fake one is
Keir Mierle854adec2020-09-03 14:07:19 -0700103# provided. However, since this doesn't depend on the backend it re-includes
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700104# the facade headers.
105pw_test("assert_facade_test") {
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700106 configs = [ ":public_include_path" ] # For internal/assert_impl.h
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700107 sources = [
108 "assert_facade_test.cc",
109 "fake_backend.cc",
Wyatt Heplera59998f2021-03-19 14:35:10 -0700110 "public/pw_assert/internal/check_impl.h",
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700111 "pw_assert_test/fake_backend.h",
112 ]
Keir Mierle854adec2020-09-03 14:07:19 -0700113 deps = [
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700114 ":assert",
Keir Mierle854adec2020-09-03 14:07:19 -0700115 dir_pw_status,
116 ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700117
118 # TODO(frolv): Fix this test on the QEMU target.
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700119 enable_if = pw_build_EXECUTABLE_TARGET_TYPE != "lm3s6965evb_executable"
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700120}
121
Armando Montanezceb66f52020-06-04 12:56:38 -0700122pw_test("assert_backend_compile_test") {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700123 enable_if = pw_assert_BACKEND != ""
Armando Montanezceb66f52020-06-04 12:56:38 -0700124 deps = [
125 ":pw_assert",
Keir Mierle0fa7f7d2020-05-07 12:34:00 -0700126 dir_pw_status,
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700127 pw_assert_BACKEND,
Armando Montanezceb66f52020-06-04 12:56:38 -0700128 ]
129 sources = [
Armando Montanezceb66f52020-06-04 12:56:38 -0700130 "assert_backend_compile_test.cc",
Michael Spanga99220e2020-06-11 20:07:16 -0400131 "assert_backend_compile_test_c.c",
Armando Montanezceb66f52020-06-04 12:56:38 -0700132 ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800133}
134
135pw_doc_group("docs") {
Rob Mohra0ba54f2020-02-27 11:43:49 -0800136 sources = [ "docs.rst" ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800137}