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