xref: /aosp_15_r20/external/pigweed/pw_tokenizer/py/BUILD.bazel (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2022 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("@rules_python//python:defs.bzl", "py_library")
16load("@rules_python//python:proto.bzl", "py_proto_library")
17load("//pw_build:python.bzl", "pw_py_binary", "pw_py_test")
18
19package(default_visibility = ["//visibility:public"])
20
21# TODO(jrreinhart): Move this file to pw_elf.
22exports_files(
23    ["elf_reader_test_binary.elf"],
24    visibility = ["//pw_elf:__pkg__"],
25)
26
27py_library(
28    name = "pw_tokenizer",
29    srcs = [
30        "pw_tokenizer/__init__.py",
31        "pw_tokenizer/database.py",
32        "pw_tokenizer/decode.py",
33        "pw_tokenizer/detokenize.py",
34        "pw_tokenizer/elf_reader.py",
35        "pw_tokenizer/encode.py",
36        "pw_tokenizer/parse_message.py",
37        "pw_tokenizer/proto/__init__.py",
38        "pw_tokenizer/serial_detokenizer.py",
39        "pw_tokenizer/tokens.py",
40    ],
41    imports = ["."],
42    deps = [
43        "//pw_cli/py:pw_cli",
44    ],
45)
46
47pw_py_binary(
48    name = "database",
49    srcs = [
50        "pw_tokenizer/database.py",
51    ],
52    deps = [
53        ":pw_tokenizer",
54    ],
55)
56
57pw_py_binary(
58    name = "detokenize",
59    srcs = [
60        "pw_tokenizer/__main__.py",
61    ],
62    main = "pw_tokenizer/__main__.py",
63    deps = [":pw_tokenizer"],
64)
65
66# This test attempts to directly access files in the source tree, which is
67# incompatible with sandboxing.
68# TODO: b/241307309 - Fix this test.
69filegroup(
70    name = "database_test",
71    srcs = ["database_test.py"],
72    # deps = [":pw_tokenizer"],
73)
74
75pw_py_test(
76    name = "decode_test",
77    srcs = [
78        "decode_test.py",
79        "tokenized_string_decoding_test_data.py",
80        "varint_test_data.py",
81    ],
82    deps = [":pw_tokenizer"],
83)
84
85pw_py_test(
86    name = "detokenize_proto_test",
87    srcs = [
88        "detokenize_proto_test.py",
89    ],
90    deps = [
91        ":detokenize_proto_test_pb2",
92        ":pw_tokenizer",
93    ],
94)
95
96proto_library(
97    name = "detokenize_proto_test_proto",
98    srcs = ["detokenize_proto_test.proto"],
99    import_prefix = "pw_tokenizer_tests",
100    strip_import_prefix = "/pw_tokenizer/py",
101    deps = [
102        "//pw_tokenizer:tokenizer_proto",
103    ],
104)
105
106py_proto_library(
107    name = "detokenize_proto_test_pb2",
108    deps = [":detokenize_proto_test_proto"],
109)
110
111filegroup(
112    name = "example_binary_with_tokenized_strings",
113    srcs = ["example_binary_with_tokenized_strings.elf"],
114)
115
116pw_py_test(
117    name = "detokenize_test",
118    srcs = ["detokenize_test.py"],
119    data = [
120        "example_binary_with_tokenized_strings.elf",
121    ],
122    deps = [
123        ":pw_tokenizer",
124    ],
125)
126
127pw_py_test(
128    name = "elf_reader_test",
129    srcs = ["elf_reader_test.py"],
130    data = [
131        "elf_reader_test_binary.elf",
132    ],
133    deps = [
134        ":pw_tokenizer",
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.
140# Commented out because it fails to compile with bazel, with the error
141# ld.lld: error: symbol 'main' has no type. Instead use a filegroup to
142# keep pw_presubmit happy.
143# cc_binary(
144#     name = "elf_reader_test_binary",
145#     srcs = [
146#         "py/elf_reader_test_binary.c",
147#     ],
148#     linkopts = ["-Wl,--unresolved-symbols=ignore-all"],  # main is not defined
149#     deps = [
150#         ":pw_tokenizer",
151#         "//pw_varint",
152#     ],
153# )
154filegroup(
155    name = "elf_reader_test_binary",
156    srcs = [
157        "elf_reader_test_binary.c",
158    ],
159)
160
161pw_py_test(
162    name = "encode_test",
163    srcs = [
164        "encode_test.py",
165        "varint_test_data.py",
166    ],
167    deps = [":pw_tokenizer"],
168)
169
170pw_py_test(
171    name = "tokens_test",
172    srcs = ["tokens_test.py"],
173    deps = [":pw_tokenizer"],
174)
175