1# 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
15load(
16    "//pw_build:pigweed.bzl",
17    "pw_cc_binary",
18    "pw_cc_library",
19    "pw_cc_test",
20)
21
22package(default_visibility = ["//visibility:public"])
23
24licenses(["notice"])  # Apache License 2.0
25
26pw_cc_library(
27    name = "pw_tokenizer",
28    srcs = [
29        "encode_args.cc",
30        "hash.cc",
31        "public/pw_tokenizer/config.h",
32        "public/pw_tokenizer/internal/argument_types.h",
33        "public/pw_tokenizer/internal/argument_types_macro_4_byte.h",
34        "public/pw_tokenizer/internal/argument_types_macro_8_byte.h",
35        "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_128_hash_macro.h",
36        "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_256_hash_macro.h",
37        "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_80_hash_macro.h",
38        "public/pw_tokenizer/internal/pw_tokenizer_65599_fixed_length_96_hash_macro.h",
39        "public/pw_tokenizer/internal/tokenize_string.h",
40        "tokenize.cc",
41    ],
42    hdrs = [
43        "public/pw_tokenizer/encode_args.h",
44        "public/pw_tokenizer/hash.h",
45        "public/pw_tokenizer/tokenize.h",
46    ],
47    includes = ["public"],
48    deps = [
49        "//pw_polyfill",
50        "//pw_preprocessor",
51        "//pw_span",
52        "//pw_varint",
53    ],
54)
55
56# TODO(pwbug/101): Need to add support for facades/backends to Bazel.
57PW_TOKENIZER_GLOBAL_HANDLER_BACKEND = "//pw_tokenizer:test_backend"
58
59PW_TOKENIZER_GLOBAL_HANDLER_WITH_PAYLOAD_BACKEND = "//pw_tokenizer:test_backend"
60
61pw_cc_library(
62    name = "test_backend",
63    visibility = ["//visibility:private"],
64)
65
66pw_cc_library(
67    name = "global_handler",
68    srcs = ["tokenize_to_global_handler.cc"],
69    hdrs = ["public/pw_tokenizer/tokenize_to_global_handler.h"],
70    deps = [
71        ":pw_tokenizer",
72        PW_TOKENIZER_GLOBAL_HANDLER_BACKEND,
73    ],
74)
75
76pw_cc_library(
77    name = "global_handler_with_payload",
78    srcs = ["tokenize_to_global_handler_with_payload.cc"],
79    hdrs = ["public/pw_tokenizer/tokenize_to_global_handler_with_payload.h"],
80    deps = [
81        ":pw_tokenizer",
82        PW_TOKENIZER_GLOBAL_HANDLER_WITH_PAYLOAD_BACKEND,
83    ],
84)
85
86pw_cc_library(
87    name = "base64",
88    srcs = [
89        "base64.cc",
90    ],
91    hdrs = [
92        "public/pw_tokenizer/base64.h",
93    ],
94    includes = ["public"],
95    deps = [
96        "//pw_base64",
97        "//pw_preprocessor",
98        "//pw_span",
99    ],
100)
101
102pw_cc_library(
103    name = "decoder",
104    srcs = [
105        "decode.cc",
106        "detokenize.cc",
107        "token_database.cc",
108    ],
109    hdrs = [
110        "public/pw_tokenizer/detokenize.h",
111        "public/pw_tokenizer/internal/decode.h",
112        "public/pw_tokenizer/token_database.h",
113    ],
114    includes = ["public"],
115    deps = [
116        "//pw_span",
117        "//pw_varint",
118    ],
119)
120
121# Executable for generating test data for the C++ and Python detokenizers. This
122# target should only be built for the host.
123pw_cc_binary(
124    name = "generate_decoding_test_data",
125    srcs = [
126        "generate_decoding_test_data.cc",
127        "tokenize_test_fakes.cc",
128    ],
129    deps = [
130        ":decoder",
131        ":pw_tokenizer",
132        "//pw_preprocessor",
133        "//pw_span",
134        "//pw_varint",
135    ],
136)
137
138# Executable for generating a test ELF file for elf_reader_test.py. A host
139# version of this binary is checked in for use in elf_reader_test.py.
140cc_binary(
141    name = "elf_reader_test_binary",
142    srcs = [
143        "py/elf_reader_test_binary.c",
144    ],
145    linkopts = ["-Wl,--unresolved-symbols=ignore-all"],  # main is not defined
146    deps = [
147        ":pw_tokenizer",
148        "//pw_varint",
149    ],
150)
151
152pw_cc_test(
153    name = "argument_types_test",
154    srcs = [
155        "argument_types_test.cc",
156        "argument_types_test_c.c",
157        "pw_tokenizer_private/argument_types_test.h",
158        "tokenize_test_fakes.cc",
159    ],
160    deps = [
161        ":pw_tokenizer",
162        "//pw_preprocessor",
163        "//pw_unit_test",
164    ],
165)
166
167pw_cc_test(
168    name = "base64_test",
169    srcs = [
170        "base64_test.cc",
171    ],
172    deps = [
173        ":base64",
174        "//pw_span",
175        "//pw_unit_test",
176    ],
177)
178
179pw_cc_test(
180    name = "decode_test",
181    srcs = [
182        "decode_test.cc",
183        "pw_tokenizer_private/tokenized_string_decoding_test_data.h",
184        "pw_tokenizer_private/varint_decoding_test_data.h",
185    ],
186    deps = [
187        ":decoder",
188        "//pw_unit_test",
189        "//pw_varint",
190    ],
191)
192
193pw_cc_test(
194    name = "detokenize_test",
195    srcs = [
196        "detokenize_test.cc",
197    ],
198    deps = [
199        ":decoder",
200        "//pw_unit_test",
201    ],
202)
203
204pw_cc_test(
205    name = "global_handlers_test",
206    srcs = [
207        "global_handlers_test.cc",
208        "global_handlers_test_c.c",
209        "pw_tokenizer_private/tokenize_test.h",
210    ],
211    deps = [
212        ":global_handler",
213        ":global_handler_with_payload",
214    ],
215)
216
217pw_cc_test(
218    name = "hash_test",
219    srcs = [
220        "hash_test.cc",
221        "pw_tokenizer_private/generated_hash_test_cases.h",
222        "tokenize_test_fakes.cc",
223    ],
224    deps = [
225        ":pw_tokenizer",
226        "//pw_preprocessor",
227        "//pw_unit_test",
228    ],
229)
230
231pw_cc_test(
232    name = "simple_tokenize_test",
233    srcs = [
234        "simple_tokenize_test.cc",
235    ],
236    deps = [
237        ":pw_tokenizer",
238        "//pw_unit_test",
239    ],
240)
241
242pw_cc_test(
243    name = "token_database_test",
244    srcs = [
245        "token_database_test.cc",
246    ],
247    deps = [
248        ":decoder",
249        "//pw_unit_test",
250    ],
251)
252
253pw_cc_test(
254    name = "tokenize_test",
255    srcs = [
256        "pw_tokenizer_private/tokenize_test.h",
257        "tokenize_test.cc",
258        "tokenize_test_c.c",
259    ],
260    deps = [
261        ":pw_tokenizer",
262        "//pw_preprocessor",
263        "//pw_unit_test",
264        "//pw_varint",
265    ],
266)
267
268# Create a shared library for the tokenizer JNI wrapper. The include paths for
269# the JNI headers must be available in the system or provided with the
270# pw_java_native_interface_include_dirs variable.
271filegroup(
272    name = "detokenizer_jni",
273    srcs = [
274        "java/dev/pigweed/tokenizer/detokenizer.cc",
275    ],
276)
277