blob: 71f7f3695968cce63cc7a4a8d667b7f7f4218358 [file] [log] [blame]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -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
Wyatt Hepler6639c452020-05-06 11:43:07 -070018import("$dir_pw_build/facade.gni")
Alexei Frolovedd2f142020-06-09 19:11:27 -070019import("$dir_pw_build/target_types.gni")
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080020import("$dir_pw_docgen/docs.gni")
karthik bharadwajeabe9a22020-04-14 09:28:28 -070021import("$dir_pw_fuzzer/fuzzer.gni")
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080022import("$dir_pw_unit_test/test.gni")
Alexei Frolov4c0428a2020-06-10 10:46:04 -070023import("backend.gni")
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080024config("default_config") {
25 include_dirs = [ "public" ]
26}
27
Alexei Frolovedd2f142020-06-09 19:11:27 -070028pw_source_set("pw_tokenizer") {
Wyatt Hepler21192402020-01-15 15:40:51 -080029 public_configs = [ ":default_config" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080030 public_deps = [
Wyatt Hepler6639c452020-05-06 11:43:07 -070031 dir_pw_preprocessor,
32 dir_pw_span,
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080033 ]
Wyatt Hepler6639c452020-05-06 11:43:07 -070034 deps = [ dir_pw_varint ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080035 public = [
36 "public/pw_tokenizer/pw_tokenizer_65599_fixed_length_hash.h",
37 "public/pw_tokenizer/tokenize.h",
38 ]
39 sources = [
Wyatt Hepler6639c452020-05-06 11:43:07 -070040 "encode_args.cc",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080041 "public/pw_tokenizer/config.h",
42 "public/pw_tokenizer/internal/argument_types.h",
43 "public/pw_tokenizer/internal/argument_types_macro_4_byte.h",
44 "public/pw_tokenizer/internal/argument_types_macro_8_byte.h",
45 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_128_hash_macro.h",
46 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_80_hash_macro.h",
47 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_96_hash_macro.h",
48 "public/pw_tokenizer/internal/tokenize_string.h",
Wyatt Hepler6639c452020-05-06 11:43:07 -070049 "pw_tokenizer_private/encode_args.h",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080050 "tokenize.cc",
51 ]
Wyatt Heplera8557ef2020-05-04 16:29:23 -070052 friend = [ ":*" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -080053}
54
Wyatt Hepler6639c452020-05-06 11:43:07 -070055# As a temporary workaround, if no backend is set, use an empty test backend so
56# that the test can define the handler function.
57# TODO(hepler): Switch this to a facade test when available.
Alexei Frolov4c0428a2020-06-10 10:46:04 -070058if (pw_tokenizer_GLOBAL_HANDLER_BACKEND == "" &&
59 pw_tokenizer_GLOBAL_HANDLER_WITH_PAYLOAD_BACKEND == "") {
Wyatt Hepler6639c452020-05-06 11:43:07 -070060 # This is an empty library to use as the backend for global_handler and
61 # global_handler_with_payload tests.
Alexei Frolovedd2f142020-06-09 19:11:27 -070062 pw_source_set("test_backend") {
Wyatt Hepler6639c452020-05-06 11:43:07 -070063 visibility = [ ":*" ]
64 }
65
Alexei Frolov4c0428a2020-06-10 10:46:04 -070066 pw_tokenizer_GLOBAL_HANDLER_BACKEND = ":test_backend"
67 pw_tokenizer_GLOBAL_HANDLER_WITH_PAYLOAD_BACKEND = ":test_backend"
Wyatt Hepler6639c452020-05-06 11:43:07 -070068
69 enable_global_handler_test = true
70} else {
71 enable_global_handler_test = false
72}
73
74pw_facade("global_handler") {
75 facade_name = "global_handler_facade"
Alexei Frolov4c0428a2020-06-10 10:46:04 -070076 backend = pw_tokenizer_GLOBAL_HANDLER_BACKEND
Wyatt Hepler6639c452020-05-06 11:43:07 -070077
78 public_configs = [ ":default_config" ]
79 public = [ "public/pw_tokenizer/tokenize_to_global_handler.h" ]
80 sources = [ "tokenize_to_global_handler.cc" ]
81 public_deps = [ ":pw_tokenizer" ]
82}
83
84pw_facade("global_handler_with_payload") {
85 facade_name = "global_handler_with_payload_facade"
Alexei Frolov4c0428a2020-06-10 10:46:04 -070086 backend = pw_tokenizer_GLOBAL_HANDLER_WITH_PAYLOAD_BACKEND
Wyatt Hepler6639c452020-05-06 11:43:07 -070087
88 public_configs = [ ":default_config" ]
89 public = [ "public/pw_tokenizer/tokenize_to_global_handler_with_payload.h" ]
90 sources = [ "tokenize_to_global_handler_with_payload.cc" ]
91 public_deps = [ ":pw_tokenizer" ]
92}
93
Alexei Frolovedd2f142020-06-09 19:11:27 -070094pw_source_set("base64") {
Wyatt Hepler21192402020-01-15 15:40:51 -080095 public_configs = [ ":default_config" ]
Rob Mohra0ba54f2020-02-27 11:43:49 -080096 public = [ "public/pw_tokenizer/base64.h" ]
Wyatt Heplera8557ef2020-05-04 16:29:23 -070097 sources = [ "base64.cc" ]
Wyatt Hepler3c2e9522020-01-09 16:08:54 -080098 public_deps = [
Wyatt Hepler6639c452020-05-06 11:43:07 -070099 dir_pw_preprocessor,
100 dir_pw_span,
Wyatt Hepler3c2e9522020-01-09 16:08:54 -0800101 ]
Wyatt Hepler6639c452020-05-06 11:43:07 -0700102 deps = [ dir_pw_base64 ]
Wyatt Hepler3c2e9522020-01-09 16:08:54 -0800103}
104
Alexei Frolovedd2f142020-06-09 19:11:27 -0700105pw_source_set("decoder") {
Wyatt Hepler21192402020-01-15 15:40:51 -0800106 public_configs = [ ":default_config" ]
Wyatt Hepler6639c452020-05-06 11:43:07 -0700107 public_deps = [ dir_pw_span ]
108 deps = [ dir_pw_varint ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800109 public = [
110 "public/pw_tokenizer/detokenize.h",
111 "public/pw_tokenizer/token_database.h",
112 ]
113 sources = [
114 "decode.cc",
115 "detokenize.cc",
116 "public/pw_tokenizer/internal/decode.h",
117 "token_database.cc",
118 ]
Wyatt Heplera8557ef2020-05-04 16:29:23 -0700119 friend = [ ":*" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800120}
121
122# Executable for generating test data for the C++ and Python detokenizers. This
123# target should only be built for the host.
Alexei Frolov2e55ee22020-06-17 17:00:10 -0700124pw_executable("generate_decoding_test_data") {
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800125 deps = [
126 ":decoder",
127 ":pw_tokenizer",
Wyatt Hepler6639c452020-05-06 11:43:07 -0700128 dir_pw_varint,
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800129 ]
Aaron Greenb3ae1dc2020-04-13 11:37:05 -0700130 sources = [
131 "generate_decoding_test_data.cc",
132 "tokenize_test_fakes.cc",
133 ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800134}
135
Wyatt Heplerbc254972020-01-06 18:35:30 -0800136# Executable for generating a test ELF file for elf_reader_test.py. A host
137# version of this binary is checked in for use in elf_reader_test.py.
Alexei Frolov2e55ee22020-06-17 17:00:10 -0700138pw_executable("elf_reader_test_binary") {
Wyatt Heplerbc254972020-01-06 18:35:30 -0800139 deps = [
140 ":pw_tokenizer",
141 "$dir_pw_varint",
142 ]
Rob Mohra0ba54f2020-02-27 11:43:49 -0800143 sources = [ "py/elf_reader_test_binary.c" ]
Wyatt Heplerbc254972020-01-06 18:35:30 -0800144 ldflags = [ "-Wl,--unresolved-symbols=ignore-all" ] # main is not defined
145}
146
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800147pw_test_group("tests") {
148 tests = [
149 ":argument_types_test",
Wyatt Hepler3c2e9522020-01-09 16:08:54 -0800150 ":base64_test",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800151 ":decode_test",
karthik bharadwajeabe9a22020-04-14 09:28:28 -0700152 ":detokenize_fuzzer",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800153 ":detokenize_test",
Wyatt Hepler6639c452020-05-06 11:43:07 -0700154 ":global_handlers_test",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800155 ":hash_test",
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800156 ":simple_tokenize_test_cpp11",
157 ":simple_tokenize_test_cpp14",
158 ":simple_tokenize_test_cpp17",
karthik bharadwaj2ee244b2020-04-16 14:08:22 -0700159 ":token_database_fuzzer",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800160 ":token_database_test",
161 ":tokenize_test",
162 ]
163 group_deps = [
164 "$dir_pw_preprocessor:tests",
165 "$dir_pw_span:tests",
166 "$dir_pw_status:tests",
167 ]
168}
169
170pw_test("argument_types_test") {
171 sources = [
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800172 "argument_types_test.cc",
Michael Spanga99220e2020-06-11 20:07:16 -0400173 "argument_types_test_c.c",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800174 "pw_tokenizer_private/argument_types_test.h",
Aaron Greenb3ae1dc2020-04-13 11:37:05 -0700175 "tokenize_test_fakes.cc",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800176 ]
Rob Mohra0ba54f2020-02-27 11:43:49 -0800177 deps = [ ":pw_tokenizer" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800178}
179
Wyatt Hepler3c2e9522020-01-09 16:08:54 -0800180pw_test("base64_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -0800181 sources = [ "base64_test.cc" ]
182 deps = [ ":base64" ]
Wyatt Hepler3c2e9522020-01-09 16:08:54 -0800183}
184
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800185pw_test("decode_test") {
186 sources = [
187 "decode_test.cc",
188 "pw_tokenizer_private/tokenized_string_decoding_test_data.h",
189 "pw_tokenizer_private/varint_decoding_test_data.h",
190 ]
191 deps = [
192 ":decoder",
193 "$dir_pw_varint",
194 ]
195}
196
197pw_test("detokenize_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -0800198 sources = [ "detokenize_test.cc" ]
199 deps = [ ":decoder" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800200}
201
Wyatt Hepler6639c452020-05-06 11:43:07 -0700202pw_test("global_handlers_test") {
203 sources = [
Wyatt Hepler6639c452020-05-06 11:43:07 -0700204 "global_handlers_test.cc",
Michael Spanga99220e2020-06-11 20:07:16 -0400205 "global_handlers_test_c.c",
Wyatt Hepler6639c452020-05-06 11:43:07 -0700206 "pw_tokenizer_private/tokenize_test.h",
207 ]
208 deps = [
209 ":global_handler",
210 ":global_handler_with_payload",
211 ]
212
213 # TODO(hepler): Switch this to a facade test when available.
214 enable_if = enable_global_handler_test
215}
216
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800217pw_test("hash_test") {
218 sources = [
219 "hash_test.cc",
220 "pw_tokenizer_private/generated_hash_test_cases.h",
Aaron Greenb3ae1dc2020-04-13 11:37:05 -0700221 "tokenize_test_fakes.cc",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800222 ]
Rob Mohra0ba54f2020-02-27 11:43:49 -0800223 deps = [ ":pw_tokenizer" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800224}
225
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800226# Fully test C++11 and C++14 compatibility by compiling all sources as C++11 or
227# C++14.
228_simple_tokenize_test_sources = [
Rob Mohra0ba54f2020-02-27 11:43:49 -0800229 "$dir_pw_varint/public/pw_varint/varint.h",
230 "$dir_pw_varint/varint.cc",
Wyatt Hepler6639c452020-05-06 11:43:07 -0700231 "encode_args.cc",
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800232 "public/pw_tokenizer/config.h",
233 "public/pw_tokenizer/internal/argument_types.h",
234 "public/pw_tokenizer/internal/argument_types_macro_4_byte.h",
235 "public/pw_tokenizer/internal/argument_types_macro_8_byte.h",
236 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_128_hash_macro.h",
237 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_80_hash_macro.h",
238 "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_96_hash_macro.h",
239 "public/pw_tokenizer/internal/tokenize_string.h",
Rob Mohra0ba54f2020-02-27 11:43:49 -0800240 "public/pw_tokenizer/pw_tokenizer_65599_fixed_length_hash.h",
241 "public/pw_tokenizer/tokenize.h",
Wyatt Hepler6639c452020-05-06 11:43:07 -0700242 "public/pw_tokenizer/tokenize_to_global_handler.h",
243 "public/pw_tokenizer/tokenize_to_global_handler_with_payload.h",
244 "pw_tokenizer_private/encode_args.h",
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800245 "simple_tokenize_test.cc",
Rob Mohra0ba54f2020-02-27 11:43:49 -0800246 "tokenize.cc",
Wyatt Hepler6639c452020-05-06 11:43:07 -0700247 "tokenize_to_global_handler.cc",
248 "tokenize_to_global_handler_with_payload.cc",
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800249]
250_simple_tokenize_test_configs = [
251 ":default_config",
252 "$dir_pw_varint:default_config",
253]
254
255pw_test("simple_tokenize_test_cpp11") {
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700256 remove_configs = [ "$dir_pw_build:cpp17" ]
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800257 configs = [ "$dir_pw_build:cpp11" ] + _simple_tokenize_test_configs
258 sources = _simple_tokenize_test_sources
Rob Mohra0ba54f2020-02-27 11:43:49 -0800259 deps = [ dir_pw_preprocessor ]
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800260}
261
262pw_test("simple_tokenize_test_cpp14") {
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700263 remove_configs = [ "$dir_pw_build:cpp17" ]
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800264 configs = [ "$dir_pw_build:cpp14" ] + _simple_tokenize_test_configs
265 sources = _simple_tokenize_test_sources
Rob Mohra0ba54f2020-02-27 11:43:49 -0800266 deps = [ dir_pw_preprocessor ]
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800267}
268
269pw_test("simple_tokenize_test_cpp17") {
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700270 configs = _simple_tokenize_test_configs
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800271 sources = _simple_tokenize_test_sources
Rob Mohra0ba54f2020-02-27 11:43:49 -0800272 deps = [ dir_pw_preprocessor ]
Wyatt Heplera6d5cc62020-01-17 14:15:40 -0800273}
274
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800275pw_test("token_database_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -0800276 sources = [ "token_database_test.cc" ]
277 deps = [ ":decoder" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800278}
279
280pw_test("tokenize_test") {
281 sources = [
282 "pw_tokenizer_private/tokenize_test.h",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800283 "tokenize_test.cc",
Michael Spanga99220e2020-06-11 20:07:16 -0400284 "tokenize_test_c.c",
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800285 ]
286 deps = [
287 ":pw_tokenizer",
288 "$dir_pw_varint",
289 ]
290}
291
karthik bharadwaj2ee244b2020-04-16 14:08:22 -0700292pw_fuzzer("token_database_fuzzer") {
293 sources = [ "token_database_fuzzer.cc" ]
294 deps = [
295 ":decoder",
296 "$dir_pw_fuzzer",
297 "$dir_pw_preprocessor",
298 "$dir_pw_span",
299 ]
300}
301
karthik bharadwajeabe9a22020-04-14 09:28:28 -0700302pw_fuzzer("detokenize_fuzzer") {
303 sources = [ "detokenize_fuzzer.cc" ]
304 deps = [
305 ":decoder",
306 "$dir_pw_fuzzer",
307 "$dir_pw_preprocessor",
308 ]
309}
310
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800311declare_args() {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700312 # pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS specifies the paths to use for
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800313 # building Java Native Interface libraries. If no paths are provided, targets
314 # that require JNI may not build correctly.
315 #
316 # Example JNI include paths for a Linux system:
317 #
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700318 # pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS = [
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800319 # "/usr/local/buildtools/java/jdk/include/",
320 # "/usr/local/buildtools/java/jdk/include/linux",
321 # ]
322 #
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700323 pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS = []
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800324}
325
326# Create a shared library for the tokenizer JNI wrapper. The include paths for
327# the JNI headers must be available in the system or provided with the
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700328# pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS variable.
Alexei Frolovedd2f142020-06-09 19:11:27 -0700329pw_shared_library("detokenizer_jni") {
Wyatt Hepler21192402020-01-15 15:40:51 -0800330 public_configs = [ ":default_config" ]
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700331 include_dirs = pw_JAVA_NATIVE_INTERFACE_INCLUDE_DIRS
Rob Mohra0ba54f2020-02-27 11:43:49 -0800332 sources = [ "java/dev/pigweed/tokenizer/detokenizer.cc" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800333 public_deps = [
334 ":decoder",
335 "$dir_pw_preprocessor",
336 ]
337}
338
339pw_doc_group("docs") {
Rob Mohra0ba54f2020-02-27 11:43:49 -0800340 sources = [ "docs.rst" ]
Wyatt Heplerf5e984a2020-04-15 18:15:09 -0700341 inputs = [ "py/pw_tokenizer/encode.py" ]
Wyatt Hepler80c6ee52020-01-03 09:54:58 -0800342}