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