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