1// Defaults for rust backend generation. 2genrule_defaults { 3 name: "pdl_rust_generator_defaults", 4 cmd: "$(location :pdlc) --output-format rust $(in) > $(out)", 5 tools: [":pdlc"], 6 defaults_visibility: [ 7 "//system/nfc:__subpackages__", 8 "//external/rust/pica", 9 "//external/uwb/src", 10 "//packages/modules/Bluetooth:__subpackages__", 11 "//tools/netsim:__subpackages__", 12 ], 13} 14 15// Defaults for legacy rust backend generation. 16genrule_defaults { 17 name: "pdl_rust_legacy_generator_defaults", 18 cmd: "$(location :pdlc) --output-format rust_legacy $(in) > $(out)", 19 tools: [":pdlc"], 20 defaults_visibility: [ 21 "//system/nfc:__subpackages__", 22 "//external/rust/pica", 23 "//external/uwb/src", 24 "//packages/modules/Bluetooth:__subpackages__", 25 "//tools/netsim:__subpackages__", 26 ], 27} 28 29// Defaults for rust_noalloc backend generation. 30genrule_defaults { 31 name: "pdl_rust_noalloc_generator_defaults", 32 cmd: "$(location :pdlc) --output-format rust_no_alloc $(in) > $(out)", 33 tools: [":pdlc"], 34} 35 36// Defaults for PDL python backend generation. 37genrule_defaults { 38 name: "pdl_python_generator_defaults", 39 tools: [ 40 ":pdlc", 41 ":pdl_python_generator", 42 ], 43} 44 45// Defaults for PDL C++ backend generation. 46genrule_defaults { 47 name: "pdl_cxx_generator_defaults", 48 tools: [ 49 ":pdlc", 50 ":pdl_cxx_generator", 51 ], 52} 53 54filegroup { 55 name: "pdl_generated_files", 56 srcs: [ 57 "tests/generated/rust/**/*.rs", 58 ], 59} 60 61rust_test_host { 62 name: "pdl_tests", 63 srcs: ["src/main.rs"], 64 rustlibs: [ 65 "libargh", 66 "libcodespan_reporting", 67 "libheck", 68 "libpdl_compiler", 69 "libpest", 70 "libprettyplease", 71 "libproc_macro2", 72 "libquote", 73 "libserde", 74 "libserde_json", 75 "libsyn", 76 "libtempfile", 77 ], 78 proc_macros: [ 79 "libpest_derive", 80 "libpaste", 81 ], 82 test_suites: ["general-tests"], 83 data: [ 84 ":pdl_generated_files", 85 ], 86} 87 88genrule { 89 name: "pdl_generated_files_compile_rs", 90 cmd: "$(location tests/generated_files_compile.sh) $(in) > $(out)", 91 srcs: [":pdl_generated_files"], 92 out: ["generated_files_compile.rs"], 93 tool_files: ["tests/generated_files_compile.sh"], 94} 95 96rust_test_host { 97 name: "pdl_generated_files_compile", 98 srcs: [":pdl_generated_files_compile_rs"], 99 features: ["serde"], 100 rustlibs: [ 101 "libbytes", 102 "libserde", 103 "libtempfile", 104 "libpdl_runtime", 105 ], 106 test_suites: ["general-tests"], 107 clippy_lints: "none", 108 lints: "none", 109} 110 111// The generators support more features for LE packets than for BE 112// packets. We use a single input written for LE packets and remove 113// the parts that don't work for BE packets. We do this by removing 114// everything between 115// 116// // Start: little_endian_only 117// 118// and 119// 120// // End: little_endian_only 121// 122// from the LE packet input. 123genrule_defaults { 124 name: "pdl_be_test_file_defaults", 125 cmd: "sed -e 's/little_endian_packets/big_endian_packets/' " + 126 " -e '/Start: little_endian_only/,/End: little_endian_only/d' " + 127 " < $(in) > $(out)", 128} 129 130genrule { 131 name: "pdl_be_test_file", 132 defaults: ["pdl_be_test_file_defaults"], 133 srcs: ["tests/canonical/le_test_file.pdl"], 134 out: ["be_test_file.pdl"], 135} 136 137genrule { 138 name: "pdl_rust_generator_tests_le_src", 139 cmd: "$(location :pdlc)" + 140 " --output-format rust" + 141 " --exclude-declaration UnsizedCustomField" + 142 " --exclude-declaration Packet_Custom_Field_VariableSize" + 143 " --exclude-declaration Struct_Custom_Field_VariableSize_" + 144 " --exclude-declaration Struct_Custom_Field_VariableSize" + 145 " --exclude-declaration Checksum" + 146 " --exclude-declaration Packet_Checksum_Field_FromStart" + 147 " --exclude-declaration Packet_Checksum_Field_FromEnd" + 148 " --exclude-declaration Struct_Checksum_Field_FromStart_" + 149 " --exclude-declaration Struct_Checksum_Field_FromStart" + 150 " --exclude-declaration Struct_Checksum_Field_FromEnd_" + 151 " --exclude-declaration Struct_Checksum_Field_FromEnd" + 152 " --exclude-declaration PartialParent5" + 153 " --exclude-declaration PartialParent12" + 154 " --exclude-declaration PartialChild5_A" + 155 " --exclude-declaration PartialChild5_B" + 156 " --exclude-declaration PartialChild12_A" + 157 " --exclude-declaration PartialChild12_B" + 158 " --exclude-declaration Packet_Array_Field_UnsizedElement_SizeModifier" + 159 " --exclude-declaration Struct_Array_Field_UnsizedElement_SizeModifier_" + 160 " --exclude-declaration Struct_Array_Field_UnsizedElement_SizeModifier" + 161 " $(location tests/canonical/le_test_file.pdl) > $(out);" + 162 "$(location :pdlc) $(location tests/canonical/le_test_vectors.json) --output-format rust --tests >> $(out)", 163 srcs: [ 164 "tests/canonical/le_test_file.pdl", 165 "tests/canonical/le_test_vectors.json", 166 ], 167 out: ["le_canonical.rs"], 168 tools: [":pdlc"], 169} 170 171genrule { 172 name: "pdl_rust_generator_tests_be_src", 173 cmd: "$(location :pdlc)" + 174 " --output-format rust" + 175 " --exclude-declaration UnsizedCustomField" + 176 " --exclude-declaration Packet_Custom_Field_VariableSize" + 177 " --exclude-declaration Struct_Custom_Field_VariableSize_" + 178 " --exclude-declaration Struct_Custom_Field_VariableSize" + 179 " --exclude-declaration Checksum" + 180 " --exclude-declaration Packet_Checksum_Field_FromStart" + 181 " --exclude-declaration Packet_Checksum_Field_FromEnd" + 182 " --exclude-declaration Struct_Checksum_Field_FromStart_" + 183 " --exclude-declaration Struct_Checksum_Field_FromStart" + 184 " --exclude-declaration Struct_Checksum_Field_FromEnd_" + 185 " --exclude-declaration Struct_Checksum_Field_FromEnd" + 186 " --exclude-declaration Packet_Array_Field_UnsizedElement_SizeModifier" + 187 " --exclude-declaration Struct_Array_Field_UnsizedElement_SizeModifier_" + 188 " --exclude-declaration Struct_Array_Field_UnsizedElement_SizeModifier" + 189 " $(location :pdl_be_test_file) > $(out);" + 190 "$(location :pdlc) $(location tests/canonical/be_test_vectors.json) --output-format rust --tests >> $(out)", 191 srcs: [ 192 ":pdl_be_test_file", 193 "tests/canonical/be_test_vectors.json", 194 ], 195 out: ["be_canonical.rs"], 196 tools: [":pdlc"], 197} 198 199rust_test_host { 200 name: "pdl_rust_generator_tests_le", 201 srcs: [":pdl_rust_generator_tests_le_src"], 202 test_suites: ["general-tests"], 203 features: ["serde"], 204 rustlibs: [ 205 "libbytes", 206 "libnum_traits", 207 "libpdl_runtime", 208 "libserde", 209 "libserde_json", 210 ], 211 clippy_lints: "none", 212 lints: "none", 213} 214 215rust_test_host { 216 name: "pdl_rust_generator_tests_be", 217 srcs: [":pdl_rust_generator_tests_be_src"], 218 test_suites: ["general-tests"], 219 features: ["serde"], 220 rustlibs: [ 221 "libbytes", 222 "libnum_traits", 223 "libpdl_runtime", 224 "libserde", 225 "libserde_json", 226 ], 227 clippy_lints: "none", 228 lints: "none", 229} 230 231// Generate the python parser+serializer backend for the 232// little endian test file located at tests/canonical/le_test_file.pdl. 233genrule { 234 name: "pdl_python_generator_le_test_gen", 235 defaults: ["pdl_python_generator_defaults"], 236 cmd: "set -o pipefail;" + 237 " $(location :pdlc) $(in) |" + 238 " $(location :pdl_python_generator)" + 239 " --exclude-declaration Packet_Array_Field_VariableElementSize_ConstantSize" + 240 " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableSize" + 241 " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableCount" + 242 " --exclude-declaration Packet_Array_Field_VariableElementSize_UnknownSize" + 243 " --output $(out) --custom-type-location tests.custom_types", 244 tool_files: [ 245 "tests/custom_types.py", 246 ], 247 srcs: [ 248 "tests/canonical/le_test_file.pdl", 249 ], 250 out: [ 251 "le_backend.py", 252 ], 253} 254 255// Generate the python parser+serializer backend for a big endian test 256// file derived from tests/canonical/le_test_file.pdl. 257genrule { 258 name: "pdl_python_generator_be_test_gen", 259 defaults: ["pdl_python_generator_defaults"], 260 cmd: "set -o pipefail;" + 261 " $(location :pdlc) $(in) |" + 262 " $(location :pdl_python_generator)" + 263 " --exclude-declaration Packet_Array_Field_VariableElementSize_ConstantSize" + 264 " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableSize" + 265 " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableCount" + 266 " --exclude-declaration Packet_Array_Field_VariableElementSize_UnknownSize" + 267 " --output $(out) --custom-type-location tests.custom_types", 268 tool_files: [ 269 "tests/custom_types.py", 270 ], 271 srcs: [ 272 ":pdl_be_test_file", 273 ], 274 out: [ 275 "be_backend.py", 276 ], 277} 278 279// Test the generated python parser+serializer against 280// pre-generated binary inputs. 281python_test_host { 282 name: "pdl_python_generator_test", 283 main: "tests/python_generator_test.py", 284 srcs: [ 285 ":pdl_python_generator_be_test_gen", 286 ":pdl_python_generator_le_test_gen", 287 "tests/custom_types.py", 288 "tests/python_generator_test.py", 289 ], 290 data: [ 291 "tests/canonical/be_test_vectors.json", 292 "tests/canonical/le_test_vectors.json", 293 ], 294 libs: [ 295 "typing_extensions", 296 ], 297 test_options: { 298 unit_test: true, 299 }, 300 version: { 301 py3: { 302 embedded_launcher: true, 303 }, 304 }, 305} 306 307// Generate the rust_noalloc backend srcs against the little-endian test vectors 308genrule { 309 name: "pdl_rust_noalloc_le_test_backend_srcs", 310 defaults: ["pdl_rust_noalloc_generator_defaults"], 311 srcs: ["tests/canonical/le_rust_noalloc_test_file.pdl"], 312 out: ["_packets.rs"], 313} 314 315// Generate the C++ parser+serializer backend for the 316// little endian test file located at tests/canonical/le_test_file.pdl. 317genrule { 318 name: "pdl_cxx_canonical_le_src_gen", 319 defaults: ["pdl_cxx_generator_defaults"], 320 cmd: "set -o pipefail;" + 321 " $(location :pdlc) $(in) |" + 322 " $(location :pdl_cxx_generator)" + 323 " --exclude-declaration Packet_Custom_Field_ConstantSize" + 324 " --exclude-declaration Packet_Custom_Field_VariableSize" + 325 " --exclude-declaration Packet_Checksum_Field_FromStart" + 326 " --exclude-declaration Packet_Checksum_Field_FromEnd" + 327 " --exclude-declaration Struct_Custom_Field_ConstantSize" + 328 " --exclude-declaration Struct_Custom_Field_VariableSize" + 329 " --exclude-declaration Struct_Checksum_Field_FromStart" + 330 " --exclude-declaration Struct_Checksum_Field_FromEnd" + 331 " --exclude-declaration Packet_Array_Field_VariableElementSize_ConstantSize" + 332 " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableSize" + 333 " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableCount" + 334 " --exclude-declaration Packet_Array_Field_VariableElementSize_UnknownSize" + 335 " --exclude-declaration Struct_Custom_Field_ConstantSize_" + 336 " --exclude-declaration Struct_Custom_Field_VariableSize_" + 337 " --exclude-declaration Struct_Checksum_Field_FromStart_" + 338 " --exclude-declaration Struct_Checksum_Field_FromEnd_" + 339 " --exclude-declaration PartialParent5" + 340 " --exclude-declaration PartialChild5_A" + 341 " --exclude-declaration PartialChild5_B" + 342 " --exclude-declaration PartialParent12" + 343 " --exclude-declaration PartialChild12_A" + 344 " --exclude-declaration PartialChild12_B" + 345 " --namespace le_test" + 346 " --output $(out)", 347 srcs: [ 348 "tests/canonical/le_test_file.pdl", 349 ], 350 out: [ 351 "canonical_le_test_file.h", 352 ], 353} 354 355// Generate the C++ parser+serializer backend tests for the 356// little endian test file located at tests/canonical/le_test_file.pdl. 357genrule { 358 name: "pdl_cxx_canonical_le_test_gen", 359 cmd: "set -o pipefail;" + 360 " inputs=( $(in) ) &&" + 361 " $(location :pdlc) $${inputs[0]} |" + 362 " $(location :pdl_cxx_unittest_generator)" + 363 " --output $(out)" + 364 " --test-vectors $${inputs[1]}" + 365 " --include-header $$(basename $${inputs[2]})" + 366 " --using-namespace le_test" + 367 " --namespace le_test" + 368 " --parser-test-suite LeParserTest" + 369 " --serializer-test-suite LeSerializerTest", 370 tools: [ 371 ":pdlc", 372 ":pdl_cxx_unittest_generator", 373 ], 374 srcs: [ 375 "tests/canonical/le_test_file.pdl", 376 377 "tests/canonical/le_test_vectors.json", 378 379 ":pdl_cxx_canonical_le_src_gen", 380 ], 381 out: [ 382 "canonical_le_test.cc", 383 ], 384} 385 386// Generate the C++ parser+serializer backend for the 387// big endian test file. 388genrule { 389 name: "pdl_cxx_canonical_be_src_gen", 390 defaults: ["pdl_cxx_generator_defaults"], 391 cmd: "set -o pipefail;" + 392 " $(location :pdlc) $(in) |" + 393 " $(location :pdl_cxx_generator)" + 394 " --exclude-declaration Packet_Custom_Field_ConstantSize" + 395 " --exclude-declaration Packet_Custom_Field_VariableSize" + 396 " --exclude-declaration Packet_Checksum_Field_FromStart" + 397 " --exclude-declaration Packet_Checksum_Field_FromEnd" + 398 " --exclude-declaration Struct_Custom_Field_ConstantSize" + 399 " --exclude-declaration Struct_Custom_Field_VariableSize" + 400 " --exclude-declaration Struct_Checksum_Field_FromStart" + 401 " --exclude-declaration Struct_Checksum_Field_FromEnd" + 402 " --exclude-declaration Packet_Array_Field_VariableElementSize_ConstantSize" + 403 " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableSize" + 404 " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableCount" + 405 " --exclude-declaration Packet_Array_Field_VariableElementSize_UnknownSize" + 406 " --exclude-declaration Struct_Custom_Field_ConstantSize_" + 407 " --exclude-declaration Struct_Custom_Field_VariableSize_" + 408 " --exclude-declaration Struct_Checksum_Field_FromStart_" + 409 " --exclude-declaration Struct_Checksum_Field_FromEnd_" + 410 " --exclude-declaration PartialParent5" + 411 " --exclude-declaration PartialChild5_A" + 412 " --exclude-declaration PartialChild5_B" + 413 " --exclude-declaration PartialParent12" + 414 " --exclude-declaration PartialChild12_A" + 415 " --exclude-declaration PartialChild12_B" + 416 " --namespace be_test" + 417 " --output $(out)", 418 srcs: [ 419 ":pdl_be_test_file", 420 ], 421 out: [ 422 "canonical_be_test_file.h", 423 ], 424} 425 426// Generate the C++ parser+serializer backend tests for the 427// big endian test file. 428genrule { 429 name: "pdl_cxx_canonical_be_test_gen", 430 cmd: "set -o pipefail;" + 431 " inputs=( $(in) ) &&" + 432 " $(location :pdlc) $${inputs[0]} |" + 433 " $(location :pdl_cxx_unittest_generator)" + 434 " --output $(out)" + 435 " --test-vectors $${inputs[1]}" + 436 " --include-header $$(basename $${inputs[2]})" + 437 " --using-namespace be_test" + 438 " --namespace be_test" + 439 " --parser-test-suite BeParserTest" + 440 " --serializer-test-suite BeSerializerTest", 441 tools: [ 442 ":pdlc", 443 ":pdl_cxx_unittest_generator", 444 ], 445 srcs: [ 446 ":pdl_be_test_file", 447 448 "tests/canonical/be_test_vectors.json", 449 450 ":pdl_cxx_canonical_be_src_gen", 451 ], 452 out: [ 453 "canonical_be_test.cc", 454 ], 455} 456 457// Test the generated C++ parser+serializer against 458// pre-generated binary inputs. 459cc_test_host { 460 name: "pdl_cxx_generator_test", 461 local_include_dirs: [ 462 "scripts", 463 ], 464 generated_headers: [ 465 "pdl_cxx_canonical_be_src_gen", 466 "pdl_cxx_canonical_le_src_gen", 467 ], 468 generated_sources: [ 469 "pdl_cxx_canonical_be_test_gen", 470 "pdl_cxx_canonical_le_test_gen", 471 ], 472 static_libs: [ 473 "libgtest", 474 ], 475} 476