blob: 7196831f5d6eac088f9e1d8a757ec3f58573d0ef [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 ]
Wyatt Hepler61663222021-05-06 10:57:43 -070063
64 # TODO(pwbug/372): Update projects to properly list pw_assert:impl.
65 # require_link_deps = [ ":impl" ]
Keir Mierle854adec2020-09-03 14:07:19 -070066}
67
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070068# Provide "pw_assert/assert.h" in its own source set, so it can be used without
69# depending on pw_assert_BACKEND. This makes it possible to use PW_ASSERT in
70# situations that might result in circular dependencies, such as in low-level
71# headers like polyfill or span. See the docs for more discussion around where
72# to use which assert headers.
Keir Mierle854adec2020-09-03 14:07:19 -070073#
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070074# The implementation function pw_assert_HandleFailure() must be provided at link
75# time. It is linked by the pw_assert:pw_assert (or pw_assert:check) targets.
76pw_source_set("assert") {
77 public_configs = [ ":public_include_path" ]
Keir Mierle854adec2020-09-03 14:07:19 -070078 public = [
Wyatt Heplera59998f2021-03-19 14:35:10 -070079 "public/pw_assert/assert.h",
Keir Mierle854adec2020-09-03 14:07:19 -070080
81 # Needed for PW_ASSERT_ENABLE_DEBUG. Note that depending on :pw_assert to
82 # get options.h won't work here since it will trigger the circular include
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070083 # problem that the :assert target is intended solve.
Keir Mierle854adec2020-09-03 14:07:19 -070084 "public/pw_assert/options.h",
85 ]
Wyatt Heplerdd3e8812020-09-29 11:14:28 -070086 public_deps = [ dir_pw_preprocessor ]
Keir Mierle854adec2020-09-03 14:07:19 -070087}
88
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -070089# pw_assert is low-level and ubiquitous. Because of this, it can often cause
90# circular dependencies. This target collects dependencies from the backend that
91# cannot be used because they would cause circular deps.
92#
Wyatt Hepler61663222021-05-06 10:57:43 -070093# This group ("$dir_pw_assert:impl") must listed in pw_build_LINK_DEPS if
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -070094# pw_assert_BACKEND is set.
95#
Wyatt Hepler61663222021-05-06 10:57:43 -070096# pw_assert backends must provide their own "impl" target that collects their
97# actual dependencies. The backend "impl" group may be empty if everything can
98# go directly in the backend target without causing circular dependencies.
99group("impl") {
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -0700100 public_deps = []
101
102 if (pw_assert_BACKEND != "") {
Wyatt Hepler61663222021-05-06 10:57:43 -0700103 public_deps +=
104 [ get_label_info(pw_assert_BACKEND, "label_no_toolchain") + ".impl" ]
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -0700105 }
106}
107
Keir Mierle854adec2020-09-03 14:07:19 -0700108# Note: While this is technically a test, doesn't verify any of the output and
109# is more of a compile test. The results can be visually verified if desired.
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700110pw_test("assert_test") {
111 configs = [ ":public_include_path" ]
112 sources = [ "assert_test.cc" ]
Keir Mierle854adec2020-09-03 14:07:19 -0700113 deps = [ ":pw_assert" ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800114}
115
116pw_test_group("tests") {
Armando Montanezceb66f52020-06-04 12:56:38 -0700117 tests = [
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700118 ":assert_test",
Armando Montanezceb66f52020-06-04 12:56:38 -0700119 ":assert_backend_compile_test",
120 ":assert_facade_test",
121 ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800122}
123
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700124# The assert facade test doesn't require a backend since a fake one is
Keir Mierle854adec2020-09-03 14:07:19 -0700125# provided. However, since this doesn't depend on the backend it re-includes
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700126# the facade headers.
127pw_test("assert_facade_test") {
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700128 configs = [ ":public_include_path" ] # For internal/assert_impl.h
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700129 sources = [
130 "assert_facade_test.cc",
131 "fake_backend.cc",
Wyatt Heplera59998f2021-03-19 14:35:10 -0700132 "public/pw_assert/internal/check_impl.h",
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700133 "pw_assert_test/fake_backend.h",
134 ]
Keir Mierle854adec2020-09-03 14:07:19 -0700135 deps = [
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700136 ":assert",
Keir Mierle854adec2020-09-03 14:07:19 -0700137 dir_pw_status,
138 ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700139
140 # TODO(frolv): Fix this test on the QEMU target.
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700141 enable_if = pw_build_EXECUTABLE_TARGET_TYPE != "lm3s6965evb_executable"
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700142}
143
Armando Montanezceb66f52020-06-04 12:56:38 -0700144pw_test("assert_backend_compile_test") {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700145 enable_if = pw_assert_BACKEND != ""
Armando Montanezceb66f52020-06-04 12:56:38 -0700146 deps = [
147 ":pw_assert",
Keir Mierle0fa7f7d2020-05-07 12:34:00 -0700148 dir_pw_status,
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700149 pw_assert_BACKEND,
Armando Montanezceb66f52020-06-04 12:56:38 -0700150 ]
151 sources = [
Armando Montanezceb66f52020-06-04 12:56:38 -0700152 "assert_backend_compile_test.cc",
Michael Spanga99220e2020-06-11 20:07:16 -0400153 "assert_backend_compile_test_c.c",
Armando Montanezceb66f52020-06-04 12:56:38 -0700154 ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800155}
156
157pw_doc_group("docs") {
Rob Mohra0ba54f2020-02-27 11:43:49 -0800158 sources = [ "docs.rst" ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800159}