1# Copyright 2021 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 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_bloat/bloat.gni") 18import("$dir_pw_build/python.gni") 19import("$dir_pw_build/target_types.gni") 20import("$dir_pw_docgen/docs.gni") 21import("$dir_pw_unit_test/test.gni") 22 23config("default_config") { 24 include_dirs = [ "public" ] 25} 26 27group("pw_hdlc") { 28 public_deps = [ 29 ":decoder", 30 ":encoded_size", 31 ":encoder", 32 ] 33} 34 35pw_source_set("common") { 36 public_configs = [ ":default_config" ] 37 public = [ "public/pw_hdlc/internal/protocol.h" ] 38 public_deps = [ dir_pw_varint ] 39 visibility = [ ":*" ] 40} 41 42pw_source_set("encoded_size") { 43 public_configs = [ ":default_config" ] 44 public = [ "public/pw_hdlc/encoded_size.h" ] 45 public_deps = [ 46 ":common", 47 "$dir_pw_bytes", 48 "$dir_pw_span", 49 "$dir_pw_varint", 50 ] 51} 52 53pw_source_set("decoder") { 54 public_configs = [ ":default_config" ] 55 public = [ "public/pw_hdlc/decoder.h" ] 56 sources = [ "decoder.cc" ] 57 public_deps = [ 58 ":common", 59 dir_pw_bytes, 60 dir_pw_checksum, 61 dir_pw_result, 62 dir_pw_span, 63 dir_pw_status, 64 ] 65 deps = [ dir_pw_log ] 66 friend = [ ":*" ] 67} 68 69pw_source_set("encoder") { 70 public_configs = [ ":default_config" ] 71 public = [ "public/pw_hdlc/encoder.h" ] 72 sources = [ 73 "encoder.cc", 74 "public/pw_hdlc/internal/encoder.h", 75 ] 76 public_deps = [ 77 ":common", 78 dir_pw_bytes, 79 dir_pw_checksum, 80 dir_pw_span, 81 dir_pw_status, 82 dir_pw_stream, 83 ] 84 deps = [ ":encoded_size" ] 85 friend = [ ":*" ] 86} 87 88pw_source_set("rpc_channel_output") { 89 public_configs = [ ":default_config" ] 90 public = [ "public/pw_hdlc/rpc_channel.h" ] 91 public_deps = [ 92 ":pw_hdlc", 93 "$dir_pw_rpc:server", 94 dir_pw_span, 95 ] 96} 97 98pw_source_set("pw_rpc") { 99 public_configs = [ ":default_config" ] 100 public = [ "public/pw_hdlc/rpc_packets.h" ] 101 sources = [ "rpc_packets.cc" ] 102 public_deps = [ 103 ":pw_hdlc", 104 "$dir_pw_rpc:server", 105 dir_pw_sys_io, 106 ] 107} 108 109pw_source_set("packet_parser") { 110 public_configs = [ ":default_config" ] 111 public = [ "public/pw_hdlc/wire_packet_parser.h" ] 112 sources = [ "wire_packet_parser.cc" ] 113 public_deps = [ 114 ":pw_hdlc", 115 "$dir_pw_router:packet_parser", 116 ] 117 deps = [ 118 dir_pw_bytes, 119 dir_pw_checksum, 120 ] 121} 122 123# A backend for pw_rpc's `system_server` that sends and receives HDLC-framed RPC 124# packets over pw_sys_io. 125# 126# Warning: This system server is polling and blocking, so it's not 127# production-ready. This exists for simplifying initial bringup/testing, and 128# should not be used in any performance-sensitive application. 129pw_source_set("hdlc_sys_io_system_server") { 130 deps = [ 131 "$dir_pw_hdlc:pw_rpc", 132 "$dir_pw_hdlc:rpc_channel_output", 133 "$dir_pw_rpc/system_server:facade", 134 "$dir_pw_stream:sys_io_stream", 135 dir_pw_log, 136 ] 137 sources = [ "hdlc_sys_io_system_server.cc" ] 138} 139 140pw_test_group("tests") { 141 tests = [ 142 ":encoder_test", 143 ":decoder_test", 144 ":rpc_channel_test", 145 ":encoded_size_test", 146 ":wire_packet_parser_test", 147 ] 148 group_deps = [ 149 "$dir_pw_preprocessor:tests", 150 "$dir_pw_status:tests", 151 "$dir_pw_stream:tests", 152 ] 153} 154 155pw_test("encoded_size_test") { 156 deps = [ 157 ":pw_hdlc", 158 "$dir_pw_bytes", 159 "$dir_pw_result", 160 "$dir_pw_stream", 161 "$dir_pw_varint", 162 ] 163 sources = [ "encoded_size_test.cc" ] 164} 165 166pw_test("encoder_test") { 167 deps = [ ":pw_hdlc" ] 168 sources = [ "encoder_test.cc" ] 169} 170 171pw_python_action("generate_decoder_test") { 172 outputs = [ "$target_gen_dir/generated_decoder_test.cc" ] 173 script = "py/decode_test.py" 174 args = [ "--generate-cc-test" ] + rebase_path(outputs, root_build_dir) 175 python_deps = [ 176 "$dir_pw_build/py", 177 "py", 178 ] 179} 180 181pw_test("decoder_test") { 182 deps = [ 183 ":generate_decoder_test", 184 ":pw_hdlc", 185 ] 186 sources = [ "decoder_test.cc" ] + get_target_outputs(":generate_decoder_test") 187} 188 189pw_test("rpc_channel_test") { 190 deps = [ 191 ":pw_hdlc", 192 ":rpc_channel_output", 193 ] 194 sources = [ "rpc_channel_test.cc" ] 195} 196 197pw_test("wire_packet_parser_test") { 198 deps = [ 199 ":packet_parser", 200 dir_pw_bytes, 201 ] 202 sources = [ "wire_packet_parser_test.cc" ] 203} 204 205pw_size_diff("size_report") { 206 title = "HDLC sizes" 207 208 binaries = [ 209 { 210 target = "size_report:full" 211 base = "size_report:base" 212 label = "HDLC encode and decode" 213 }, 214 { 215 target = "size_report:full_crc" 216 base = "size_report:base_crc" 217 label = "HDLC encode and decode, ignoring CRC and varint" 218 }, 219 ] 220} 221 222pw_doc_group("docs") { 223 sources = [ 224 "docs.rst", 225 "rpc_example/docs.rst", 226 ] 227 inputs = [ 228 "py/pw_hdlc/decode.py", 229 "py/pw_hdlc/encode.py", 230 ] 231 report_deps = [ ":size_report" ] 232} 233