• 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/python.gni")
15import("//build/config/sanitizers/sanitizers.gni")
16import("//build/ohos_var.gni")
17
18# Gen module info to file
19# private template
20#
21template("generate_module_info") {
22  assert(defined(invoker.module_name),
23         "module_label must be defined for ${target_name}.")
24  assert(defined(invoker.module_type),
25         "module_type must be defined for ${target_name}.")
26
27  forward_variables_from(invoker,
28                         [
29                           "testonly",
30                           "visibility",
31                         ])
32  forward_variables_from(invoker,
33                         [
34                           "module_label",
35                           "module_name",
36                           "module_source_dir",
37                           "module_install_images",
38                           "module_type",
39                           "module_install_name",
40                           "module_install_dir",
41                           "relative_install_dir",
42                           "module_output_extension",
43                           "module_source",
44                           "notice",
45                           "shlib_type",
46                           "innerapi_tags",
47                           "version_script",
48                           "part_name",
49                           "subsystem_name",
50                         ])
51
52  if (!defined(module_label)) {
53    if (module_type == "java_library" || module_type == "none" ||
54        module_type == "app" || module_type == "dex") {
55      module_label = get_label_info(":$module_name", "label_no_toolchain")
56    } else {
57      module_label = get_label_info(":$module_name", "label_with_toolchain")
58    }
59  }
60  module_deps = [ get_label_info(module_label, "label_no_toolchain") ]
61
62  gen_script = "//build/templates/metadata/gen_module_info.py"
63
64  if (!defined(module_source_dir)) {
65    module_source_dir = "$root_out_dir"
66  }
67  if (!defined(module_install_name)) {
68    module_install_name = module_name
69  }
70  if (!defined(module_output_extension)) {
71    module_output_extension = ""
72  }
73
74  output_file = "${target_out_dir}/${module_name}_module_info.json"
75
76  # reset module_type when module_type is lib
77  if (module_type == "lib") {
78    if (target_cpu == "arm64" || target_cpu == "x86_64") {
79      module_type = "lib64"
80    } else if (target_cpu == "arm" || target_cpu == "x86") {
81      module_type = "lib"
82    } else {
83      assert(false, "Error: unsupported target cpu name.")
84    }
85  }
86
87  if (!is_standard_system && is_asan &&
88      ("${module_type}" == "lib" || "${module_type}" == "lib64" ||
89       "${module_type}" == "bin")) {
90    system_base_dir = "${system_base_dir}/asan"
91  }
92
93  action(target_name) {
94    args = [
95      "--system-base-dir",
96      system_base_dir,
97      "--ramdisk-base-dir",
98      ramdisk_base_dir,
99      "--vendor-base-dir",
100      vendor_base_dir,
101      "--updater-base-dir",
102      updater_base_dir,
103      "--sys_prod-base-dir",
104      sys_prod_base_dir,
105      "--eng_system-base-dir",
106      eng_system_base_dir,
107      "--eng_chipset-base-dir",
108      eng_chipset_base_dir,
109      "--updater_vendor-base-dir",
110      updater_vendor_base_dir,
111      "--chip_prod-base-dir",
112      chip_prod_base_dir,
113      "--type",
114      module_type,
115      "--target-label",
116      module_label,
117      "--source-dir",
118      rebase_path(module_source_dir, "$root_build_dir"),
119      "--label-name",
120      module_name,
121      "--output-file",
122      rebase_path(output_file, "$root_build_dir"),
123    ]
124
125    if (module_install_name != "") {
126      args += [
127        "--install-name",
128        module_install_name,
129      ]
130    }
131
132    if (defined(invoker.module_alt_output_extension)) {
133      args += [
134        "--alternative-suffix",
135        invoker.module_alt_output_extension,
136      ]
137    }
138
139    if (defined(invoker.install_enable) && !invoker.install_enable) {
140      args += [ "--install-enable" ]
141    }
142    if (defined(invoker.collect) && invoker.collect) {
143      args += [ "--collect" ]
144    }
145
146    if (defined(module_install_images)) {
147      if (defined(module_install_dir) && module_install_dir != "") {
148        args += [
149          "--module-install-dir",
150          module_install_dir,
151        ]
152      }
153      if (defined(relative_install_dir) && relative_install_dir != "") {
154        args += [
155          "--relative-install-dir",
156          relative_install_dir,
157        ]
158      }
159      args += [ "--install-images" ]
160      args += module_install_images
161    }
162
163    # if prebuilt, add prebuilt=True
164    if (defined(invoker.prebuilt) && invoker.prebuilt) {
165      args += [
166        "--prebuilt",
167        "--module-source",
168        module_source,
169      ]
170    }
171
172    if (module_output_extension != "") {
173      args += [
174        "--suffix",
175        module_output_extension,
176      ]
177    }
178
179    if (defined(invoker.symlink_target_name)) {
180      args += [ "--symlink-target" ]
181      args += invoker.symlink_target_name
182    }
183
184    if (defined(invoker.output_prefix_override) &&
185        invoker.output_prefix_override) {
186      args += [ "--prefix-override" ]
187    }
188    if (defined(notice)) {
189      args += [
190        "--notice",
191        rebase_path(notice, root_build_dir),
192      ]
193    }
194
195    if (defined(part_name)) {
196      args += [
197        "--part-name",
198        part_name,
199      ]
200    }
201    if (defined(subsystem_name)) {
202      args += [
203        "--subsystem-name",
204        subsystem_name,
205      ]
206    }
207    if (defined(shlib_type)) {
208      args += [
209        "--shlib-type",
210        shlib_type,
211      ]
212    }
213    if (defined(innerapi_tags)) {
214      args += [ "--innerapi-tags" ]
215      args += innerapi_tags
216    }
217    if (defined(version_script)) {
218      args += [
219        "--version_script",
220        version_script,
221      ]
222    }
223    script = gen_script
224    outputs = [ output_file ]
225  }
226
227  generated_file("${target_name}_install_info") {
228    outputs = [ "${target_out_dir}/${module_name}_install_info.json" ]
229    data_keys = [ "install_modules" ]
230    output_conversion = "json"
231    deps = module_deps
232  }
233}
234
235template("write_meta_data") {
236  assert(defined(invoker.meta_data), "meta_data must be defined")
237  assert(defined(invoker.type), "type must be defined")
238  forward_variables_from(invoker, [ "testonly" ])
239
240  action_with_pydeps(target_name) {
241    forward_variables_from(invoker,
242                           [
243                             "deps",
244                             "meta_data",
245                             "type",
246                             "resources",
247                             "hap_path",
248                             "app_profile",
249                             "hap_profile",
250                             "package_name",
251                             "raw_assets",
252                             "js_assets",
253                             "ets_assets",
254                             "js2abc",
255                             "unresolved_assets",
256                           ])
257    if (type != "js_assets" && type != "ets_assets" &&
258        type != "unresolved_assets" && type != "assets" &&
259        type != "resources" && type != "hap" && type != "app_profile") {
260      assert(
261          false,
262          "type must be one of [js_assets, ets_assets, unresolved_assets, assets, resources, hap, app_profile]")
263    }
264    if (type != "hap") {
265      _parent_invoker = invoker.invoker
266      _caller_target_name = get_label_info(":${_parent_invoker.target_name}",
267                                           "label_no_toolchain")
268      sources = [ _caller_target_name ]
269      sources = filter_exclude(sources, app_target_allowlist)
270      if (sources != []) {
271        if (type == "js_assets" || type == "ets_assets" ||
272            type == "unresolved_assets" || type == "assets") {
273          assert(
274              false,
275              "Illegal target name: \"${_caller_target_name}\", target name of ohos_js_assets or ohos_assets must endswith assets or asset ")
276        } else if (type == "resources") {
277          assert(
278              false,
279              "Illegal target name: \"${_caller_target_name}\", target name of ohos_resources must endswith res or resources or resource")
280        }
281      }
282    }
283
284    script = "//build/templates/metadata/write_meta_data.py"
285    outputs = [ meta_data ]
286    depfile = "$target_gen_dir/$target_name.d"
287
288    args = [
289      "--output",
290      rebase_path(meta_data, root_build_dir),
291      "--type",
292      type,
293      "--depfile",
294      rebase_path(depfile, root_build_dir),
295    ]
296
297    if (!defined(deps)) {
298      deps = []
299    }
300
301    _possible_deps = []
302    if (defined(invoker.possible_deps)) {
303      _possible_deps = invoker.possible_deps
304    }
305
306    _deps_metadata = []
307    inputs = []
308    foreach(d, _possible_deps) {
309      sources_raw = []
310      _target_label = get_label_info(d, "label_no_toolchain")
311      sources_raw += [ _target_label ]
312      sources = filter_exclude(sources_raw, app_target_allowlist)
313      if (sources == []) {
314        _deps_metadata += [ get_label_info(d, "target_gen_dir") + "/" +
315                            get_label_info(d, "name") + ".metadata" ]
316        deps += [ "${_target_label}__metadata" ]
317      }
318    }
319
320    if (_deps_metadata != []) {
321      args += [ "--deps-metadata" ]
322      foreach(d, _deps_metadata) {
323        args += [ rebase_path(d, root_build_dir) ]
324      }
325      inputs += _deps_metadata
326    }
327
328    if (defined(resources)) {
329      args += [ "--resources" ]
330      foreach(res, resources) {
331        args += [ rebase_path(res, root_build_dir) ]
332      }
333      if (defined(package_name)) {
334        args += [
335          "--package-name",
336          package_name,
337        ]
338      }
339    }
340
341    if (defined(app_profile)) {
342      args += [
343        "--app-profile",
344        rebase_path(app_profile, root_build_dir),
345      ]
346    }
347
348    if (defined(hap_profile)) {
349      args += [
350        "--hap-profile",
351        rebase_path(hap_profile, root_build_dir),
352      ]
353    }
354
355    if (defined(raw_assets)) {
356      args += [ "--raw-assets" ]
357      foreach(asset, raw_assets) {
358        args += [ rebase_path(asset, root_build_dir) ]
359      }
360    }
361
362    if (defined(js_assets)) {
363      args += [ "--js-assets" ]
364      foreach(asset, js_assets) {
365        args += [ rebase_path(asset, root_build_dir) ]
366      }
367    }
368
369    if (defined(ets_assets)) {
370      args += [ "--ets-assets" ]
371      foreach(asset, ets_assets) {
372        args += [ rebase_path(asset, root_build_dir) ]
373      }
374    }
375
376    if (defined(unresolved_assets)) {
377      args += [ "--unresolved-assets" ]
378      foreach(asset, unresolved_assets) {
379        args += [ rebase_path(asset, root_build_dir) ]
380      }
381    }
382
383    if (defined(js2abc) && js2abc) {
384      args += [ "--js2abc" ]
385    }
386
387    if (defined(hap_path)) {
388      args += [
389        "--hap-path",
390        rebase_path(hap_path, root_build_dir),
391      ]
392    }
393  }
394}
395