Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 1 | # Copyright 2021 The Pigweed Authors |
Keir Mierle | 3cee879 | 2020-01-22 17:08:13 -0800 | [diff] [blame] | 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 Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 15 | import("//build_overrides/pigweed.gni") |
| 16 | |
Keir Mierle | 3cee879 | 2020-01-22 17:08:13 -0800 | [diff] [blame] | 17 | import("$dir_pw_build/facade.gni") |
| 18 | import("$dir_pw_docgen/docs.gni") |
| 19 | import("$dir_pw_unit_test/test.gni") |
Wyatt Hepler | d49f8fe | 2020-10-15 10:13:47 -0700 | [diff] [blame] | 20 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 21 | declare_args() { |
| 22 | # Backend for the pw_assert module. |
| 23 | pw_assert_BACKEND = "" |
| 24 | } |
| 25 | |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 26 | config("public_include_path") { |
Keir Mierle | 3cee879 | 2020-01-22 17:08:13 -0800 | [diff] [blame] | 27 | include_dirs = [ "public" ] |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 28 | visibility = [ ":*" ] |
Keir Mierle | 3cee879 | 2020-01-22 17:08:13 -0800 | [diff] [blame] | 29 | } |
| 30 | |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 31 | # Depending on dir_pw_assert provides both assert and check. |
| 32 | group("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. |
| 41 | group("facade") { |
| 42 | public_deps = [ |
| 43 | ":assert", |
| 44 | ":check.facade", |
| 45 | ] |
| 46 | } |
| 47 | |
| 48 | group("pw_assert.facade") { |
| 49 | public_deps = [ ":facade" ] |
| 50 | } |
| 51 | |
| 52 | # Provides the rich PW_CHECK macros. |
| 53 | pw_facade("check") { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 54 | backend = pw_assert_BACKEND |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 55 | public_configs = [ ":public_include_path" ] |
Keir Mierle | d1211ed | 2020-04-03 13:20:46 -0700 | [diff] [blame] | 56 | public = [ |
Wyatt Hepler | a59998f | 2021-03-19 14:35:10 -0700 | [diff] [blame] | 57 | "public/pw_assert/check.h", |
| 58 | "public/pw_assert/internal/check_impl.h", |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 59 | "public/pw_assert/options.h", |
Wyatt Hepler | a59998f | 2021-03-19 14:35:10 -0700 | [diff] [blame] | 60 | "public/pw_assert/short.h", |
Keir Mierle | d1211ed | 2020-04-03 13:20:46 -0700 | [diff] [blame] | 61 | ] |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 62 | public_deps = [ dir_pw_preprocessor ] |
Wyatt Hepler | 6166322 | 2021-05-06 10:57:43 -0700 | [diff] [blame] | 63 | |
Wyatt Hepler | 1e36400 | 2021-05-06 17:44:03 -0700 | [diff] [blame] | 64 | require_link_deps = [ ":impl" ] |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 67 | # 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 Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 72 | # |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 73 | # 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. |
| 75 | pw_source_set("assert") { |
| 76 | public_configs = [ ":public_include_path" ] |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 77 | public = [ |
Wyatt Hepler | a59998f | 2021-03-19 14:35:10 -0700 | [diff] [blame] | 78 | "public/pw_assert/assert.h", |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 79 | |
| 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 Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 82 | # problem that the :assert target is intended solve. |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 83 | "public/pw_assert/options.h", |
| 84 | ] |
Wyatt Hepler | dd3e881 | 2020-09-29 11:14:28 -0700 | [diff] [blame] | 85 | public_deps = [ dir_pw_preprocessor ] |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Wyatt Hepler | 8bd4fb0 | 2021-05-03 15:30:58 -0700 | [diff] [blame] | 88 | # 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 Hepler | 6166322 | 2021-05-06 10:57:43 -0700 | [diff] [blame] | 92 | # This group ("$dir_pw_assert:impl") must listed in pw_build_LINK_DEPS if |
Wyatt Hepler | 8bd4fb0 | 2021-05-03 15:30:58 -0700 | [diff] [blame] | 93 | # pw_assert_BACKEND is set. |
| 94 | # |
Wyatt Hepler | 6166322 | 2021-05-06 10:57:43 -0700 | [diff] [blame] | 95 | # 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. |
| 98 | group("impl") { |
Wyatt Hepler | 8bd4fb0 | 2021-05-03 15:30:58 -0700 | [diff] [blame] | 99 | public_deps = [] |
| 100 | |
| 101 | if (pw_assert_BACKEND != "") { |
Wyatt Hepler | 6166322 | 2021-05-06 10:57:43 -0700 | [diff] [blame] | 102 | public_deps += |
| 103 | [ get_label_info(pw_assert_BACKEND, "label_no_toolchain") + ".impl" ] |
Wyatt Hepler | 8bd4fb0 | 2021-05-03 15:30:58 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 107 | # 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 Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 109 | pw_test("assert_test") { |
| 110 | configs = [ ":public_include_path" ] |
| 111 | sources = [ "assert_test.cc" ] |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 112 | deps = [ ":pw_assert" ] |
Keir Mierle | 3cee879 | 2020-01-22 17:08:13 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | pw_test_group("tests") { |
Armando Montanez | ceb66f5 | 2020-06-04 12:56:38 -0700 | [diff] [blame] | 116 | tests = [ |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 117 | ":assert_test", |
Armando Montanez | ceb66f5 | 2020-06-04 12:56:38 -0700 | [diff] [blame] | 118 | ":assert_backend_compile_test", |
| 119 | ":assert_facade_test", |
| 120 | ] |
Keir Mierle | 3cee879 | 2020-01-22 17:08:13 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Keir Mierle | 8d2a84f | 2020-04-14 22:00:00 -0700 | [diff] [blame] | 123 | # The assert facade test doesn't require a backend since a fake one is |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 124 | # provided. However, since this doesn't depend on the backend it re-includes |
Keir Mierle | 8d2a84f | 2020-04-14 22:00:00 -0700 | [diff] [blame] | 125 | # the facade headers. |
| 126 | pw_test("assert_facade_test") { |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 127 | configs = [ ":public_include_path" ] # For internal/assert_impl.h |
Keir Mierle | 8d2a84f | 2020-04-14 22:00:00 -0700 | [diff] [blame] | 128 | sources = [ |
| 129 | "assert_facade_test.cc", |
| 130 | "fake_backend.cc", |
Wyatt Hepler | a59998f | 2021-03-19 14:35:10 -0700 | [diff] [blame] | 131 | "public/pw_assert/internal/check_impl.h", |
Keir Mierle | 8d2a84f | 2020-04-14 22:00:00 -0700 | [diff] [blame] | 132 | "pw_assert_test/fake_backend.h", |
| 133 | ] |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 134 | deps = [ |
Wyatt Hepler | 3d0e315 | 2021-04-29 17:08:31 -0700 | [diff] [blame] | 135 | ":assert", |
Keir Mierle | 854adec | 2020-09-03 14:07:19 -0700 | [diff] [blame] | 136 | dir_pw_status, |
| 137 | ] |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 138 | |
| 139 | # TODO(frolv): Fix this test on the QEMU target. |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 140 | enable_if = pw_build_EXECUTABLE_TARGET_TYPE != "lm3s6965evb_executable" |
Keir Mierle | 8d2a84f | 2020-04-14 22:00:00 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Armando Montanez | ceb66f5 | 2020-06-04 12:56:38 -0700 | [diff] [blame] | 143 | pw_test("assert_backend_compile_test") { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 144 | enable_if = pw_assert_BACKEND != "" |
Armando Montanez | ceb66f5 | 2020-06-04 12:56:38 -0700 | [diff] [blame] | 145 | deps = [ |
| 146 | ":pw_assert", |
Keir Mierle | 0fa7f7d | 2020-05-07 12:34:00 -0700 | [diff] [blame] | 147 | dir_pw_status, |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 148 | pw_assert_BACKEND, |
Armando Montanez | ceb66f5 | 2020-06-04 12:56:38 -0700 | [diff] [blame] | 149 | ] |
| 150 | sources = [ |
Armando Montanez | ceb66f5 | 2020-06-04 12:56:38 -0700 | [diff] [blame] | 151 | "assert_backend_compile_test.cc", |
Michael Spang | a99220e | 2020-06-11 20:07:16 -0400 | [diff] [blame] | 152 | "assert_backend_compile_test_c.c", |
Armando Montanez | ceb66f5 | 2020-06-04 12:56:38 -0700 | [diff] [blame] | 153 | ] |
Keir Mierle | 3cee879 | 2020-01-22 17:08:13 -0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | pw_doc_group("docs") { |
Rob Mohr | a0ba54f | 2020-02-27 11:43:49 -0800 | [diff] [blame] | 157 | sources = [ "docs.rst" ] |
Keir Mierle | 3cee879 | 2020-01-22 17:08:13 -0800 | [diff] [blame] | 158 | } |