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