• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2022 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/rust/rustc_toolchain.gni")
15import("//build/templates/cxx/cxx.gni")
16import("//build/templates/rust/ohos_rust_library.gni")
17
18allowAllLints = [
19  "--cap-lints",
20  "allow",
21]
22rustcOhosLints = [
23  "-A",
24  "deprecated",
25  "-D",
26  "missing-docs",
27  "-D",
28  "warnings",
29]
30rustcVendorLints = [
31  "-A",
32  "deprecated",
33  "-D",
34  "warnings",
35]
36clippyOhosLints = [
37  "-A",
38  "clippy::type-complexity",
39  "-A",
40  "clippy::unnecessary-wraps",
41  "-A",
42  "clippy::unusual-byte-groupings",
43  "-A",
44  "clippy::upper-case-acronyms",
45  "-A",
46  "clippy::let_and_return",
47]
48clippyVendorLints = [
49  "-A",
50  "clippy::complexity",
51  "-A",
52  "clippy::perf",
53  "-A",
54  "clippy::style",
55]
56
57template("rust_target") {
58  assert(!defined(invoker.crate_root) ||
59         !(defined(invoker.generate_crate_root) && invoker.generate_crate_root))
60
61  _crate_name = target_name
62  if (defined(invoker.crate_name)) {
63    _crate_name = invoker.crate_name
64  }
65  _crate_type = ""
66  if (defined(invoker.crate_type)) {
67    _crate_type = invoker.crate_type
68  }
69  _deps = []
70  if (defined(invoker.deps)) {
71    _deps += invoker.deps
72  }
73
74  _rustflags = []
75  if (defined(invoker.rustflags)) {
76    _rustflags += invoker.rustflags
77  }
78
79  _public_deps = []
80  if (defined(invoker.public_deps)) {
81    _public_deps += invoker.public_deps
82  }
83
84  if (defined(invoker.output_dir) && invoker.output_dir != "") {
85    _out_dir = invoker.output_dir
86  } else {
87    _out_dir = target_out_dir
88  }
89
90  if (defined(invoker.features)) {
91    foreach(i, invoker.features) {
92      _rustflags += [ "--cfg=feature=\"${i}\"" ]
93    }
94  }
95  _rustenv = [ "OUT_DIR=" + rebase_path(_out_dir) ]
96  if (defined(invoker.rustenv)) {
97    _rustenv += invoker.rustenv
98  }
99
100  assert(defined(invoker.sources), "sources must be listed")
101
102  _rust_deps = _deps
103  _rust_public_deps = _public_deps
104
105  _edition = rust_default_edition
106  if (defined(invoker.edition)) {
107    _edition = invoker.edition
108  }
109  _rustflags += [ string_join("",
110                              [
111                                "--edition=",
112                                _edition,
113                              ]) ]
114  if (invoker.target_type == "rust_proc_macro") {
115    _rustflags += [
116      "--extern",
117      "proc_macro",
118    ]
119  }
120  target(invoker.target_type, "${target_name}") {
121    forward_variables_from(invoker,
122                           "*",
123                           [
124                             "features",
125                             "deps",
126                             "public_deps",
127                             "rustflags",
128                             "rustenv",
129
130                             # "configs",
131                             "output_dir",
132                             "crate_type",
133                           ])
134    crate_name = _crate_name
135
136    deps = _rust_deps
137    public_deps = _rust_public_deps
138    rustflags = _rustflags
139    rustenv = _rustenv
140    crate_type = _crate_type
141    if (target_type == "rust_proc_macro") {
142      output_dir = _out_dir
143    }
144    if (!defined(output_name) || output_name == "") {
145      output_name = crate_name
146    }
147  }
148}
149
150template("ohos_rust_executable") {
151  _target_name = target_name
152  _rustflags = []
153  rust_target("$_target_name") {
154    target_type = "ohos_executable"
155    forward_variables_from(invoker, "*")
156    if (!defined(invoker.crate_name)) {
157      crate_name = _target_name
158    }
159    crate_type = "bin"
160    if (defined(invoker.crate_type)) {
161      assert(invoker.crate_type == crate_type,
162             "crate_type should be $crate_type or use default value.")
163    }
164    configs = []
165    if (!defined(deps)) {
166      deps = []
167    }
168    _external_deps = [
169      "common:libstd.dylib.so",
170      "common:libtest.dylib.so",
171    ]
172    if (defined(external_deps)) {
173      external_deps += _external_deps
174    } else {
175      external_deps = _external_deps
176    }
177    if (defined(invoker.rustc_lints)) {
178      rustc_lints = invoker.rustc_lints
179    }
180    if (defined(invoker.clippy_lints)) {
181      clippy_lints = invoker.clippy_lints
182    }
183
184    if (!defined(rustc_lints) && !defined(clippy_lints)) {
185      file_path =
186          get_path_info(get_path_info(invoker.sources, "dir"), "abspath")
187      file_path_split = string_split(file_path[0], "/")
188      source_dir_begin = file_path_split[2]
189
190      if (source_dir_begin == "third_party") {
191        _rustflags += allowAllLints
192      } else if (source_dir_begin == "prebuilts") {
193        _rustflags += allowAllLints
194      } else if (source_dir_begin == "vendor") {
195        _rustflags += rustcVendorLints
196        _rustflags += clippyVendorLints
197      } else if (source_dir_begin == "device") {
198        _rustflags += rustcVendorLints
199        _rustflags += clippyVendorLints
200      } else {
201        _rustflags += rustcOhosLints
202        _rustflags += clippyOhosLints
203      }
204    }
205
206    if (defined(rustc_lints)) {
207      if (invoker.rustc_lints == "openharmony") {
208        _rustflags += rustcOhosLints
209      } else if (rustc_lints == "vendor") {
210        _rustflags += rustcVendorLints
211      } else if (rustc_lints == "none") {
212        _rustflags += allowAllLints
213      }
214    }
215    if (defined(clippy_lints)) {
216      if (invoker.clippy_lints == "openharmony") {
217        _rustflags += clippyOhosLints
218      } else if (clippy_lints == "vendor") {
219        _rustflags += clippyVendorLints
220      } else if (clippy_lints == "none") {
221        _rustflags += allowAllLints
222      }
223    }
224    if (!defined(rustflags)) {
225      rustflags = _rustflags
226    } else {
227      rustflags += _rustflags
228    }
229    if (!defined(rust_static_link) || !rust_static_link) {
230      rustflags += [ "-Cprefer-dynamic" ]
231    }
232  }
233}
234
235template("ohos_rust_shared_library") {
236  _target_name = target_name
237  _rustflags = []
238  rust_target("$_target_name") {
239    target_type = "ohos_rust_library"
240    forward_variables_from(invoker, "*")
241    if (!defined(invoker.crate_name)) {
242      crate_name = _target_name
243    }
244    crate_type = "dylib"
245    if (defined(invoker.crate_type)) {
246      assert(invoker.crate_type == crate_type,
247             "crate_type should be $crate_type or use default value.")
248    }
249
250    if (defined(invoker.output_extension)) {
251      module_output_extension = "." + invoker.output_extension
252    } else {
253      module_output_extension = dylib_extension
254    }
255
256    if (defined(invoker.rustc_lints)) {
257      rustc_lints = invoker.rustc_lints
258    }
259    if (defined(invoker.clippy_lints)) {
260      clippy_lints = invoker.clippy_lints
261    }
262
263    if (!defined(rustc_lints) && !defined(clippy_lints)) {
264      file_path =
265          get_path_info(get_path_info(invoker.sources, "dir"), "abspath")
266      file_path_split = string_split(file_path[0], "/")
267      source_dir_begin = file_path_split[2]
268
269      if (source_dir_begin == "third_party") {
270        _rustflags += allowAllLints
271      } else if (source_dir_begin == "prebuilts") {
272        _rustflags += allowAllLints
273      } else if (source_dir_begin == "vendor") {
274        _rustflags += rustcVendorLints
275        _rustflags += clippyVendorLints
276      } else if (source_dir_begin == "device") {
277        _rustflags += rustcVendorLints
278        _rustflags += clippyVendorLints
279      } else {
280        _rustflags += rustcOhosLints
281        _rustflags += clippyOhosLints
282      }
283    }
284
285    if (defined(rustc_lints)) {
286      if (invoker.rustc_lints == "openharmony") {
287        _rustflags += rustcOhosLints
288      } else if (rustc_lints == "vendor") {
289        _rustflags += rustcVendorLints
290      } else if (rustc_lints == "none") {
291        _rustflags += allowAllLints
292      }
293    }
294    if (defined(clippy_lints)) {
295      if (invoker.clippy_lints == "openharmony") {
296        _rustflags += clippyOhosLints
297      } else if (clippy_lints == "vendor") {
298        _rustflags += clippyVendorLints
299      } else if (clippy_lints == "none") {
300        _rustflags += allowAllLints
301      }
302    }
303    if (!defined(rustflags)) {
304      rustflags = _rustflags
305    } else {
306      rustflags += _rustflags
307    }
308  }
309}
310
311template("ohos_rust_static_library") {
312  _target_name = target_name
313  _rustflags = []
314  rust_target("$_target_name") {
315    target_type = "ohos_rust_library"
316    forward_variables_from(invoker, "*")
317    if (!defined(invoker.crate_name)) {
318      crate_name = _target_name
319    }
320    crate_type = "rlib"
321    if (defined(invoker.crate_type)) {
322      assert(invoker.crate_type == crate_type,
323             "crate_type should be $crate_type or use default value.")
324    }
325    module_output_extension = rlib_extension
326    install_enable = false
327
328    if (defined(invoker.rustc_lints)) {
329      rustc_lints = invoker.rustc_lints
330    }
331    if (defined(invoker.clippy_lints)) {
332      clippy_lints = invoker.clippy_lints
333    }
334
335    if (!defined(rustc_lints) && !defined(clippy_lints)) {
336      file_path =
337          get_path_info(get_path_info(invoker.sources, "dir"), "abspath")
338      file_path_split = string_split(file_path[0], "/")
339      source_dir_begin = file_path_split[2]
340
341      if (source_dir_begin == "third_party") {
342        _rustflags += allowAllLints
343      } else if (source_dir_begin == "prebuilts") {
344        _rustflags += allowAllLints
345      } else if (source_dir_begin == "vendor") {
346        _rustflags += rustcVendorLints
347        _rustflags += clippyVendorLints
348      } else if (source_dir_begin == "device") {
349        _rustflags += rustcVendorLints
350        _rustflags += clippyVendorLints
351      } else {
352        _rustflags += rustcOhosLints
353        _rustflags += clippyOhosLints
354      }
355    }
356
357    if (defined(rustc_lints)) {
358      if (invoker.rustc_lints == "openharmony") {
359        _rustflags += rustcOhosLints
360      } else if (rustc_lints == "vendor") {
361        _rustflags += rustcVendorLints
362      } else if (rustc_lints == "none") {
363        _rustflags += allowAllLints
364      }
365    }
366    if (defined(clippy_lints)) {
367      if (invoker.clippy_lints == "openharmony") {
368        _rustflags += clippyOhosLints
369      } else if (clippy_lints == "vendor") {
370        _rustflags += clippyVendorLints
371      } else if (clippy_lints == "none") {
372        _rustflags += allowAllLints
373      }
374    }
375    if (!defined(rustflags)) {
376      rustflags = _rustflags
377    } else {
378      rustflags += _rustflags
379    }
380  }
381}
382
383template("ohos_rust_shared_ffi") {
384  _target_name = target_name
385  _rustflags = []
386  rust_target("$_target_name") {
387    target_type = "ohos_shared_library"
388    forward_variables_from(invoker, "*")
389    if (!defined(invoker.crate_name)) {
390      crate_name = _target_name
391    }
392    crate_type = "cdylib"
393    if (defined(invoker.crate_type)) {
394      assert(invoker.crate_type == crate_type,
395             "crate_type should be $crate_type or use default value.")
396    }
397
398    if (!defined(deps)) {
399      deps = []
400    }
401    _external_deps = [
402      "common:libstd.dylib.so",
403      "common:libtest.dylib.so",
404    ]
405    if (defined(external_deps)) {
406      external_deps += _external_deps
407    } else {
408      external_deps = _external_deps
409    }
410
411    if (defined(invoker.rustc_lints)) {
412      rustc_lints = invoker.rustc_lints
413    }
414    if (defined(invoker.clippy_lints)) {
415      clippy_lints = invoker.clippy_lints
416    }
417
418    if (!defined(rustc_lints) && !defined(clippy_lints)) {
419      file_path =
420          get_path_info(get_path_info(invoker.sources, "dir"), "abspath")
421      file_path_split = string_split(file_path[0], "/")
422      source_dir_begin = file_path_split[2]
423
424      if (source_dir_begin == "third_party") {
425        _rustflags += allowAllLints
426      } else if (source_dir_begin == "prebuilts") {
427        _rustflags += allowAllLints
428      } else if (source_dir_begin == "vendor") {
429        _rustflags += rustcVendorLints
430        _rustflags += clippyVendorLints
431      } else if (source_dir_begin == "device") {
432        _rustflags += rustcVendorLints
433        _rustflags += clippyVendorLints
434      } else {
435        _rustflags += rustcOhosLints
436        _rustflags += clippyOhosLints
437      }
438    }
439
440    if (defined(rustc_lints)) {
441      if (invoker.rustc_lints == "openharmony") {
442        _rustflags += rustcOhosLints
443      } else if (rustc_lints == "vendor") {
444        _rustflags += rustcVendorLints
445      } else if (rustc_lints == "none") {
446        _rustflags += allowAllLints
447      }
448    }
449    if (defined(clippy_lints)) {
450      if (invoker.clippy_lints == "openharmony") {
451        _rustflags += clippyOhosLints
452      } else if (clippy_lints == "vendor") {
453        _rustflags += clippyVendorLints
454      } else if (clippy_lints == "none") {
455        _rustflags += allowAllLints
456      }
457    }
458    if (!defined(rustflags)) {
459      rustflags = _rustflags
460    } else {
461      rustflags += _rustflags
462    }
463  }
464}
465
466template("ohos_rust_static_ffi") {
467  _target_name = target_name
468  _rustflags = []
469  rust_target("$_target_name") {
470    target_type = "ohos_static_library"
471    forward_variables_from(invoker, "*")
472    if (!defined(invoker.crate_name)) {
473      crate_name = _target_name
474    }
475    crate_type = "staticlib"
476    if (defined(invoker.crate_type)) {
477      assert(invoker.crate_type == crate_type,
478             "crate_type should be $crate_type or use default value.")
479    }
480    if (!defined(deps)) {
481      deps = []
482    }
483    _external_deps = [
484      "common:libstd.dylib.so",
485      "common:libtest.dylib.so",
486    ]
487    if (defined(external_deps)) {
488      external_deps += _external_deps
489    } else {
490      external_deps = _external_deps
491    }
492    if (defined(invoker.rustc_lints)) {
493      rustc_lints = invoker.rustc_lints
494    }
495    if (defined(invoker.clippy_lints)) {
496      clippy_lints = invoker.clippy_lints
497    }
498
499    if (!defined(rustc_lints) && !defined(clippy_lints)) {
500      file_path =
501          get_path_info(get_path_info(invoker.sources, "dir"), "abspath")
502      file_path_split = string_split(file_path[0], "/")
503      source_dir_begin = file_path_split[2]
504
505      if (source_dir_begin == "third_party") {
506        _rustflags += allowAllLints
507      } else if (source_dir_begin == "prebuilts") {
508        _rustflags += allowAllLints
509      } else if (source_dir_begin == "vendor") {
510        _rustflags += rustcVendorLints
511        _rustflags += clippyVendorLints
512      } else if (source_dir_begin == "device") {
513        _rustflags += rustcVendorLints
514        _rustflags += clippyVendorLints
515      } else {
516        _rustflags += rustcOhosLints
517        _rustflags += clippyOhosLints
518      }
519    }
520
521    if (defined(rustc_lints)) {
522      if (invoker.rustc_lints == "openharmony") {
523        _rustflags += rustcOhosLints
524      } else if (rustc_lints == "vendor") {
525        _rustflags += rustcVendorLints
526      } else if (rustc_lints == "none") {
527        _rustflags += allowAllLints
528      }
529    }
530    if (defined(clippy_lints)) {
531      if (invoker.clippy_lints == "openharmony") {
532        _rustflags += clippyOhosLints
533      } else if (clippy_lints == "vendor") {
534        _rustflags += clippyVendorLints
535      } else if (clippy_lints == "none") {
536        _rustflags += allowAllLints
537      }
538    }
539    if (!defined(rustflags)) {
540      rustflags = _rustflags
541    } else {
542      rustflags += _rustflags
543    }
544  }
545}
546
547template("ohos_rust_proc_macro") {
548  assert(!defined(invoker.output_dir),
549         "output_dir is not allowed to be defined.")
550  if (defined(invoker.subsystem_name) && defined(invoker.part_name)) {
551    subsystem_name = invoker.subsystem_name
552    part_name = invoker.part_name
553  } else if (defined(invoker.part_name)) {
554    part_name = invoker.part_name
555    _part_subsystem_info_file =
556        "$root_build_dir/build_configs/parts_info/part_subsystem.json"
557    _arguments = [
558      "--part-name",
559      part_name,
560      "--part-subsystem-info-file",
561      rebase_path(_part_subsystem_info_file, root_build_dir),
562    ]
563    get_subsystem_script = "//build/templates/common/get_subsystem_name.py"
564    subsystem_name =
565        exec_script(get_subsystem_script, _arguments, "trim string")
566    if (is_use_check_deps) {
567      skip_check_subsystem = true
568    }
569  } else if (defined(invoker.subsystem_name)) {
570    subsystem_name = invoker.subsystem_name
571    part_name = subsystem_name
572  } else {
573    subsystem_name = "common"
574    part_name = subsystem_name
575  }
576  assert(subsystem_name != "")
577  assert(part_name != "")
578  if (is_use_check_deps) {
579    _check_target = "${target_name}__check"
580    target_path = get_label_info(":${target_name}", "label_no_toolchain")
581    check_target(_check_target) {
582      module_deps = []
583      if (defined(invoker.deps)) {
584        module_deps += invoker.deps
585      }
586      if (defined(invoker.public_deps)) {
587        module_deps += invoker.public_deps
588      }
589      if (defined(invoker.external_deps)) {
590        module_ex_deps = invoker.external_deps
591      }
592    }
593  }
594  if (check_deps) {
595    deps_data = {
596    }
597    module_label = get_label_info(":${target_name}", "label_with_toolchain")
598    module_deps = []
599    if (defined(invoker.deps)) {
600      foreach(dep, invoker.deps) {
601        module_deps += [ get_label_info(dep, "label_no_toolchain") ]
602      }
603    }
604    module_ex_deps = []
605    if (defined(invoker.external_deps) && invoker.external_deps != []) {
606      module_ex_deps = invoker.external_deps
607    }
608    deps_data = {
609      part_name = part_name
610      module_label = module_label
611      deps = module_deps
612      external_deps = module_ex_deps
613    }
614    write_file("${root_out_dir}/deps_files/${part_name}__${target_name}.json",
615               deps_data,
616               "json")
617  }
618
619  if (is_standard_system) {
620    output_dir = "${root_out_dir}/${subsystem_name}/${part_name}"
621  } else {
622    output_dir = "${root_out_dir}"
623  }
624
625  _test_target = defined(invoker.testonly) && invoker.testonly
626  if (!_test_target) {
627    _notice_target = "${target_name}__notice"
628    _main_target_name = target_name
629    collect_notice(_notice_target) {
630      forward_variables_from(invoker,
631                             [
632                               "testonly",
633                               "license_as_sources",
634                               "license_file",
635                             ])
636
637      module_name = _main_target_name
638      module_source_dir = get_label_info(":${_main_target_name}", "dir")
639    }
640  }
641
642  target_label = get_label_info(":${target_name}", "label_with_toolchain")
643  target_toolchain = get_label_info(target_label, "toolchain")
644
645  if (target_toolchain == "${current_toolchain}") {
646    ohos_module_name = target_name
647    _module_info_target = "${target_name}_info"
648    generate_module_info(_module_info_target) {
649      module_name = ohos_module_name
650      module_type = "lib"
651      module_source_dir = "$root_out_dir"
652      if (defined(output_dir)) {
653        module_source_dir = output_dir
654      }
655
656      module_install_name = ohos_module_name
657      if (defined(invoker.output_name)) {
658        module_install_name = invoker.output_name
659      }
660
661      module_install_images = [ "system" ]
662      if (defined(invoker.install_images)) {
663        module_install_images = []
664        module_install_images += invoker.install_images
665      }
666
667      module_output_extension = shlib_extension
668      if (defined(invoker.output_extension)) {
669        module_output_extension = "." + invoker.output_extension
670      }
671
672      install_enable = true
673      if (defined(invoker.install_enable)) {
674        install_enable = invoker.install_enable
675      }
676
677      if (defined(invoker.module_install_dir)) {
678        module_install_dir = invoker.module_install_dir
679      }
680
681      if (defined(invoker.relative_install_dir)) {
682        relative_install_dir = invoker.relative_install_dir
683      }
684
685      if (defined(invoker.symlink_target_name)) {
686        symlink_target_name = invoker.symlink_target_name
687      }
688
689      if (defined(invoker.output_prefix_override)) {
690        output_prefix_override = invoker.output_prefix_override
691      }
692      notice = "$target_out_dir/$ohos_module_name.notice.txt"
693    }
694  }
695
696  _rustflags = []
697  rust_target(target_name) {
698    target_type = "rust_proc_macro"
699    forward_variables_from(invoker,
700                           "*",
701                           [
702                             "configs",
703                             "remove_configs",
704                             "no_default_deps",
705                             "external_deps",
706                             "install_images",
707                             "module_install_dir",
708                             "relative_install_dir",
709                             "symlink_target_name",
710                             "output_dir",
711                             "install_enable",
712                             "version_script",
713                             "license_file",
714                             "license_as_sources",
715                             "use_exceptions",
716                             "stl",
717
718                             # Sanitizer variables
719                             "sanitize",
720                           ])
721    if (!defined(invoker.crate_name)) {
722      crate_name = _target_name
723    }
724    crate_type = "proc-macro"
725    if (defined(invoker.crate_type)) {
726      assert(invoker.crate_type == crate_type,
727             "crate_type should be $crate_type or use default value.")
728    }
729
730    output_dir = output_dir
731
732    if (!defined(inputs)) {
733      inputs = []
734    }
735
736    if (!defined(ldflags)) {
737      ldflags = []
738    }
739
740    if (defined(invoker.configs)) {
741      configs += invoker.configs
742    }
743    if (defined(invoker.remove_configs)) {
744      configs -= invoker.remove_configs
745    }
746
747    if (!defined(output_name)) {
748      output_name = target_name
749    }
750
751    if (defined(invoker.no_default_deps)) {
752      no_default_deps = invoker.no_default_deps
753    }
754
755    if (!defined(libs)) {
756      libs = []
757    }
758    if (!defined(cflags_cc)) {
759      cflags_cc = []
760    }
761    if (!defined(deps)) {
762      deps = []
763    }
764    if (is_use_check_deps) {
765      deps += [ ":$_check_target" ]
766    }
767    if (target_toolchain == "${current_toolchain}" && !skip_gen_module_info) {
768      deps += [ ":$_module_info_target" ]
769    }
770
771    if (!_test_target) {
772      deps += [ ":$_notice_target" ]
773    }
774    if (!defined(include_dirs)) {
775      include_dirs = []
776    }
777    if (defined(invoker.external_deps)) {
778      component_override_map = rebase_path(
779              "${root_build_dir}/build_configs/component_override_map.json")
780      external_deps_script =
781          rebase_path("//build/templates/common/external_deps_handler.py")
782      external_deps_temp_file =
783          "$target_gen_dir/${part_name}__${target_name}_external_deps_temp.json"
784      arguments = [ "--external-deps" ]
785      arguments += invoker.external_deps
786      arguments += [
787        "--parts-src-flag-file",
788        rebase_path(parts_src_flag_file, root_build_dir),
789        "--external-deps-temp-file",
790        rebase_path(external_deps_temp_file, root_build_dir),
791        "--sdk-base-dir",
792        rebase_path("${innersdk_base_dir}", root_build_dir),
793        "--sdk-dir-name",
794        "${innersdk_dir_name}",
795        "--current-toolchain",
796        current_toolchain,
797        "--innerkits-adapter-info-file",
798        rebase_path("//build/ohos/inner_kits_adapter.json", root_build_dir),
799        "--component-override-map",
800        component_override_map,
801      ]
802      if (is_use_sdk) {
803        arguments += [ "--use-sdk" ]
804      }
805
806      handler_result = exec_script(external_deps_script, arguments, "string")
807      if (handler_result != "") {
808        print(handler_result)
809      }
810
811      external_deps_info = read_file(external_deps_temp_file, "json")
812      if (defined(external_deps_info.deps)) {
813        deps += external_deps_info.deps
814      }
815      if (defined(external_deps_info.libs)) {
816        libs += external_deps_info.libs
817      }
818      if (defined(external_deps_info.include_dirs)) {
819        include_dirs += external_deps_info.include_dirs
820      }
821    }
822
823    install_module_info = {
824      module_def = target_label
825      module_info_file =
826          rebase_path(get_label_info(module_def, "target_out_dir"),
827                      root_build_dir) + "/${target_name}_module_info.json"
828      subsystem_name = subsystem_name
829      part_name = part_name
830      toolchain = current_toolchain
831      toolchain_out_dir = rebase_path(root_out_dir, root_build_dir)
832    }
833    metadata = {
834      install_modules = [ install_module_info ]
835    }
836    if (defined(is_debug) && !is_debug && enable_debug_components != "") {
837      foreach(component_name, debug_components) {
838        if (part_name == component_name) {
839          configs -= default_opt_configs
840          configs += debug_level_configs
841        }
842      }
843    }
844
845    if (defined(invoker.rustc_lints)) {
846      rustc_lints = invoker.rustc_lints
847    }
848    if (defined(invoker.clippy_lints)) {
849      clippy_lints = invoker.clippy_lints
850    }
851
852    if (!defined(rustc_lints) && !defined(clippy_lints)) {
853      file_path =
854          get_path_info(get_path_info(invoker.sources, "dir"), "abspath")
855      file_path_split = string_split(file_path[0], "/")
856      source_dir_begin = file_path_split[2]
857
858      if (source_dir_begin == "third_party") {
859        _rustflags += allowAllLints
860      } else if (source_dir_begin == "prebuilts") {
861        _rustflags += allowAllLints
862      } else if (source_dir_begin == "vendor") {
863        _rustflags += rustcVendorLints
864        _rustflags += clippyVendorLints
865      } else if (source_dir_begin == "device") {
866        _rustflags += rustcVendorLints
867        _rustflags += clippyVendorLints
868      } else {
869        _rustflags += rustcOhosLints
870        _rustflags += clippyOhosLints
871      }
872    }
873
874    if (defined(rustc_lints)) {
875      if (invoker.rustc_lints == "openharmony") {
876        _rustflags += rustcOhosLints
877      } else if (rustc_lints == "vendor") {
878        _rustflags += rustcVendorLints
879      } else if (rustc_lints == "none") {
880        _rustflags += allowAllLints
881      }
882    }
883    if (defined(clippy_lints)) {
884      if (invoker.clippy_lints == "openharmony") {
885        _rustflags += clippyOhosLints
886      } else if (clippy_lints == "vendor") {
887        _rustflags += clippyVendorLints
888      } else if (clippy_lints == "none") {
889        _rustflags += allowAllLints
890      }
891    }
892    if (!defined(rustflags)) {
893      rustflags = _rustflags
894    } else {
895      rustflags += _rustflags
896    }
897  }
898}
899