• 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/ohos/notice/notice.gni")
15import("//build/templates/metadata/module_info.gni")
16
17template("ohos_copy") {
18  assert(defined(invoker.sources),
19         "sources must be defined for ${target_name}.")
20  assert(defined(invoker.outputs),
21         "outputs must be defined for ${target_name}.")
22
23  _is_test_target = defined(invoker.testonly) && invoker.testonly
24  _is_prebuilt = defined(invoker.prebuilt) && invoker.prebuilt
25  assert(_is_prebuilt != "")  # Mark as used
26
27  # module_info generation is bypassed for prebuilt static library
28  _bypass_module_info_generation =
29      defined(invoker.bypass_module_info_generation) &&
30      invoker.bypass_module_info_generation
31  _main_target_name = target_name
32  _target_label =
33      get_label_info(":${_main_target_name}", "label_with_toolchain")
34  assert(_target_label != "")  # Mark as used
35
36  if (defined(invoker.subsystem_name) && defined(invoker.part_name)) {
37    _subsystem_name = invoker.subsystem_name
38    _part_name = invoker.part_name
39  } else if (defined(invoker.part_name)) {
40    _part_name = invoker.part_name
41    _part_subsystem_info_file =
42        "$root_build_dir/build_configs/parts_info/part_subsystem.json"
43    _arguments = [
44      "--part-name",
45      _part_name,
46      "--part-subsystem-info-file",
47      rebase_path(_part_subsystem_info_file, root_build_dir),
48    ]
49    get_subsystem_script = "//build/templates/common/get_subsystem_name.py"
50    _subsystem_name =
51        exec_script(get_subsystem_script, _arguments, "trim string")
52  } else if (defined(invoker.subsystem_name)) {
53    _subsystem_name = invoker.subsystem_name
54    _part_name = _subsystem_name
55  } else {
56    _subsystem_name = "common"
57    _part_name = _subsystem_name
58  }
59  assert(_subsystem_name != "")  # Mark as used
60  assert(_part_name != "")  # Mark as used
61
62  _deps = []
63  if (defined(invoker.deps)) {
64    _deps += invoker.deps
65  }
66
67  if (!_is_test_target) {
68    _notice_target = "${_main_target_name}__notice"
69
70    # Prebuilt target has some lexing error character
71    _notice_target = string_replace(_notice_target, "@", "_")
72    _notice_target = string_replace(_notice_target, "+", "_")
73    collect_notice(_notice_target) {
74      forward_variables_from(invoker,
75                             [
76                               "testonly",
77                               "license_as_sources",
78                               "license_file",
79                             ])
80      module_name = _main_target_name
81      module_source_dir = get_label_info(":${_main_target_name}", "dir")
82    }
83    _deps += [ ":$_notice_target" ]
84  }
85
86  copy(target_name) {
87    forward_variables_from(invoker,
88                           [
89                             "testonly",
90                             "visibility",
91                             "public_configs",
92                             "sources",
93                             "outputs",
94                           ])
95    deps = _deps
96
97    if (!_bypass_module_info_generation) {
98      _install_module_info = {
99        module_def = _target_label
100        module_info_file =
101            rebase_path(get_label_info(_target_label, "target_out_dir"),
102                        root_build_dir) +
103            "/${_main_target_name}_module_info.json"
104        subsystem_name = _subsystem_name
105        part_name = _part_name
106        toolchain = current_toolchain
107        toolchain_out_dir = rebase_path(root_out_dir, root_build_dir)
108      }
109
110      metadata = {
111        install_modules = [ _install_module_info ]
112      }
113    }
114  }
115
116  if (!_bypass_module_info_generation) {
117    generate_module_info("${_main_target_name}_info") {
118      forward_variables_from(invoker,
119                             [
120                               "module_install_dir",
121                               "relative_install_dir",
122                               "module_source_dir",
123                               "module_install_name",
124                               "module_type",
125                               "install_enable",
126                             ])
127      module_name = _main_target_name
128      if (!defined(module_type)) {
129        module_type = "unknown"
130      }
131      if (!defined(module_source_dir)) {
132        module_source_dir = "${target_out_dir}"
133      }
134
135      if (_is_prebuilt) {
136        _outputs = invoker.outputs
137        module_source = string_replace(_outputs[0], "${target_out_dir}/", "", 1)
138      }
139      prebuilt = _is_prebuilt
140
141      if (!defined(install_enable)) {
142        install_enable = false
143      }
144
145      module_install_images = [ "system" ]
146      if (defined(invoker.install_images)) {
147        module_install_images = []
148        module_install_images += invoker.install_images
149      }
150
151      if (defined(invoker.symlink_target_name)) {
152        symlink_target_name = invoker.symlink_target_name
153      }
154
155      notice = "$target_out_dir/$_main_target_name.notice.txt"
156    }
157  }
158}
159