1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("//build/config/clang/clang.gni") 15import("//build/config/python.gni") 16import("//build/ohos.gni") 17import("//build/ohos_var.gni") 18import("//build/templates/cxx/cxx.gni") 19 20if (!is_arkui_x) { 21 import("//build/rust/rustc_toolchain.gni") 22} 23 24template("_testcase_resources") { 25 assert(defined(invoker.testcase_target_name)) 26 assert(defined(invoker.test_output_dir)) 27 assert(defined(invoker.module_out_path)) 28 29 _deps = [] 30 if (defined(invoker.deps)) { 31 _deps += invoker.deps 32 } 33 action_with_pydeps(target_name) { 34 if (defined(invoker.testonly)) { 35 testonly = invoker.testonly 36 } 37 deps = _deps 38 inputs = [] 39 script = "//build/ohos/testfwk/testcase_resource_copy.py" 40 output_file = "$target_out_dir/$target_name.json" 41 outputs = [ output_file ] 42 depfile = "$target_gen_dir/$target_name.d" 43 args = [] 44 if (defined(invoker.resource_config_file)) { 45 args += [ 46 "--resource-config-file", 47 rebase_path(invoker.resource_config_file, root_build_dir), 48 ] 49 inputs += [ invoker.resource_config_file ] 50 } 51 args += [ 52 "--depfile", 53 rebase_path(depfile, root_build_dir), 54 "--testcase-target-name", 55 invoker.testcase_target_name, 56 "--part-build-out-path", 57 rebase_path(root_out_dir, root_build_dir), 58 "--resource-output-path", 59 rebase_path(invoker.test_output_dir + "/resource", root_build_dir), 60 "--module-out-path", 61 invoker.module_out_path, 62 "--output-file", 63 rebase_path(output_file, root_build_dir), 64 ] 65 } 66} 67 68# ohos test template 69template("_ohos_test") { 70 assert(defined(invoker.test_type), "test_type is required.") 71 assert(defined(invoker.module_out_path)) 72 73 _deps = [] 74 if (defined(invoker.deps)) { 75 _deps += invoker.deps 76 } 77 78 if (defined(invoker.crate_type)) { 79 _deps += [ "//build/rust:libstd.dylib.so" ] 80 } 81 82 test_output_dir = 83 "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}" 84 85 # generate module list file in gn stage 86 if (!skip_generate_module_list_file) { 87 _gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py" 88 _arguments = [ 89 "--target", 90 target_name, 91 "--target_label", 92 get_label_info(":$target_name", "label_with_toolchain"), 93 "--source_dir", 94 rebase_path(get_label_info(":$target_name", "dir"), root_build_dir), 95 "--test_type", 96 invoker.test_type, 97 ] 98 99 _module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf" 100 101 _arguments += [ 102 "--output_dir", 103 rebase_path(test_output_dir, root_build_dir), 104 "--module_list_file", 105 rebase_path(_module_list_file, root_build_dir), 106 ] 107 exec_script(_gen_module_list_script, _arguments) 108 } 109 110 # copy testcase resource 111 testcase_target_name = target_name 112 _testcase_resources("${testcase_target_name}_resource_copy") { 113 if (defined(invoker.resource_config_file)) { 114 resource_config_file = invoker.resource_config_file 115 } 116 module_out_path = invoker.module_out_path 117 deps = _deps 118 testonly = true 119 } 120 121 # copy fuzz config file 122 if (defined(invoker.fuzz_config_file)) { 123 fuzz_config_file = invoker.fuzz_config_file 124 action("${target_name}_copy_fuzz_config_file") { 125 script = "//build/ohos/testfwk/fuzz_config_file_copy.py" 126 inputs = [ fuzz_config_file ] 127 args = [] 128 args += [ 129 "--fuzz-config-file-path", 130 rebase_path(fuzz_config_file, root_build_dir), 131 "--fuzz-config-file-output-path", 132 rebase_path(root_out_dir + "/tests/res", root_build_dir), 133 ] 134 outputs = [ "$target_out_dir/${target_name}_result.txt" ] 135 } 136 } 137 138 _has_sources = defined(invoker.sources) && invoker.sources != [] 139 if (_has_sources) { 140 _c_sources_file = "$target_gen_dir/$target_name.sources" 141 write_file(_c_sources_file, rebase_path(invoker.sources, root_build_dir)) 142 } 143 write_file("$test_output_dir/${target_name}_path.txt", 144 get_label_info(":$target_name", "dir"), 145 "string") 146 147 ohos_executable(target_name) { 148 forward_variables_from(invoker, 149 "*", 150 [ 151 "test_type", 152 "module_out_path", 153 "visibility", 154 ]) 155 forward_variables_from(invoker, [ "visibility" ]) 156 if (!defined(deps)) { 157 deps = [] 158 } 159 deps += [ ":${testcase_target_name}_resource_copy" ] 160 if (defined(invoker.fuzz_config_file)) { 161 deps += [ ":${target_name}_copy_fuzz_config_file" ] 162 } 163 164 subsystem_name = "tests" 165 part_name = invoker.test_type 166 ohos_test = true 167 testonly = true 168 output_name = "$target_name" 169 } 170} 171 172template("ohos_unittest") { 173 _ohos_test(target_name) { 174 testonly = true 175 forward_variables_from(invoker, "*") 176 test_type = "unittest" 177 deps = [] 178 external_deps = [] 179 if (defined(invoker.deps)) { 180 deps += invoker.deps 181 } 182 if (defined(invoker.external_deps)) { 183 external_deps += invoker.external_deps 184 } 185 186 # Add static link library judgment logic below 187 188 if (defined(invoker.rtti_compile_flag) && invoker.rtti_compile_flag) { 189 external_deps += [ "googletest:gtest_rtti_main" ] 190 } else { 191 external_deps += [ "googletest:gtest_main" ] 192 } 193 } 194} 195 196template("ohos_moduletest") { 197 _ohos_test(target_name) { 198 testonly = true 199 forward_variables_from(invoker, "*") 200 test_type = "moduletest" 201 deps = [] 202 external_deps = [] 203 if (defined(invoker.deps)) { 204 deps += invoker.deps 205 } 206 if (defined(invoker.external_deps)) { 207 external_deps += invoker.external_deps 208 } 209 external_deps += [ "googletest:gtest_main" ] 210 } 211} 212 213template("ohos_systemtest") { 214 _ohos_test(target_name) { 215 forward_variables_from(invoker, "*") 216 test_type = "systemtest" 217 } 218} 219 220template("ohos_performancetest") { 221 _ohos_test(target_name) { 222 testonly = true 223 forward_variables_from(invoker, "*") 224 test_type = "performance" 225 deps = [] 226 external_deps = [] 227 if (defined(invoker.deps)) { 228 deps += invoker.deps 229 } 230 deps += 231 [ "//test/testfwk/developer_test/aw/cxx/hwext:performance_test_static" ] 232 if (defined(invoker.external_deps)) { 233 external_deps += invoker.external_deps 234 } 235 external_deps += [ "googletest:gtest_main" ] 236 } 237} 238 239template("ohos_securitytest") { 240 _ohos_test(target_name) { 241 forward_variables_from(invoker, "*") 242 test_type = "security" 243 } 244} 245 246template("ohos_reliabilitytest") { 247 _ohos_test(target_name) { 248 forward_variables_from(invoker, "*") 249 test_type = "reliability" 250 } 251} 252 253template("ohos_distributedtest") { 254 _ohos_test(target_name) { 255 forward_variables_from(invoker, "*") 256 test_type = "distributedtest" 257 deps = [] 258 if (defined(invoker.deps)) { 259 deps += invoker.deps 260 } 261 deps += [ 262 "//test/testfwk/developer_test/aw/cxx/distributed:distributedtest_lib", 263 ] 264 } 265} 266 267template("ohos_fuzztest") { 268 # Judge the compliation library. 269 # Do the FUZZ compliation if the compliation library is the musl. 270 if (use_musl) { 271 _ohos_test(target_name) { 272 forward_variables_from(invoker, 273 "*", 274 [ 275 "deps", 276 "cflags", 277 ]) 278 test_type = "fuzztest" 279 deps = [] 280 if (defined(invoker.deps)) { 281 deps += invoker.deps 282 } 283 cflags = [] 284 if (defined(invoker.cflags)) { 285 cflags += invoker.cflags 286 } 287 cflags += [ 288 "-fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters", 289 "-fsanitize=fuzzer", 290 ] 291 if (target_cpu == "arm64") { 292 libs = 293 [ "$clang_lib_base_path/aarch64-linux-ohos/libclang_rt.fuzzer.a" ] 294 } else if (target_cpu == "x86_64") { 295 libs = [ "$clang_lib_base_path/x86_64-linux-ohos/libclang_rt.fuzzer.a" ] 296 } else { 297 libs = [ "$clang_lib_base_path/arm-linux-ohos/libclang_rt.fuzzer.a" ] 298 } 299 } 300 } else { 301 group(target_name) { 302 not_needed(invoker, "*") 303 } 304 } 305} 306 307template("ohos_benchmarktest") { 308 _ohos_test(target_name) { 309 testonly = true 310 forward_variables_from(invoker, "*", [ "deps" ]) 311 test_type = "benchmark" 312 313 deps = [] 314 external_deps = [] 315 if (defined(invoker.deps)) { 316 deps += invoker.deps 317 } 318 if (defined(invoker.external_deps)) { 319 external_deps += invoker.external_deps 320 } 321 external_deps += [ "benchmark:benchmark" ] 322 } 323} 324 325template("_test_py_file_copy") { 326 assert(defined(invoker.sources), "sources is required.") 327 assert(defined(invoker.target_base_dir)) 328 assert(defined(invoker.copy_output_dir)) 329 330 action_with_pydeps(target_name) { 331 forward_variables_from(invoker, 332 [ 333 "sources", 334 "testonly", 335 "visibility", 336 ]) 337 script = "//build/ohos/testfwk/test_py_file_copy.py" 338 deps = [] 339 if (defined(invoker.deps)) { 340 deps += invoker.deps 341 } 342 343 depfile = "$target_gen_dir/$target_name.d" 344 outfile = "$target_out_dir/$target_name.out" 345 outputs = [ outfile ] 346 args = [ 347 "--target-base-dir", 348 rebase_path(invoker.target_base_dir, root_build_dir), 349 "--copy-output-dir", 350 rebase_path(invoker.copy_output_dir, root_build_dir), 351 "--outfile", 352 rebase_path(outfile, root_build_dir), 353 "--depfile", 354 rebase_path(depfile, root_build_dir), 355 "--source-files", 356 ] 357 args += rebase_path(sources, root_build_dir) 358 } 359} 360 361# python test template 362template("_ohos_test_py") { 363 assert(defined(invoker.test_type), "test_type is required.") 364 assert(defined(invoker.sources), "sources is required.") 365 366 _gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py" 367 _arguments = [ 368 "--target", 369 target_name, 370 "--target_label", 371 get_label_info(":$target_name", "label_with_toolchain"), 372 "--source_dir", 373 rebase_path(get_label_info(":$target_name", "dir"), root_build_dir), 374 "--test_type", 375 invoker.test_type, 376 ] 377 378 if (defined(invoker.module_out_path)) { 379 test_output_dir = 380 "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}" 381 _module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf" 382 } else { 383 test_output_dir = "$root_out_dir/tests/${invoker.test_type}" 384 _module_list_file = "$root_out_dir/module_list_files/$target_name.mlf" 385 } 386 387 _arguments += [ 388 "--output_dir", 389 rebase_path(test_output_dir, root_build_dir), 390 "--module_list_file", 391 rebase_path(_module_list_file, root_build_dir), 392 ] 393 exec_script(_gen_module_list_script, _arguments) 394 395 _test_py_file_copy(target_name) { 396 testonly = true 397 target_base_dir = get_label_info(":$target_name", "dir") 398 copy_output_dir = test_output_dir 399 sources = get_path_info(invoker.sources, "abspath") 400 } 401} 402 403template("ohos_unittest_py") { 404 _ohos_test_py(target_name) { 405 forward_variables_from(invoker, "*") 406 test_type = "unittest" 407 } 408} 409 410template("ohos_moduletest_py") { 411 _ohos_test_py(target_name) { 412 forward_variables_from(invoker, "*") 413 test_type = "moduletest" 414 } 415} 416 417template("ohos_systemtest_py") { 418 _ohos_test_py(target_name) { 419 forward_variables_from(invoker, "*") 420 test_type = "systemtest" 421 } 422} 423 424template("ohos_performancetest_py") { 425 _ohos_test_py(target_name) { 426 forward_variables_from(invoker, "*") 427 test_type = "performance" 428 } 429} 430 431template("ohos_securitytest_py") { 432 _ohos_test_py(target_name) { 433 forward_variables_from(invoker, "*") 434 test_type = "security" 435 } 436} 437 438template("ohos_reliabilitytest_py") { 439 _ohos_test_py(target_name) { 440 forward_variables_from(invoker, "*") 441 test_type = "reliability" 442 } 443} 444 445template("ohos_distributedtest_py") { 446 _ohos_test_py(target_name) { 447 forward_variables_from(invoker, "*") 448 test_type = "distributedtest" 449 } 450} 451 452template("ohos_fuzztest_py") { 453 _ohos_test_py(target_name) { 454 forward_variables_from(invoker, "*") 455 test_type = "fuzztest" 456 } 457} 458 459#js api test template 460template("ohos_js_test") { 461 assert(defined(invoker.test_type), "test_type must be defined.") 462 assert(defined(invoker.hap_profile), "hap_profile must be defined.") 463 assert(defined(invoker.module_out_path), "module_out_path must be defined.") 464 465 # generate module list file in gn stage 466 _gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py" 467 _arguments = [ 468 "--target", 469 target_name, 470 "--target_label", 471 get_label_info(":$target_name", "label_with_toolchain"), 472 "--source_dir", 473 rebase_path(get_label_info(":$target_name", "dir"), root_build_dir), 474 "--test_type", 475 invoker.test_type, 476 ] 477 478 _test_output_dir = 479 "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}" 480 _module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf" 481 482 write_file("$_test_output_dir/${target_name}_path.txt", 483 get_label_info(":$target_name", "dir"), 484 "string") 485 486 _arguments += [ 487 "--output_dir", 488 rebase_path(_test_output_dir, root_build_dir), 489 "--module_list_file", 490 rebase_path(_module_list_file, root_build_dir), 491 ] 492 exec_script(_gen_module_list_script, _arguments) 493 494 # copy testcase resource 495 testcase_target_name = target_name 496 _testcase_resources("${testcase_target_name}_resource_copy") { 497 if (defined(invoker.resource_config_file)) { 498 resource_config_file = invoker.resource_config_file 499 } 500 module_out_path = invoker.module_out_path 501 test_output_dir = _test_output_dir 502 } 503 504 _suite_path = get_label_info(":$target_name", "dir") 505 _template_path = "//test/testfwk/developer_test/libs/js_template" 506 _target_path = "${_template_path}/$target_name" 507 _target_js_copy = "${target_name}__js_copy" 508 action_with_pydeps(_target_js_copy) { 509 script = "//build/ohos/testfwk/test_js_file_copy.py" 510 outputs = [ "$target_out_dir/$target_name.out" ] 511 args = [ 512 "--suite_path", 513 rebase_path(_suite_path, root_build_dir), 514 "--template_path", 515 rebase_path(_template_path, root_build_dir), 516 "--target_path", 517 rebase_path(_target_path, root_build_dir), 518 "--test_output_dir", 519 rebase_path(_test_output_dir, root_build_dir), 520 "--target_name", 521 testcase_target_name, 522 ] 523 deps = [ ":${testcase_target_name}_resource_copy" ] 524 } 525 526 _target_js_assets = "${target_name}__intl_js_assets" 527 ohos_js_assets(_target_js_assets) { 528 source_dir = "${_target_path}/src/main/js/default" 529 deps = [ ":$_target_js_copy" ] 530 } 531 _target_resources = "${target_name}__resources" 532 ohos_resources(_target_resources) { 533 sources = [ "${_target_path}/src/main/resources" ] 534 deps = [ ":$_target_js_assets" ] 535 hap_profile = invoker.hap_profile 536 } 537 538 ohos_hap(target_name) { 539 forward_variables_from(invoker, 540 "*", 541 [ 542 "test_type", 543 "module_out_path", 544 "visibility", 545 ]) 546 forward_variables_from(invoker, [ "visibility" ]) 547 548 deps = [ 549 ":$_target_js_assets", 550 ":$_target_resources", 551 ] 552 final_hap_path = "$_test_output_dir/$target_name.hap" 553 js_build_mode = "debug" 554 testonly = true 555 } 556} 557 558template("ohos_js_unittest") { 559 ohos_js_test(target_name) { 560 forward_variables_from(invoker, "*") 561 test_type = "unittest" 562 } 563} 564 565template("ohos_js_stage_test") { 566 if (defined(invoker.part_name)) { 567 _part_name = invoker.part_name 568 } 569 if (defined(invoker.subsystem_name)) { 570 _subsystem_name = invoker.subsystem_name 571 } 572 if (defined(invoker.test_type)) { 573 _test_type = invoker.test_type 574 } 575 _build_part_boolean = true 576 577 if (defined(invoker.module_out_path)) { 578 _test_output_dir = 579 "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}" 580 } else { 581 _test_output_dir = "$root_out_dir/tests/${invoker.test_type}" 582 } 583 write_file("$_test_output_dir/${target_name}_path.txt", 584 get_label_info(":$target_name", "dir"), 585 "string") 586 587 # generate module list file in gn stage 588 if (!skip_generate_module_list_file) { 589 _gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py" 590 _arguments = [ 591 "--target", 592 target_name, 593 "--target_label", 594 get_label_info(":$target_name", "label_with_toolchain"), 595 "--source_dir", 596 rebase_path(get_label_info(":$target_name", "dir"), root_build_dir), 597 "--test_type", 598 _test_type, 599 ] 600 601 _module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf" 602 603 _arguments += [ 604 "--output_dir", 605 rebase_path(_test_output_dir, root_build_dir), 606 "--module_list_file", 607 rebase_path(_module_list_file, root_build_dir), 608 ] 609 exec_script(_gen_module_list_script, _arguments) 610 } 611 612 assert(defined(invoker.hap_name), 613 "hap_name is required in target ${target_name}") 614 assert(!defined(invoker.final_hap_path), 615 "please use hap_name instead of final_hap_path") 616 _hap_name = invoker.hap_name 617 _final_hap_path = "" 618 _target_name = "" 619 _final_hap_path = 620 "$root_out_dir/tests/haps/${invoker.module_out_path}/${_hap_name}.hap" 621 _target_name = "module_${target_name}" 622 623 _archive_filename = "${_hap_name}.hap" 624 625 if (_build_part_boolean == true) { 626 target("ohos_hap", _target_name) { 627 forward_variables_from(invoker, "*") 628 final_hap_path = _final_hap_path 629 testonly = true 630 } 631 } else { 632 print(tmp_subsystem_part + " is not build") 633 print(_target_name) 634 if (defined(invoker.certificate_profile)) { 635 print(invoker.certificate_profile) 636 } 637 if (defined(invoker.ets2abc)) { 638 print(invoker.ets2abc) 639 } 640 if (defined(invoker.deps)) { 641 print(invoker.deps) 642 } 643 if (defined(invoker.hap_profile)) { 644 print(invoker.hap_profile) 645 } 646 if (defined(invoker.testonly)) { 647 print(invoker.testonly) 648 } 649 } 650 651 _deps = [ ":module_${target_name}" ] 652 653 _archive_testfile = "$root_out_dir/tests/$_test_type/${invoker.module_out_path}/${_archive_filename}" 654 _arguments = [] 655 _arguments = [ 656 "--build_target_name", 657 target_name, 658 "--project_path", 659 rebase_path("."), 660 "--archive_testfile", 661 rebase_path("${_archive_testfile}"), 662 "--final_hap_path", 663 rebase_path("${_final_hap_path}"), 664 "--test_type", 665 _test_type, 666 "--module_out_path", 667 invoker.module_out_path, 668 ] 669 if (_subsystem_name != "") { 670 _arguments += [ 671 "--subsystem_name", 672 _subsystem_name, 673 ] 674 } 675 if (_part_name != "") { 676 _arguments += [ 677 "--part_name", 678 _part_name, 679 ] 680 } 681 682 action(target_name) { 683 deps = _deps 684 script = rebase_path("//build/ohos/testfwk/test_js_stage_file_copy.py") 685 args = _arguments 686 outputs = [ _archive_testfile ] 687 testonly = true 688 } 689} 690 691template("ohos_js_stage_unittest") { 692 ohos_js_stage_test(target_name) { 693 forward_variables_from(invoker, "*") 694 test_type = "unittest" 695 } 696} 697 698template("ohos_rust_unittest") { 699 _target_name = target_name 700 _rustflags = [] 701 _public_deps = [ "//build/rust/tests:original_libstd.so" ] 702 ohos_unittest("$_target_name") { 703 forward_variables_from(invoker, "*") 704 public_deps = _public_deps 705 if (!defined(invoker.crate_name)) { 706 crate_name = _target_name 707 } 708 crate_type = "bin" 709 if (defined(invoker.crate_type)) { 710 assert(invoker.crate_type == crate_type, 711 "crate_type should be $crate_type or use default value.") 712 } 713 714 if (defined(invoker.rustc_lints)) { 715 rustc_lints = invoker.rustc_lints 716 } 717 if (defined(invoker.clippy_lints)) { 718 clippy_lints = invoker.clippy_lints 719 } 720 721 if (!defined(rustc_lints) && !defined(clippy_lints)) { 722 file_path = 723 get_path_info(get_path_info(invoker.sources, "dir"), "abspath") 724 file_path_split = string_split(file_path[0], "/") 725 source_dir_begin = file_path_split[2] 726 727 if (source_dir_begin == "openharmony") { 728 _rustflags += allowAllLints 729 } else if (source_dir_begin == "prebuilts") { 730 _rustflags += allowAllLints 731 } else if (source_dir_begin == "vendor") { 732 _rustflags += rustcVendorLints 733 _rustflags += clippyVendorLints 734 } else if (source_dir_begin == "device") { 735 _rustflags += rustcVendorLints 736 _rustflags += clippyVendorLints 737 } else { 738 _rustflags += rustcOhosLints 739 _rustflags += clippyOhosLints 740 } 741 } 742 743 if (defined(rustc_lints)) { 744 if (invoker.rustc_lints == "openharmony") { 745 _rustflags += rustcOhosLints 746 } else if (rustc_lints == "vendor") { 747 _rustflags += rustcVendorLints 748 } else if (rustc_lints == "none") { 749 _rustflags += allowAllLints 750 } 751 } 752 if (defined(clippy_lints)) { 753 if (invoker.clippy_lints == "openharmony") { 754 _rustflags += clippyOhosLints 755 } else if (clippy_lints == "vendor") { 756 _rustflags += clippyVendorLints 757 } else if (clippy_lints == "none") { 758 _rustflags += allowAllLints 759 } 760 } 761 if (!defined(rustflags)) { 762 rustflags = _rustflags 763 } else { 764 rustflags += _rustflags 765 } 766 edition = rust_default_edition 767 if (defined(invoker.edition)) { 768 edition = invoker.edition 769 } 770 rustflags += [ 771 "--cfg", 772 "feature=\"test\"", 773 "--test", 774 "-Csymbol-mangling-version=v0", 775 "--edition=${edition}", 776 ] 777 } 778} 779 780template("ohos_rust_systemtest") { 781 _target_name = target_name 782 _rustflags = [] 783 _public_deps = [ "//build/rust/tests:original_libstd.so" ] 784 ohos_systemtest("$_target_name") { 785 forward_variables_from(invoker, "*") 786 public_deps = _public_deps 787 if (!defined(invoker.crate_name)) { 788 crate_name = _target_name 789 } 790 crate_type = "bin" 791 if (defined(invoker.crate_type)) { 792 assert(invoker.crate_type == crate_type, 793 "crate_type should be $crate_type or use default value.") 794 } 795 796 if (defined(invoker.rustc_lints)) { 797 rustc_lints = invoker.rustc_lints 798 } 799 if (defined(invoker.clippy_lints)) { 800 clippy_lints = invoker.clippy_lints 801 } 802 803 if (!defined(rustc_lints) && !defined(clippy_lints)) { 804 file_path = 805 get_path_info(get_path_info(invoker.sources, "dir"), "abspath") 806 file_path_split = string_split(file_path[0], "/") 807 source_dir_begin = file_path_split[2] 808 809 if (source_dir_begin == "openharmony") { 810 _rustflags += allowAllLints 811 } else if (source_dir_begin == "prebuilts") { 812 _rustflags += allowAllLints 813 } else if (source_dir_begin == "vendor") { 814 _rustflags += rustcVendorLints 815 _rustflags += clippyVendorLints 816 } else if (source_dir_begin == "device") { 817 _rustflags += rustcVendorLints 818 _rustflags += clippyVendorLints 819 } else { 820 _rustflags += rustcOhosLints 821 _rustflags += clippyOhosLints 822 } 823 } 824 825 if (defined(rustc_lints)) { 826 if (invoker.rustc_lints == "openharmony") { 827 _rustflags += rustcOhosLints 828 } else if (rustc_lints == "vendor") { 829 _rustflags += rustcVendorLints 830 } else if (rustc_lints == "none") { 831 _rustflags += allowAllLints 832 } 833 } 834 if (defined(clippy_lints)) { 835 if (invoker.clippy_lints == "openharmony") { 836 _rustflags += clippyOhosLints 837 } else if (clippy_lints == "vendor") { 838 _rustflags += clippyVendorLints 839 } else if (clippy_lints == "none") { 840 _rustflags += allowAllLints 841 } 842 } 843 if (!defined(rustflags)) { 844 rustflags = _rustflags 845 } else { 846 rustflags += _rustflags 847 } 848 edition = rust_default_edition 849 if (defined(invoker.edition)) { 850 edition = invoker.edition 851 } 852 rustflags += [ 853 "--cfg", 854 "feature=\"test\"", 855 "--test", 856 "-Csymbol-mangling-version=v0", 857 "--edition=${edition}", 858 ] 859 } 860} 861