• 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/ohos/config.gni")
16import("//build/config/security/security_config.gni")
17import("//build/ohos/notice/notice.gni")
18import("//build/ohos_var.gni")
19import("//build/templates/common/check_target.gni")
20import("//build/templates/metadata/module_info.gni")
21
22declare_args() {
23  # Compile with no sanitize check, for local debug only
24  allow_sanitize_debug = false
25}
26
27default_opt_configs = [
28  "//build/config/compiler:default_symbols",
29  "//build/config/compiler:default_optimization",
30]
31
32debug_level_configs = [
33  "//build/config/compiler:symbols",
34  "//build/config/compiler:no_optimize",
35]
36
37template("ohos_executable") {
38  assert(!defined(invoker.output_dir),
39         "output_dir is not allowed to be defined.")
40
41  _test_target = defined(invoker.testonly) && invoker.testonly
42  if (defined(invoker.subsystem_name) && defined(invoker.part_name)) {
43    subsystem_name = invoker.subsystem_name
44    part_name = invoker.part_name
45  } else if (defined(invoker.part_name)) {
46    part_name = invoker.part_name
47    _part_subsystem_info_file =
48        "$root_build_dir/build_configs/parts_info/part_subsystem.json"
49    _arguments = [
50      "--part-name",
51      part_name,
52      "--part-subsystem-info-file",
53      rebase_path(_part_subsystem_info_file, root_build_dir),
54    ]
55    get_subsystem_script = "//build/templates/common/get_subsystem_name.py"
56    subsystem_name =
57        exec_script(get_subsystem_script, _arguments, "trim string")
58    if (is_use_check_deps && !_test_target) {
59      skip_check_subsystem = true
60    }
61  } else if (defined(invoker.subsystem_name)) {
62    subsystem_name = invoker.subsystem_name
63    part_name = subsystem_name
64  } else {
65    subsystem_name = "build"
66    part_name = "build_framework"
67  }
68  assert(subsystem_name != "")
69  assert(part_name != "")
70
71  if (defined(is_arkui_x) && is_arkui_x && defined(invoker.external_deps)) {
72    invoker.external_deps = []
73  }
74
75  if (is_use_check_deps && !_test_target) {
76    _check_target = "${target_name}__check"
77    target_path = get_label_info(":${target_name}", "label_no_toolchain")
78    check_target(_check_target) {
79      module_deps = []
80      if (defined(invoker.deps)) {
81        module_deps += invoker.deps
82      }
83      if (defined(invoker.public_deps)) {
84        module_deps += invoker.public_deps
85      }
86      if (defined(invoker.external_deps)) {
87        module_ex_deps = invoker.external_deps
88      }
89    }
90  }
91
92  if (check_deps) {
93    deps_data = {
94    }
95    module_label = get_label_info(":${target_name}", "label_with_toolchain")
96    module_deps = []
97    if (defined(invoker.deps)) {
98      foreach(dep, invoker.deps) {
99        module_deps += [ get_label_info(dep, "label_no_toolchain") ]
100      }
101    }
102    module_ex_deps = []
103    if (defined(invoker.external_deps) && invoker.external_deps != []) {
104      module_ex_deps = invoker.external_deps
105    }
106    deps_data = {
107      part_name = part_name
108      module_label = module_label
109      deps = module_deps
110      external_deps = module_ex_deps
111    }
112
113    write_file("${root_out_dir}/deps_files/${part_name}__${target_name}.json",
114               deps_data,
115               "json")
116  }
117
118  _ohos_test = false
119  if (defined(invoker.ohos_test) && invoker.ohos_test) {
120    output_dir = invoker.test_output_dir
121    _ohos_test = true
122  } else {
123    if (is_standard_system) {
124      output_dir = "${root_out_dir}/${subsystem_name}/${part_name}"
125    } else {
126      output_dir = "${root_out_dir}"
127    }
128  }
129
130  _security_config_target = "${target_name}__security_config"
131  ohos_security_config(_security_config_target) {
132    forward_variables_from(invoker, [ "auto_var_init" ])
133  }
134
135  if (!allow_sanitize_debug && !build_xts &&
136      defined(ext_sanitizer_check_list_path)) {
137    build_name = "${target_name}"
138    ohos_sanitizer_check("${target_name}_sanitizer_check") {
139      forward_variables_from(invoker, [ "sanitize" ])
140    }
141  }
142
143  _sanitize_config_target = "${target_name}__sanitizer_config"
144  ohos_sanitizer_config(_sanitize_config_target) {
145    forward_variables_from(invoker, [ "sanitize" ])
146  }
147
148  if (!_test_target) {
149    _main_target_name = target_name
150    _notice_target = "${_main_target_name}__notice"
151    collect_notice(_notice_target) {
152      forward_variables_from(invoker,
153                             [
154                               "testonly",
155                               "license_as_sources",
156                               "license_file",
157                             ])
158
159      module_name = _main_target_name
160      module_source_dir = get_label_info(":${_main_target_name}", "dir")
161    }
162  }
163  target_label = get_label_info(":${target_name}", "label_with_toolchain")
164  target_toolchain = get_label_info(target_label, "toolchain")
165
166  if (!_ohos_test) {
167    ohos_module_name = target_name
168    _module_info_target = "${target_name}_info"
169    generate_module_info(_module_info_target) {
170      forward_variables_from(invoker, [ "testonly" ])
171      module_name = ohos_module_name
172      module_type = "bin"
173
174      module_source_dir = "$root_out_dir"
175      if (defined(output_dir)) {
176        module_source_dir = output_dir
177      }
178
179      module_install_name = ohos_module_name
180      if (defined(invoker.output_name)) {
181        module_install_name = invoker.output_name
182      }
183
184      module_install_images = [ "system" ]
185      if (defined(invoker.install_images)) {
186        module_install_images = []
187        module_install_images += invoker.install_images
188      }
189
190      module_output_extension = executable_extension
191      if (defined(invoker.output_extension)) {
192        module_output_extension = "." + invoker.output_extension
193      }
194
195      if (is_double_framework) {
196        install_enable = false
197      } else {
198        install_enable = true
199      }
200      if (defined(invoker.install_enable)) {
201        install_enable = invoker.install_enable
202      }
203
204      if (defined(invoker.module_install_dir)) {
205        module_install_dir = invoker.module_install_dir
206      }
207
208      if (defined(invoker.relative_install_dir)) {
209        relative_install_dir = invoker.relative_install_dir
210      }
211
212      if (defined(invoker.symlink_target_name)) {
213        symlink_target_name = invoker.symlink_target_name
214      }
215
216      if (defined(invoker.version_script)) {
217        version_script = rebase_path(invoker.version_script, root_build_dir)
218      }
219      notice = "$target_out_dir/$ohos_module_name.notice.txt"
220    }
221  }
222
223  if (!defined(invoker.stable)) {
224    stable = false
225  }
226
227  executable("${target_name}") {
228    forward_variables_from(invoker,
229                           "*",
230                           [
231                             "configs",
232                             "remove_configs",
233                             "static_link",
234                             "install_images",
235                             "module_install_dir",
236                             "relative_install_dir",
237                             "symlink_target_name",
238                             "output_dir",
239                             "install_enable",
240                             "version_script",
241                             "license_file",
242                             "license_as_sources",
243                             "use_exceptions",
244                             "use_rtti",
245
246                             # Sanitizer variables
247                             "sanitize",
248                             "crate_type",
249                             "stack_protector_ret",
250                             "branch_protector_ret",
251                           ])
252    output_dir = output_dir
253
254    if (defined(invoker.configs)) {
255      configs += invoker.configs
256    }
257    if (defined(invoker.remove_configs)) {
258      configs -= invoker.remove_configs
259    }
260    configs += [ ":$_sanitize_config_target" ]
261    configs += [ ":$_security_config_target" ]
262
263    if (defined(invoker.use_exceptions) && invoker.use_exceptions) {
264      configs += [ "//build/config/compiler:exceptions" ]
265      configs -= [ "//build/config/compiler:no_exceptions" ]
266    }
267
268    if (defined(invoker.use_rtti) && invoker.use_rtti) {
269      configs += [ "//build/config/compiler:rtti" ]
270      configs -= [ "//build/config/compiler:no_rtti" ]
271    }
272
273    if (!defined(cflags)) {
274      cflags = []
275    }
276
277    # Enable branch protection.
278    if (defined(invoker.branch_protector_ret)) {
279      if (invoker.branch_protector_ret == "pac_ret") {
280        # We need to remove stack_protector_ret_strong_config because it's conflict with pac-ret.
281        foreach(config, configs) {
282          if (config ==
283              "//build/config/security:stack_protector_ret_strong_config") {
284            configs -=
285                [ "//build/config/security:stack_protector_ret_strong_config" ]
286          }
287        }
288        if (support_branch_protector_pac_ret) {
289          cflags += [ "-mbranch-protection=pac-ret+b-key" ]
290        } else {
291          configs +=
292              [ "//build/config/security:stack_protector_ret_all_config" ]
293        }
294      }
295
296      if (support_stack_protector_ret &&
297          invoker.branch_protector_ret == "stack_protector_ret_all") {
298        configs -=
299            [ "//build/config/security:stack_protector_ret_strong_config" ]
300        configs += [ "//build/config/security:stack_protector_ret_all_config" ]
301      }
302
303      # Nothing to do, supported by default.
304      if (support_stack_protector_ret &&
305          invoker.branch_protector_ret == "stack_protector_ret_strong") {
306      }
307    } else {
308      if (support_stack_protector_ret) {
309        if (defined(invoker.stack_protector_ret)) {
310          configs -=
311              [ "//build/config/security:stack_protector_ret_strong_config" ]
312          if (invoker.stack_protector_ret) {
313            configs +=
314                [ "//build/config/security:stack_protector_ret_all_config" ]
315          } else {
316            configs += [ "//build/config/security:stack_protector_config" ]
317          }
318        }
319      }
320    }
321
322    if (!defined(deps)) {
323      deps = []
324    }
325    if (is_use_check_deps && !_test_target) {
326      deps += [ ":$_check_target" ]
327    }
328    if (!_ohos_test && !skip_gen_module_info) {
329      deps += [ ":$_module_info_target" ]
330    }
331    if (!defined(libs)) {
332      libs = []
333    }
334    if (!defined(include_dirs)) {
335      include_dirs = []
336    }
337    if (!defined(ldflags)) {
338      ldflags = []
339    }
340
341    if (defined(invoker.static_link) && invoker.static_link) {
342      no_default_deps = true
343      configs -= [ "//build/config:executable_config" ]
344      ldflags += [ "-static" ]
345      if (is_ohos && use_musl) {
346        import("//build/config/ohos/musl.gni")
347        deps += [ "//third_party/musl:soft_static_libs" ]
348      }
349    } else if (is_ohos) {
350      if (current_cpu == "arm" || current_cpu == "arm64" ||
351          current_cpu == "riscv64") {
352        libs += [ "unwind" ]
353      }
354      libs += [
355        rebase_path(libclang_rt_file),
356        "c++",
357      ]
358    }
359
360    if (!defined(output_name)) {
361      output_name = target_name
362    }
363
364    if (defined(invoker.version_script)) {
365      _version_script = rebase_path(invoker.version_script, root_build_dir)
366      if (!defined(ldflags)) {
367        ldflags = []
368      }
369      ldflags += [
370        "-rdynamic",
371        "-Wl,--version-script=${_version_script}",
372      ]
373    }
374
375    # We don't need to change config when "is_debug==true"
376    # "enable_debug_components" isn't blank means some components using debug level compilation
377    if (defined(is_debug) && !is_debug && enable_debug_components != "") {
378      foreach(component_name, debug_components) {
379        if (part_name == component_name) {
380          configs -= default_opt_configs
381          configs += debug_level_configs
382        }
383      }
384    }
385    if (target_toolchain == "${current_toolchain}") {
386      install_module_info = {
387        module_def = target_label
388        part_name = part_name
389        module_info_file =
390            rebase_path(get_label_info(module_def, "target_out_dir"),
391                        root_build_dir) + "/${target_name}_module_info.json"
392        subsystem_name = subsystem_name
393        part_name = part_name
394        toolchain = current_toolchain
395        toolchain_out_dir = rebase_path(root_out_dir, root_build_dir)
396      }
397      metadata = {
398        install_modules = [ install_module_info ]
399      }
400    }
401    if (!_test_target) {
402      deps += [ ":$_notice_target" ]
403    }
404
405    module_label = get_label_info(":${target_name}", "label_with_toolchain")
406
407    deps_info = []
408    foreach(dep, deps) {
409      info = {
410      }
411      info = {
412        target_out_dir =
413            rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir)
414        target_name = get_label_info(dep, "name")
415      }
416      deps_info += [ info ]
417    }
418    target_deps_data = {
419      label = module_label
420      module_deps_info = deps_info
421      module_libs = libs
422      type = "executable"
423      prebuilt = false
424      stable = stable
425      toolchain = get_label_info(":${target_name}", "toolchain")
426    }
427    write_file("${target_out_dir}/${target_name}_deps_data.json",
428               target_deps_data,
429               "json")
430  }
431}
432
433# Defines a shared_library
434#
435# The shared_library template is used to generated so file.
436#
437# Parameters
438#
439#   subsystem_name (required)
440#   [string]
441#   configs (optional)
442#   [list]
443#   remove_cnofigs (optional)
444#   [list]
445#   version_script (optional)
446#   [string]
447template("ohos_shared_library") {
448  assert(!defined(invoker.output_dir),
449         "output_dir is not allowed to be defined.")
450
451  _test_target = defined(invoker.testonly) && invoker.testonly
452  if (defined(invoker.subsystem_name) && defined(invoker.part_name)) {
453    subsystem_name = invoker.subsystem_name
454    part_name = invoker.part_name
455  } else if (defined(invoker.part_name)) {
456    part_name = invoker.part_name
457    _part_subsystem_info_file =
458        "$root_build_dir/build_configs/parts_info/part_subsystem.json"
459    _arguments = [
460      "--part-name",
461      part_name,
462      "--part-subsystem-info-file",
463      rebase_path(_part_subsystem_info_file, root_build_dir),
464    ]
465    get_subsystem_script = "//build/templates/common/get_subsystem_name.py"
466    subsystem_name =
467        exec_script(get_subsystem_script, _arguments, "trim string")
468    if (is_use_check_deps && !_test_target) {
469      skip_check_subsystem = true
470    }
471  } else if (defined(invoker.subsystem_name)) {
472    subsystem_name = invoker.subsystem_name
473    part_name = subsystem_name
474  } else {
475    subsystem_name = "build"
476    part_name = "build_framework"
477  }
478  assert(subsystem_name != "")
479  assert(part_name != "")
480
481  if (defined(is_arkui_x) && is_arkui_x && defined(invoker.external_deps)) {
482    invoker.external_deps = []
483  }
484
485  if (is_use_check_deps && !_test_target) {
486    _check_target = "${target_name}__check"
487    target_path = get_label_info(":${target_name}", "label_no_toolchain")
488    check_target(_check_target) {
489      module_deps = []
490      if (defined(invoker.deps)) {
491        module_deps += invoker.deps
492      }
493      if (defined(invoker.public_deps)) {
494        module_deps += invoker.public_deps
495      }
496      if (defined(invoker.external_deps)) {
497        module_ex_deps = invoker.external_deps
498      }
499    }
500  }
501
502  # auto set auto_relative_install_dir by innerapi_tags
503  if (defined(invoker.innerapi_tags)) {
504    is_chipsetsdk = false
505    is_platformsdk = false
506    is_passthrough = false
507    foreach(tag, filter_include(invoker.innerapi_tags, [ "chipsetsdk*" ])) {
508      is_chipsetsdk = true
509    }
510    foreach(tag, filter_include(invoker.innerapi_tags, [ "platformsdk*" ])) {
511      is_platformsdk = true
512    }
513    foreach(tag, filter_include(invoker.innerapi_tags, [ "passthrough*" ])) {
514      is_passthrough = true
515    }
516
517    if (is_chipsetsdk && is_platformsdk) {
518      auto_relative_install_dir = "chipset-pub-sdk"
519    } else if (is_chipsetsdk) {
520      auto_relative_install_dir = "chipset-sdk"
521    } else if (is_platformsdk) {
522      auto_relative_install_dir = "platformsdk"
523    }
524    if (is_passthrough) {
525      auto_relative_install_dir = chipset_passthrough_dir
526    }
527
528    is_ndk = false
529    foreach(tag, filter_include(invoker.innerapi_tags, [ "ndk" ])) {
530      is_ndk = true
531    }
532    if (is_ndk) {
533      auto_relative_install_dir = "ndk"
534    }
535  }
536
537  if (check_deps) {
538    deps_data = {
539    }
540    module_label = get_label_info(":${target_name}", "label_with_toolchain")
541    module_deps = []
542    if (defined(invoker.deps)) {
543      foreach(dep, invoker.deps) {
544        module_deps += [ get_label_info(dep, "label_no_toolchain") ]
545      }
546    }
547    module_ex_deps = []
548    if (defined(invoker.external_deps) && invoker.external_deps != []) {
549      module_ex_deps = invoker.external_deps
550    }
551    deps_data = {
552      part_name = part_name
553      module_label = module_label
554      deps = module_deps
555      external_deps = module_ex_deps
556    }
557    write_file("${root_out_dir}/deps_files/${part_name}__${target_name}.json",
558               deps_data,
559               "json")
560  }
561
562  if (is_standard_system) {
563    output_dir = "${root_out_dir}/${subsystem_name}/${part_name}"
564  } else {
565    output_dir = "${root_out_dir}"
566  }
567
568  _security_config_target = "${target_name}__security_config"
569  ohos_security_config(_security_config_target) {
570    forward_variables_from(invoker, [ "auto_var_init" ])
571  }
572
573  if (!allow_sanitize_debug && !build_xts &&
574      defined(ext_sanitizer_check_list_path)) {
575    build_name = "${target_name}"
576    ohos_sanitizer_check("${target_name}_sanitizer_check") {
577      forward_variables_from(invoker, [ "sanitize" ])
578    }
579  }
580
581  _sanitize_config_target = "${target_name}__sanitizer_config"
582  ohos_sanitizer_config(_sanitize_config_target) {
583    forward_variables_from(invoker, [ "sanitize" ])
584  }
585
586  if (!_test_target) {
587    _notice_target = "${target_name}__notice"
588    _main_target_name = target_name
589    collect_notice(_notice_target) {
590      forward_variables_from(invoker,
591                             [
592                               "testonly",
593                               "license_as_sources",
594                               "license_file",
595                             ])
596
597      module_name = _main_target_name
598      module_source_dir = get_label_info(":${_main_target_name}", "dir")
599    }
600  }
601
602  target_label = get_label_info(":${target_name}", "label_with_toolchain")
603  target_toolchain = get_label_info(target_label, "toolchain")
604
605  if (target_toolchain == "${current_toolchain}") {
606    ohos_module_name = target_name
607    _module_info_target = "${target_name}_info"
608    generate_module_info(_module_info_target) {
609      forward_variables_from(invoker, [ "testonly" ])
610      module_name = ohos_module_name
611      module_type = "lib"
612      module_source_dir = "$root_out_dir"
613      if (defined(output_dir)) {
614        module_source_dir = output_dir
615      }
616
617      module_install_name = ohos_module_name
618      if (defined(invoker.output_name)) {
619        module_install_name = invoker.output_name
620      }
621
622      module_install_images = [ "system" ]
623      if (defined(invoker.install_images)) {
624        module_install_images = []
625        module_install_images += invoker.install_images
626      }
627
628      module_output_extension = shlib_extension
629      if (defined(invoker.output_extension)) {
630        module_output_extension = "." + invoker.output_extension
631      }
632
633      install_enable = true
634      if (defined(invoker.install_enable)) {
635        install_enable = invoker.install_enable
636      }
637
638      if (defined(invoker.module_install_dir)) {
639        module_install_dir = invoker.module_install_dir
640      }
641
642      if (defined(invoker.symlink_target_name)) {
643        symlink_target_name = invoker.symlink_target_name
644      }
645
646      if (defined(invoker.output_prefix_override)) {
647        output_prefix_override = invoker.output_prefix_override
648      }
649      notice = "$target_out_dir/$ohos_module_name.notice.txt"
650
651      # update relative_install_dir if auto_relative_install_dir defined
652      if (defined(auto_relative_install_dir)) {
653        relative_install_dir = auto_relative_install_dir
654      }
655
656      # update relative_install_dir if relative_install_dir defined in BUILD.gn
657      if (defined(invoker.relative_install_dir)) {
658        relative_install_dir = invoker.relative_install_dir
659      }
660
661      # Passing shlib_type and innerapi_tags to generate_module_info
662      if (defined(invoker.shlib_type)) {
663        invalid = true
664        valid_types = [
665          "sa",
666          "sa_stub",
667          "sa_proxy",
668          "hdi",
669          "hdi_stub",
670          "hdi_proxy",
671          "innerapi",
672          "napi",
673        ]
674        foreach(t, filter_include(valid_types, [ invoker.shlib_type ])) {
675          if (t == invoker.shlib_type) {
676            invalid = false
677          }
678        }
679        shlib_type = invoker.shlib_type
680        assert(
681            invalid != true,
682            "$target_label has invalid shlib_type value: $shlib_type, allowed values: $valid_types")
683      }
684      if (defined(invoker.innerapi_tags)) {
685        invalid = false
686        valid_tags = [
687          "ndk",
688          "chipsetsdk",
689          "chipsetsdk_indirect",
690          "platformsdk",
691          "platformsdk_indirect",
692          "passthrough",
693          "passthrough_indirect",
694          "sasdk",
695        ]
696        foreach(tag, filter_exclude(invoker.innerapi_tags, valid_tags)) {
697          if (tag != "") {
698            invalid = true
699          }
700        }
701        innerapi_tags = invoker.innerapi_tags
702        assert(
703            invalid != true,
704            "$target_label has invalid innerapi_tags $innerapi_tags, allowed values: $valid_tags")
705      }
706
707      if (defined(invoker.version_script)) {
708        version_script = rebase_path(invoker.version_script, root_build_dir)
709      }
710    }
711  }
712
713  if (!defined(invoker.stable)) {
714    stable = false
715  }
716
717  shared_library("${target_name}") {
718    forward_variables_from(invoker,
719                           "*",
720                           [
721                             "configs",
722                             "remove_configs",
723                             "no_default_deps",
724                             "install_images",
725                             "module_install_dir",
726                             "relative_install_dir",
727                             "symlink_target_name",
728                             "output_dir",
729                             "install_enable",
730                             "version_script",
731                             "exported_symbols_list",
732                             "license_file",
733                             "license_as_sources",
734                             "use_exceptions",
735                             "use_rtti",
736                             "stl",
737
738                             # Sanitizer variables
739                             "sanitize",
740                             "stack_protector_ret",
741                             "branch_protector_ret",
742                           ])
743    output_dir = output_dir
744
745    if (!defined(inputs)) {
746      inputs = []
747    }
748
749    if (!defined(ldflags)) {
750      ldflags = []
751    }
752
753    if (defined(invoker.configs)) {
754      configs += invoker.configs
755    }
756    if (defined(invoker.remove_configs)) {
757      configs -= invoker.remove_configs
758    }
759
760    configs += [ ":$_sanitize_config_target" ]
761    configs += [ ":$_security_config_target" ]
762
763    if (defined(invoker.use_exceptions) && invoker.use_exceptions) {
764      configs += [ "//build/config/compiler:exceptions" ]
765      configs -= [ "//build/config/compiler:no_exceptions" ]
766    }
767
768    if (defined(invoker.use_rtti) && invoker.use_rtti) {
769      configs += [ "//build/config/compiler:rtti" ]
770      configs -= [ "//build/config/compiler:no_rtti" ]
771    }
772
773    if (!defined(cflags)) {
774      cflags = []
775    }
776
777    # Enable branch protection.
778    if (defined(invoker.branch_protector_ret)) {
779      if (invoker.branch_protector_ret == "pac_ret") {
780        # We need to remove stack_protector_ret_strong_config because it's conflict with pac-ret.
781        foreach(config, configs) {
782          if (config ==
783              "//build/config/security:stack_protector_ret_strong_config") {
784            configs -=
785                [ "//build/config/security:stack_protector_ret_strong_config" ]
786          }
787        }
788        if (support_branch_protector_pac_ret) {
789          cflags += [ "-mbranch-protection=pac-ret+b-key" ]
790        } else {
791          configs +=
792              [ "//build/config/security:stack_protector_ret_all_config" ]
793        }
794      }
795
796      if (support_stack_protector_ret &&
797          invoker.branch_protector_ret == "stack_protector_ret_all") {
798        configs -=
799            [ "//build/config/security:stack_protector_ret_strong_config" ]
800        configs += [ "//build/config/security:stack_protector_ret_all_config" ]
801      }
802
803      # Nothing to do, supported by default.
804      if (support_stack_protector_ret &&
805          invoker.branch_protector_ret == "stack_protector_ret_strong") {
806      }
807    } else {
808      if (support_stack_protector_ret) {
809        if (defined(invoker.stack_protector_ret)) {
810          configs -=
811              [ "//build/config/security:stack_protector_ret_strong_config" ]
812          if (invoker.stack_protector_ret) {
813            configs +=
814                [ "//build/config/security:stack_protector_ret_all_config" ]
815          } else {
816            configs += [ "//build/config/security:stack_protector_config" ]
817          }
818        }
819      }
820    }
821
822    # check whether to add adlt configs
823    install_enable = true
824    if (defined(invoker.install_enable)) {
825      install_enable = invoker.install_enable
826    }
827    if (install_enable && enable_adlt && is_standard_system &&
828        target_toolchain == "${current_toolchain}" && is_ohos) {
829      inputs_args = []
830      if (target_cpu == "arm64" || target_cpu == "x86_64") {
831        module_type = "lib64"
832      } else if (target_cpu == "arm" || target_cpu == "x86") {
833        module_type = "lib"
834      } else {
835        assert(false, "Unsupported target_cpu: $target_cpu")
836      }
837      inputs_args += [
838        "--type",
839        module_type,
840        "--system-base-dir",
841        system_base_dir,
842      ]
843
844      module_install_name = target_name
845      if (defined(invoker.output_name)) {
846        module_install_name = invoker.output_name
847      }
848      inputs_args += [
849        "--install-name",
850        module_install_name,
851      ]
852
853      module_install_images = [ "system" ]
854      if (defined(invoker.install_images)) {
855        module_install_images = []
856        module_install_images += invoker.install_images
857      }
858      inputs_args += [ "--install-images" ]
859      inputs_args += module_install_images
860
861      if (defined(invoker.module_install_dir) &&
862          invoker.module_install_dir != "") {
863        inputs_args += [
864          "--module-install-dir",
865          invoker.module_install_dir,
866        ]
867      }
868      if (defined(invoker.relative_install_dir)) {
869        relative_install_dir = invoker.relative_install_dir
870      }
871      if (defined(auto_relative_install_dir)) {
872        relative_install_dir = auto_relative_install_dir
873      }
874      if (defined(relative_install_dir) && relative_install_dir != "") {
875        inputs_args += [
876          "--relative-install-dir",
877          relative_install_dir,
878        ]
879      }
880
881      module_output_extension = shlib_extension
882      if (defined(invoker.output_extension)) {
883        module_output_extension = "." + invoker.output_extension
884      }
885      if (module_output_extension != "") {
886        inputs_args += [
887          "--suffix",
888          module_output_extension,
889        ]
890      }
891
892      if (defined(invoker.output_prefix_override) &&
893          invoker.output_prefix_override) {
894        inputs_args += [ "--prefix-override" ]
895      }
896      inputs_args += [
897        "--allowed-lib-list",
898        rebase_path(allowed_lib_list),
899      ]
900      result = exec_script("//build/ohos/images/get_module_install_dest.py",
901                           inputs_args,
902                           "string")
903      if (result == "") {
904        configs += [ "//build/config/ohos:adlt_config" ]
905      }
906    }
907
908    if (!defined(output_name)) {
909      output_name = target_name
910    }
911
912    if (defined(invoker.no_default_deps)) {
913      no_default_deps = invoker.no_default_deps
914    }
915
916    if (defined(invoker.version_script)) {
917      _version_script = rebase_path(invoker.version_script, root_build_dir)
918      inputs += [ invoker.version_script ]
919      ldflags += [ "-Wl,--version-script=${_version_script}" ]
920    }
921
922    if (target_os == "ios" && defined(invoker.exported_symbols_list)) {
923      _exported_symbols_list =
924          rebase_path(invoker.exported_symbols_list, root_build_dir)
925      inputs += [ invoker.exported_symbols_list ]
926      ldflags += [
927        "-exported_symbols_list",
928        "${_exported_symbols_list}",
929      ]
930    }
931
932    if (!defined(ldflags)) {
933      ldflags = []
934    }
935    if (!defined(libs)) {
936      libs = []
937    }
938    if (!defined(cflags_cc)) {
939      cflags_cc = []
940    }
941    if (!defined(deps)) {
942      deps = []
943    }
944    if (is_use_check_deps && !_test_target) {
945      deps += [ ":$_check_target" ]
946    }
947    if (target_toolchain == "${current_toolchain}" && !skip_gen_module_info) {
948      deps += [ ":$_module_info_target" ]
949    }
950    if (is_ohos) {
951      if (defined(invoker.stl)) {
952        cflags_cc += [
953          "-nostdinc++",
954          "-I" + rebase_path(
955                  "${toolchains_dir}/${host_platform_dir}/llvm_ndk/include/libcxx-ohos/include/c++/v1",
956                  root_build_dir),
957        ]
958        ldflags += [
959          "-nostdlib++",
960          "-L" + rebase_path("${clang_stl_path}/${abi_target}", root_build_dir),
961        ]
962
963        libs += [ invoker.stl ]
964      } else {
965        if (current_cpu == "arm" || current_cpu == "arm64" ||
966            current_cpu == "riscv64") {
967          libs += [ "unwind" ]
968        }
969
970        libs += [ rebase_path(libclang_rt_file) ]
971        if (target_name != "libpcre2" && target_name != "libselinux" &&
972            target_name != "libsec_shared" && target_name != "libsepol") {
973          libs += [ "c++" ]
974        }
975      }
976    }
977
978    if (!_test_target) {
979      deps += [ ":$_notice_target" ]
980    }
981    if (!defined(include_dirs)) {
982      include_dirs = []
983    }
984
985    install_module_info = {
986      module_def = target_label
987      module_info_file =
988          rebase_path(get_label_info(module_def, "target_out_dir"),
989                      root_build_dir) + "/${target_name}_module_info.json"
990      subsystem_name = subsystem_name
991      part_name = part_name
992      toolchain = current_toolchain
993      toolchain_out_dir = rebase_path(root_out_dir, root_build_dir)
994    }
995    metadata = {
996      install_modules = [ install_module_info ]
997    }
998    if (defined(is_debug) && !is_debug && enable_debug_components != "") {
999      foreach(component_name, debug_components) {
1000        if (part_name == component_name) {
1001          configs -= default_opt_configs
1002          configs += debug_level_configs
1003        }
1004      }
1005    }
1006
1007    # Hide symbols for all sa libraries if not specified by version_script
1008    if (defined(invoker.shlib_type) && invoker.shlib_type == "sa") {
1009      if (!defined(invoker.version_script)) {
1010        _version_script =
1011            rebase_path("//build/templates/cxx/singleton.versionscript")
1012        inputs += [ _version_script ]
1013        ldflags += [ "-Wl,--version-script=${_version_script}" ]
1014      }
1015    }
1016
1017    # Set version_script for hdi service libraries
1018    if (defined(invoker.shlib_type) && invoker.shlib_type == "hdi") {
1019      if (!defined(invoker.version_script)) {
1020        _version_script = rebase_path("//build/templates/cxx/hdi.versionscript")
1021        inputs += [ _version_script ]
1022        ldflags += [ "-Wl,--version-script=${_version_script}" ]
1023      }
1024    }
1025
1026    module_type_napi = false
1027    if (defined(invoker.relative_install_dir) &&
1028        (build_ohos_sdk != true && build_ohos_ndk != true)) {
1029      relative_paths = string_split(invoker.relative_install_dir, "/")
1030      foreach(p, relative_paths) {
1031        if (p == "module") {
1032          module_type_napi = true
1033        }
1034      }
1035      if (module_type_napi) {
1036        foreach(m, filter_include(napi_white_list, [ target_name ])) {
1037          if (m == target_name) {
1038            module_type_napi = false
1039          }
1040        }
1041      }
1042    }
1043    if (module_type_napi) {
1044      if (!defined(invoker.version_script)) {
1045        _version_script =
1046            rebase_path("//build/templates/cxx/napi.versionscript")
1047        inputs += [ _version_script ]
1048        ldflags += [ "-Wl,--version-script=${_version_script}" ]
1049      }
1050    }
1051
1052    deps_info = []
1053    foreach(dep, deps) {
1054      info = {
1055      }
1056      info = {
1057        target_out_dir =
1058            rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir)
1059        target_name = get_label_info(dep, "name")
1060      }
1061      deps_info += [ info ]
1062    }
1063    module_label = get_label_info(":${target_name}", "label_with_toolchain")
1064    target_deps_data = {
1065      label = module_label
1066      module_deps_info = deps_info
1067      module_libs = libs
1068      type = "shared_library"
1069      prebuilt = false
1070      stable = stable
1071      toolchain = get_label_info(":${target_name}", "toolchain")
1072    }
1073    write_file("${target_out_dir}/${target_name}_deps_data.json",
1074               target_deps_data,
1075               "json")
1076  }
1077}
1078
1079template("ohos_static_library") {
1080  _test_target = defined(invoker.testonly) && invoker.testonly
1081  if (defined(invoker.subsystem_name) && defined(invoker.part_name)) {
1082    subsystem_name = invoker.subsystem_name
1083    part_name = invoker.part_name
1084  } else if (defined(invoker.part_name)) {
1085    part_name = invoker.part_name
1086    _part_subsystem_info_file =
1087        "$root_build_dir/build_configs/parts_info/part_subsystem.json"
1088    _arguments = [
1089      "--part-name",
1090      part_name,
1091      "--part-subsystem-info-file",
1092      rebase_path(_part_subsystem_info_file, root_build_dir),
1093    ]
1094    get_subsystem_script = "//build/templates/common/get_subsystem_name.py"
1095    subsystem_name =
1096        exec_script(get_subsystem_script, _arguments, "trim string")
1097    if (is_use_check_deps && !_test_target) {
1098      skip_check_subsystem = true
1099    }
1100  } else if (defined(invoker.subsystem_name)) {
1101    subsystem_name = invoker.subsystem_name
1102    part_name = subsystem_name
1103  } else {
1104    subsystem_name = "build"
1105    part_name = "build_framework"
1106  }
1107  assert(subsystem_name != "")
1108  assert(part_name != "")
1109
1110  if (defined(is_arkui_x) && is_arkui_x && defined(invoker.external_deps)) {
1111    invoker.external_deps = []
1112  }
1113
1114  if (is_use_check_deps && !_test_target) {
1115    _check_target = "${target_name}__check"
1116    target_path = get_label_info(":${target_name}", "label_no_toolchain")
1117    check_target(_check_target) {
1118      module_deps = []
1119      if (defined(invoker.deps)) {
1120        module_deps += invoker.deps
1121      }
1122      if (defined(invoker.public_deps)) {
1123        module_deps += invoker.public_deps
1124      }
1125      if (defined(invoker.external_deps)) {
1126        module_ex_deps = invoker.external_deps
1127      }
1128    }
1129  }
1130  if (check_deps) {
1131    deps_data = {
1132    }
1133    module_label = get_label_info(":${target_name}", "label_with_toolchain")
1134    module_deps = []
1135    if (defined(invoker.deps)) {
1136      foreach(dep, invoker.deps) {
1137        module_deps += [ get_label_info(dep, "label_no_toolchain") ]
1138      }
1139    }
1140    module_ex_deps = []
1141    if (defined(invoker.external_deps) && invoker.external_deps != []) {
1142      module_ex_deps = invoker.external_deps
1143    }
1144    deps_data = {
1145      part_name = part_name
1146      module_label = module_label
1147      deps = module_deps
1148      external_deps = module_ex_deps
1149    }
1150
1151    write_file("${root_out_dir}/deps_files/${part_name}__${target_name}.json",
1152               deps_data,
1153               "json")
1154  }
1155
1156  _security_config_target = "${target_name}__security_config"
1157  ohos_security_config(_security_config_target) {
1158    forward_variables_from(invoker, [ "auto_var_init" ])
1159  }
1160
1161  if (!allow_sanitize_debug && !build_xts &&
1162      defined(ext_sanitizer_check_list_path)) {
1163    build_name = "${target_name}"
1164    ohos_sanitizer_check("${target_name}_sanitizer_check") {
1165      forward_variables_from(invoker, [ "sanitize" ])
1166    }
1167  }
1168
1169  _sanitize_config_target = "${target_name}__sanitizer_config"
1170  ohos_sanitizer_config(_sanitize_config_target) {
1171    forward_variables_from(invoker, [ "sanitize" ])
1172  }
1173
1174  if (!_test_target) {
1175    _notice_target = "${target_name}__notice"
1176    _main_target_name = target_name
1177    collect_notice(_notice_target) {
1178      forward_variables_from(invoker,
1179                             [
1180                               "testonly",
1181                               "license_as_sources",
1182                               "license_file",
1183                             ])
1184      module_type = "static_library"
1185      module_name = _main_target_name
1186      module_source_dir = get_label_info(":${_main_target_name}", "dir")
1187    }
1188  }
1189
1190  static_library(target_name) {
1191    forward_variables_from(invoker,
1192                           "*",
1193                           [
1194                             "configs",
1195                             "remove_configs",
1196                             "no_default_deps",
1197                             "license_file",
1198                             "license_as_sources",
1199                             "use_exceptions",
1200                             "use_rtti",
1201                             "subsystem_name",
1202
1203                             # Sanitizer variables
1204                             "sanitize",
1205                             "stack_protector_ret",
1206                             "branch_protector_ret",
1207                           ])
1208    if (defined(invoker.configs)) {
1209      configs += invoker.configs
1210    }
1211    if (defined(invoker.remove_configs)) {
1212      configs -= invoker.remove_configs
1213    }
1214    if (is_standard_system) {
1215      configs -= [ "//build/config/compiler:thin_archive" ]
1216    }
1217    configs += [ ":$_sanitize_config_target" ]
1218    configs += [ ":$_security_config_target" ]
1219
1220    if (defined(invoker.use_exceptions) && invoker.use_exceptions) {
1221      configs += [ "//build/config/compiler:exceptions" ]
1222      configs -= [ "//build/config/compiler:no_exceptions" ]
1223    }
1224
1225    if (defined(invoker.use_rtti) && invoker.use_rtti) {
1226      configs += [ "//build/config/compiler:rtti" ]
1227      configs -= [ "//build/config/compiler:no_rtti" ]
1228    }
1229
1230    if (!defined(cflags)) {
1231      cflags = []
1232    }
1233
1234    # Enable branch protection.
1235    if (defined(invoker.branch_protector_ret)) {
1236      if (invoker.branch_protector_ret == "pac_ret") {
1237        # We need to remove stack_protector_ret_strong_config because it's conflict with pac-ret.
1238        foreach(config, configs) {
1239          if (config ==
1240              "//build/config/security:stack_protector_ret_strong_config") {
1241            configs -=
1242                [ "//build/config/security:stack_protector_ret_strong_config" ]
1243          }
1244        }
1245        if (support_branch_protector_pac_ret) {
1246          cflags += [ "-mbranch-protection=pac-ret+b-key" ]
1247        } else {
1248          configs +=
1249              [ "//build/config/security:stack_protector_ret_all_config" ]
1250        }
1251      }
1252
1253      if (support_stack_protector_ret &&
1254          invoker.branch_protector_ret == "stack_protector_ret_all") {
1255        configs -=
1256            [ "//build/config/security:stack_protector_ret_strong_config" ]
1257        configs += [ "//build/config/security:stack_protector_ret_all_config" ]
1258      }
1259
1260      # Nothing to do, supported by default.
1261      if (support_stack_protector_ret &&
1262          invoker.branch_protector_ret == "stack_protector_ret_strong") {
1263      }
1264    } else {
1265      if (support_stack_protector_ret) {
1266        if (defined(invoker.stack_protector_ret)) {
1267          configs -=
1268              [ "//build/config/security:stack_protector_ret_strong_config" ]
1269          if (invoker.stack_protector_ret) {
1270            configs +=
1271                [ "//build/config/security:stack_protector_ret_all_config" ]
1272          } else {
1273            configs += [ "//build/config/security:stack_protector_config" ]
1274          }
1275        }
1276      }
1277    }
1278
1279    if (defined(invoker.no_default_deps)) {
1280      no_default_deps = invoker.no_default_deps
1281    }
1282
1283    if (!defined(deps)) {
1284      deps = []
1285    }
1286    if (is_use_check_deps && !_test_target) {
1287      deps += [ ":$_check_target" ]
1288    }
1289    if (!_test_target) {
1290      deps += [ ":$_notice_target" ]
1291    }
1292    if (!defined(libs)) {
1293      libs = []
1294    }
1295    if (!defined(include_dirs)) {
1296      include_dirs = []
1297    }
1298
1299    if (defined(is_debug) && !is_debug && enable_debug_components != "") {
1300      foreach(component_name, debug_components) {
1301        if (part_name == component_name) {
1302          configs -= default_opt_configs
1303          configs += debug_level_configs
1304        }
1305      }
1306    }
1307
1308    deps_info = []
1309    foreach(dep, deps) {
1310      info = {
1311      }
1312      info = {
1313        target_out_dir =
1314            rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir)
1315        target_name = get_label_info(dep, "name")
1316      }
1317      deps_info += [ info ]
1318    }
1319    module_label = get_label_info(":${target_name}", "label_with_toolchain")
1320    target_deps_data = {
1321      label = module_label
1322      module_deps_info = deps_info
1323      module_libs = libs
1324      type = "static_library"
1325      prebuilt = false
1326      toolchain = get_label_info(":${target_name}", "toolchain")
1327    }
1328    write_file("${target_out_dir}/${target_name}_deps_data.json",
1329               target_deps_data,
1330               "json")
1331  }
1332}
1333
1334template("ohos_source_set") {
1335  _test_target = defined(invoker.testonly) && invoker.testonly
1336  if (defined(invoker.subsystem_name) && defined(invoker.part_name)) {
1337    subsystem_name = invoker.subsystem_name
1338    part_name = invoker.part_name
1339  } else if (defined(invoker.part_name)) {
1340    part_name = invoker.part_name
1341    _part_subsystem_info_file =
1342        "$root_build_dir/build_configs/parts_info/part_subsystem.json"
1343    _arguments = [
1344      "--part-name",
1345      part_name,
1346      "--part-subsystem-info-file",
1347      rebase_path(_part_subsystem_info_file, root_build_dir),
1348    ]
1349    get_subsystem_script = "//build/templates/common/get_subsystem_name.py"
1350    subsystem_name =
1351        exec_script(get_subsystem_script, _arguments, "trim string")
1352    if (is_use_check_deps && !_test_target) {
1353      skip_check_subsystem = true
1354    }
1355  } else if (defined(invoker.subsystem_name)) {
1356    subsystem_name = invoker.subsystem_name
1357    part_name = subsystem_name
1358  } else {
1359    subsystem_name = "build"
1360    part_name = "build_framework"
1361  }
1362  assert(subsystem_name != "")
1363  assert(part_name != "")
1364
1365  if (defined(is_arkui_x) && is_arkui_x && defined(invoker.external_deps)) {
1366    invoker.external_deps = []
1367  }
1368  if (is_use_check_deps && !_test_target) {
1369    _check_target = "${target_name}__check"
1370    target_path = get_label_info(":${target_name}", "label_no_toolchain")
1371    check_target(_check_target) {
1372      module_deps = []
1373      if (defined(invoker.deps)) {
1374        module_deps += invoker.deps
1375      }
1376      if (defined(invoker.public_deps)) {
1377        module_deps += invoker.public_deps
1378      }
1379      if (defined(invoker.external_deps)) {
1380        module_ex_deps = invoker.external_deps
1381      }
1382    }
1383  }
1384
1385  if (check_deps) {
1386    deps_data = {
1387    }
1388    module_label = get_label_info(":${target_name}", "label_with_toolchain")
1389    module_deps = []
1390    if (defined(invoker.deps)) {
1391      foreach(dep, invoker.deps) {
1392        module_deps += [ get_label_info(dep, "label_no_toolchain") ]
1393      }
1394    }
1395    module_ex_deps = []
1396    if (defined(invoker.external_deps) && invoker.external_deps != []) {
1397      module_ex_deps = invoker.external_deps
1398    }
1399    deps_data = {
1400      part_name = part_name
1401      module_label = module_label
1402      deps = module_deps
1403      external_deps = module_ex_deps
1404    }
1405    write_file("${root_out_dir}/deps_files/${part_name}__${target_name}.json",
1406               deps_data,
1407               "json")
1408  }
1409
1410  _security_config_target = "${target_name}__security_config"
1411  ohos_security_config(_security_config_target) {
1412    forward_variables_from(invoker, [ "auto_var_init" ])
1413  }
1414
1415  if (!allow_sanitize_debug && !build_xts &&
1416      defined(ext_sanitizer_check_list_path)) {
1417    build_name = "${target_name}"
1418    ohos_sanitizer_check("${target_name}_sanitizer_check") {
1419      forward_variables_from(invoker, [ "sanitize" ])
1420    }
1421  }
1422
1423  _sanitize_config_target = "${target_name}__sanitizer_config"
1424  ohos_sanitizer_config(_sanitize_config_target) {
1425    forward_variables_from(invoker, [ "sanitize" ])
1426  }
1427
1428  if (!_test_target) {
1429    _main_target_name = target_name
1430    _notice_target = "${_main_target_name}__notice"
1431    collect_notice(_notice_target) {
1432      forward_variables_from(invoker,
1433                             [
1434                               "testonly",
1435                               "license_as_sources",
1436                               "license_file",
1437                             ])
1438
1439      module_type = "source_set"
1440      module_name = _main_target_name
1441      module_source_dir = get_label_info(":${_main_target_name}", "dir")
1442    }
1443  }
1444
1445  source_set(target_name) {
1446    forward_variables_from(invoker,
1447                           "*",
1448                           [
1449                             "configs",
1450                             "remove_configs",
1451                             "no_default_deps",
1452                             "license_file",
1453                             "license_as_sources",
1454                             "use_exceptions",
1455                             "use_rtti",
1456                             "subsystem_name",
1457
1458                             # Sanitizer variables
1459                             "sanitize",
1460                             "stack_protector_ret",
1461                             "branch_protector_ret",
1462                           ])
1463    if (defined(invoker.configs)) {
1464      configs += invoker.configs
1465    }
1466    if (defined(invoker.remove_configs)) {
1467      configs -= invoker.remove_configs
1468    }
1469
1470    configs += [ ":$_sanitize_config_target" ]
1471    configs += [ ":$_security_config_target" ]
1472
1473    if (defined(invoker.use_exceptions) && invoker.use_exceptions) {
1474      configs += [ "//build/config/compiler:exceptions" ]
1475      configs -= [ "//build/config/compiler:no_exceptions" ]
1476    }
1477
1478    if (defined(invoker.use_rtti) && invoker.use_rtti) {
1479      configs += [ "//build/config/compiler:rtti" ]
1480      configs -= [ "//build/config/compiler:no_rtti" ]
1481    }
1482
1483    if (!defined(cflags)) {
1484      cflags = []
1485    }
1486
1487    # Enable branch protection.
1488    if (defined(invoker.branch_protector_ret)) {
1489      if (invoker.branch_protector_ret == "pac_ret") {
1490        # We need to remove stack_protector_ret_strong_config because it's conflict with pac-ret.
1491        foreach(config, configs) {
1492          if (config ==
1493              "//build/config/security:stack_protector_ret_strong_config") {
1494            configs -=
1495                [ "//build/config/security:stack_protector_ret_strong_config" ]
1496          }
1497        }
1498        if (support_branch_protector_pac_ret) {
1499          cflags += [ "-mbranch-protection=pac-ret+b-key" ]
1500        } else {
1501          configs +=
1502              [ "//build/config/security:stack_protector_ret_all_config" ]
1503        }
1504      }
1505
1506      if (support_stack_protector_ret &&
1507          invoker.branch_protector_ret == "stack_protector_ret_all") {
1508        configs -=
1509            [ "//build/config/security:stack_protector_ret_strong_config" ]
1510        configs += [ "//build/config/security:stack_protector_ret_all_config" ]
1511      }
1512
1513      # Nothing to do, supported by default.
1514      if (support_stack_protector_ret &&
1515          invoker.branch_protector_ret == "stack_protector_ret_strong") {
1516      }
1517    } else {
1518      if (support_stack_protector_ret) {
1519        if (defined(invoker.stack_protector_ret)) {
1520          configs -=
1521              [ "//build/config/security:stack_protector_ret_strong_config" ]
1522          if (invoker.stack_protector_ret) {
1523            configs +=
1524                [ "//build/config/security:stack_protector_ret_all_config" ]
1525          } else {
1526            configs += [ "//build/config/security:stack_protector_config" ]
1527          }
1528        }
1529      }
1530    }
1531
1532    if (defined(invoker.no_default_deps)) {
1533      no_default_deps = invoker.no_default_deps
1534    }
1535
1536    if (!defined(deps)) {
1537      deps = []
1538    }
1539    if (is_use_check_deps && !_test_target) {
1540      deps += [ ":$_check_target" ]
1541    }
1542    if (!_test_target) {
1543      deps += [ ":$_notice_target" ]
1544    }
1545
1546    if (!defined(libs)) {
1547      libs = []
1548    }
1549    if (!defined(include_dirs)) {
1550      include_dirs = []
1551    }
1552
1553    if (defined(is_debug) && !is_debug && enable_debug_components != "") {
1554      foreach(component_name, debug_components) {
1555        if (part_name == component_name) {
1556          configs -= default_opt_configs
1557          configs += debug_level_configs
1558        }
1559      }
1560    }
1561
1562    deps_info = []
1563    foreach(dep, deps) {
1564      info = {
1565      }
1566      info = {
1567        target_out_dir =
1568            rebase_path(get_label_info(dep, "target_out_dir"), root_build_dir)
1569        target_name = get_label_info(dep, "name")
1570      }
1571      deps_info += [ info ]
1572    }
1573    module_label = get_label_info(":${target_name}", "label_with_toolchain")
1574    target_deps_data = {
1575      label = module_label
1576      module_deps_info = deps_info
1577      module_libs = libs
1578      type = "source_set"
1579      toolchain = get_label_info(":${target_name}", "toolchain")
1580    }
1581    write_file("${target_out_dir}/${target_name}_deps_data.json",
1582               target_deps_data,
1583               "json")
1584  }
1585}
1586