blob: 258cd13ef8bf4bb2ed03c5c70c375bd683296d2f [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
Wyatt Hepler1e364002021-05-06 17:44:03 -070064 require_link_deps = [ ":impl" ]
Keir Mierle854adec2020-09-03 14:07:19 -070065}
66
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070067# Provide "pw_assert/assert.h" in its own source set, so it can be used without
68# depending on pw_assert_BACKEND. This makes it possible to use PW_ASSERT in
69# situations that might result in circular dependencies, such as in low-level
70# headers like polyfill or span. See the docs for more discussion around where
71# to use which assert headers.
Keir Mierle854adec2020-09-03 14:07:19 -070072#
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070073# The implementation function pw_assert_HandleFailure() must be provided at link
74# time. It is linked by the pw_assert:pw_assert (or pw_assert:check) targets.
75pw_source_set("assert") {
76 public_configs = [ ":public_include_path" ]
Keir Mierle854adec2020-09-03 14:07:19 -070077 public = [
Wyatt Heplera59998f2021-03-19 14:35:10 -070078 "public/pw_assert/assert.h",
Keir Mierle854adec2020-09-03 14:07:19 -070079
80 # Needed for PW_ASSERT_ENABLE_DEBUG. Note that depending on :pw_assert to
81 # get options.h won't work here since it will trigger the circular include
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070082 # problem that the :assert target is intended solve.
Keir Mierle854adec2020-09-03 14:07:19 -070083 "public/pw_assert/options.h",
84 ]
Wyatt Heplerdd3e8812020-09-29 11:14:28 -070085 public_deps = [ dir_pw_preprocessor ]
Keir Mierle854adec2020-09-03 14:07:19 -070086}
87
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -070088# pw_assert is low-level and ubiquitous. Because of this, it can often cause
89# circular dependencies. This target collects dependencies from the backend that
90# cannot be used because they would cause circular deps.
91#
Wyatt Hepler61663222021-05-06 10:57:43 -070092# This group ("$dir_pw_assert:impl") must listed in pw_build_LINK_DEPS if
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -070093# pw_assert_BACKEND is set.
94#
Wyatt Hepler61663222021-05-06 10:57:43 -070095# pw_assert backends must provide their own "impl" target that collects their
96# actual dependencies. The backend "impl" group may be empty if everything can
97# go directly in the backend target without causing circular dependencies.
98group("impl") {
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -070099 public_deps = []
100
101 if (pw_assert_BACKEND != "") {
Wyatt Hepler61663222021-05-06 10:57:43 -0700102 public_deps +=
103 [ get_label_info(pw_assert_BACKEND, "label_no_toolchain") + ".impl" ]
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -0700104 }
105}
106
Keir Mierle854adec2020-09-03 14:07:19 -0700107# Note: While this is technically a test, doesn't verify any of the output and
108# is more of a compile test. The results can be visually verified if desired.
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700109pw_test("assert_test") {
110 configs = [ ":public_include_path" ]
111 sources = [ "assert_test.cc" ]
Keir Mierle854adec2020-09-03 14:07:19 -0700112 deps = [ ":pw_assert" ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800113}
114
115pw_test_group("tests") {
Armando Montanezceb66f52020-06-04 12:56:38 -0700116 tests = [
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700117 ":assert_test",
Armando Montanezceb66f52020-06-04 12:56:38 -0700118 ":assert_backend_compile_test",
119 ":assert_facade_test",
120 ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800121}
122
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700123# The assert facade test doesn't require a backend since a fake one is
Keir Mierle854adec2020-09-03 14:07:19 -0700124# provided. However, since this doesn't depend on the backend it re-includes
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700125# the facade headers.
126pw_test("assert_facade_test") {
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700127 configs = [ ":public_include_path" ] # For internal/assert_impl.h
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700128 sources = [
129 "assert_facade_test.cc",
130 "fake_backend.cc",
Wyatt Heplera59998f2021-03-19 14:35:10 -0700131 "public/pw_assert/internal/check_impl.h",
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700132 "pw_assert_test/fake_backend.h",
133 ]
Keir Mierle854adec2020-09-03 14:07:19 -0700134 deps = [
Wyatt Hepler3d0e3152021-04-29 17:08:31 -0700135 ":assert",
Keir Mierle854adec2020-09-03 14:07:19 -0700136 dir_pw_status,
137 ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700138
139 # TODO(frolv): Fix this test on the QEMU target.
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700140 enable_if = pw_build_EXECUTABLE_TARGET_TYPE != "lm3s6965evb_executable"
Keir Mierle8d2a84f2020-04-14 22:00:00 -0700141}
142
Armando Montanezceb66f52020-06-04 12:56:38 -0700143pw_test("assert_backend_compile_test") {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700144 enable_if = pw_assert_BACKEND != ""
Armando Montanezceb66f52020-06-04 12:56:38 -0700145 deps = [
146 ":pw_assert",
Keir Mierle0fa7f7d2020-05-07 12:34:00 -0700147 dir_pw_status,
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700148 pw_assert_BACKEND,
Armando Montanezceb66f52020-06-04 12:56:38 -0700149 ]
150 sources = [
Armando Montanezceb66f52020-06-04 12:56:38 -0700151 "assert_backend_compile_test.cc",
Michael Spanga99220e2020-06-11 20:07:16 -0400152 "assert_backend_compile_test_c.c",
Armando Montanezceb66f52020-06-04 12:56:38 -0700153 ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800154}
155
156pw_doc_group("docs") {
Rob Mohra0ba54f2020-02-27 11:43:49 -0800157 sources = [ "docs.rst" ]
Keir Mierle3cee8792020-01-22 17:08:13 -0800158}