• 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/ohos_var.gni")
16import("//build/templates/metadata/module_info.gni")
17
18if (is_ohos) {
19  import("//build/config/ohos/abi.gni")
20}
21
22template("merge_profile") {
23  forward_variables_from(invoker, [ "testonly" ])
24  assert(defined(invoker.hap_profile),
25         "hap_profile must be defined for compile_resources")
26  action(target_name) {
27    forward_variables_from(invoker,
28                           [
29                             "meta_data",
30                             "hap_profile",
31                             "generated_profile",
32                             "deps",
33                           ])
34    script = "//build/scripts/merge_profile.py"
35    depfile = "$target_gen_dir/$target_name.d"
36
37    _rebased_metadata = rebase_path(meta_data, root_build_dir)
38    inputs = [
39      meta_data,
40      restool,
41      hap_profile,
42    ]
43    args = [
44      "--resources-dir=@FileArg($_rebased_metadata:root:resources)",
45      "--depfile",
46      rebase_path(depfile, root_build_dir),
47      "--app-profile=@FileArg($_rebased_metadata:root:app_profile)",
48      "--hap-profile",
49      rebase_path(hap_profile, root_build_dir),
50      "--generated-profile",
51      rebase_path(generated_profile, root_build_dir),
52      "--release-type",
53      release_type,
54    ]
55    outputs = [ generated_profile ]
56  }
57}
58
59template("compile_resources") {
60  forward_variables_from(invoker, [ "testonly" ])
61  assert(defined(invoker.hap_profile),
62         "hap_profile must be defined for compile_resources")
63  assert(
64      defined(invoker.packaged_resources) ||
65          defined(invoker.generated_header_dir),
66      "hap_profile or generated_header_dir must be defined for compile_resources")
67  _generate_resource = defined(invoker.packaged_resources)
68  if (_generate_resource) {
69    _packaged_resources = invoker.packaged_resources
70  }
71  _generate_header = defined(invoker.generated_header_dir)
72  if (_generate_header) {
73    _generated_header_file = invoker.generated_header_dir + "/ResourceTable.h"
74  }
75  action_with_pydeps(target_name) {
76    forward_variables_from(invoker,
77                           [
78                             "meta_data",
79                             "hap_profile",
80                             "deps",
81                           ])
82    script = "//build/scripts/compile_resources.py"
83    depfile = "$target_gen_dir/$target_name.d"
84    if (defined(deps)) {
85      deps += [
86        "//developtools/global_resource_tool:restool($host_toolchain)",
87        "//developtools/global_resource_tool:restool_id_defined($host_toolchain)",
88      ]
89    } else {
90      deps = [
91        "//developtools/global_resource_tool:restool($host_toolchain)",
92        "//developtools/global_resource_tool:restool_id_defined($host_toolchain)",
93      ]
94    }
95    restool_path =
96        get_label_info(
97            "//developtools/global_resource_tool:restool($host_toolchain)",
98            "root_out_dir") + "/developtools/global_resource_tool/restool"
99    _rebased_metadata = rebase_path(meta_data, root_build_dir)
100    inputs = [
101      meta_data,
102      restool,
103      hap_profile,
104    ]
105    args = [
106      "--resources-dir=@FileArg($_rebased_metadata:root:resources)",
107      "--depfile",
108      rebase_path(depfile, root_build_dir),
109      "--restool-path",
110      rebase_path(restool_path, root_build_dir),
111      "--hap-profile=@FileArg($_rebased_metadata:root:hap_profile)",
112      "--app-profile=@FileArg($_rebased_metadata:root:app_profile)",
113    ]
114    outputs = []
115    if (_generate_resource) {
116      outputs += [ _packaged_resources ]
117      args += [
118        "--output-resources-zipfile",
119        rebase_path(_packaged_resources, root_build_dir),
120      ]
121    }
122    if (_generate_header) {
123      outputs += [ _generated_header_file ]
124      args += [
125        "--output-header-file",
126        rebase_path(_generated_header_file, root_build_dir),
127      ]
128    }
129  }
130}
131
132template("package_app") {
133  forward_variables_from(invoker, [ "testonly" ])
134  assert(defined(invoker.hap_profile),
135         "hap_profile must be defined for $target_name")
136  assert(defined(invoker.hap_path), "hap_path must be defined for $target_name")
137  action_with_pydeps(target_name) {
138    forward_variables_from(invoker,
139                           [
140                             "deps",
141                             "shared_libraries",
142                             "hap_profile",
143                             "hap_path",
144                             "packaged_resources",
145                             "packaged_js_assets",
146                             "meta_data",
147                             "private_key_path",
148                             "signature_algorithm",
149                             "certificate_profile",
150                             "keystore_path",
151                             "keystore_password",
152                             "key_alias",
153                             "certificate_file",
154                             "install_module_info",
155                             "enable_ark",
156                             "build_mode",
157                           ])
158    script = "//build/scripts/hapbuilder.py"
159    depfile = "$target_gen_dir/$target_name.d"
160    _rebased_metadata = rebase_path(meta_data, root_build_dir)
161    outputs = [ hap_path ]
162    args = [
163      "--depfile",
164      rebase_path(depfile, root_build_dir),
165      "--hap-profile=@FileArg($_rebased_metadata:root:hap_profile)",
166      "--hapsigner",
167      rebase_path(hapsigner, root_build_dir),
168      "--hap-packing-tool",
169      rebase_path(hap_packing_tool, root_build_dir),
170      "--hap-path",
171      rebase_path(hap_path, root_build_dir),
172      "--packaged-resources",
173      rebase_path(packaged_resources, root_build_dir),
174      "--packaged-js-assets",
175      rebase_path(packaged_js_assets, root_build_dir),
176      "--assets=@FileArg($_rebased_metadata:root:assets)",
177      "--app-profile=@FileArg($_rebased_metadata:root:app_profile)",
178      "--build-mode",
179      build_mode,
180    ]
181
182    inputs = [
183      hap_profile,
184      hapsigner,
185      hap_packing_tool,
186      packaged_js_assets,
187      packaged_resources,
188      meta_data,
189    ]
190
191    _private_key_path = default_hap_private_key_path
192    if (defined(private_key_path)) {
193      _private_key_path = private_key_path
194    }
195    _signature_algorithm = default_signature_algorithm
196    if (defined(signature_algorithm)) {
197      _signature_algorithm = signature_algorithm
198    }
199    _key_alias = default_key_alias
200    if (defined(key_alias)) {
201      _key_alias = key_alias
202    }
203    _keystore_path = default_keystore_path
204    if (defined(keystore_path)) {
205      _keystore_path = keystore_path
206    }
207    _keystore_password = default_keystore_password
208    if (defined(keystore_password)) {
209      _keystore_password = keystore_password
210    }
211    _certificate_file = default_hap_certificate_file
212    if (defined(certificate_file)) {
213      _certificate_file = certificate_file
214    }
215
216    inputs += [
217      certificate_profile,
218      _keystore_path,
219      _certificate_file,
220    ]
221
222    args += [
223      "--private-key-path",
224      _private_key_path,
225      "--sign-algo",
226      _signature_algorithm,
227      "--certificate-profile",
228      rebase_path(certificate_profile, root_build_dir),
229      "--keyalias",
230      _key_alias,
231      "--keystore-path",
232      rebase_path(_keystore_path, root_build_dir),
233      "--keystorepasswd",
234      _keystore_password,
235      "--certificate-file",
236      rebase_path(_certificate_file, root_build_dir),
237    ]
238
239    if (defined(shared_libraries)) {
240      foreach(lib, shared_libraries) {
241        _module_info = get_label_info(lib, "target_out_dir") + "/" +
242                       get_label_info(lib, "name") + "_module_info.json"
243        _rebased_module_info = rebase_path(_module_info, root_build_dir)
244        args += [ "--dso=@FileArg($_rebased_module_info:source)" ]
245      }
246      if (is_ohos) {
247        args += [
248          "--ohos-app-abi",
249          ohos_app_abi,
250        ]
251      }
252    }
253
254    if (defined(install_module_info)) {
255      metadata = {
256        install_modules = [ install_module_info ]
257      }
258    }
259    if (defined(enable_ark) && enable_ark) {
260      _ark_dpes = [
261        "//arkcompiler/ets_frontend/ts2panda:ts2abc_js_file($host_toolchain)",
262        "//arkcompiler/ets_frontend/ts2panda:ark_ts2abc_build($host_toolchain)",
263      ]
264      if (defined(deps)) {
265        deps += _ark_dpes
266      } else {
267        deps = _ark_dpes
268      }
269      _js2abc_js = get_label_info(
270                       "//arkcompiler/ets_frontend/ts2panda:ts2abc_js_file($host_toolchain)",
271                       "target_out_dir") + "/ts2abc.js"
272      args += [
273        "--nodejs-path",
274        rebase_path(nodejs, root_build_dir),
275        "--js2abc-js",
276        rebase_path(_js2abc_js, root_build_dir),
277        "--enable-ark",
278      ]
279      inputs += [
280        nodejs,
281        _js2abc_js,
282      ]
283    }
284  }
285}
286
287template("compile_js_assets") {
288  forward_variables_from(invoker, [ "testonly" ])
289  assert(defined(invoker.meta_data) && defined(invoker.packaged_js_assets),
290         "meta_data and packaged_js_assets must be for compile_js_assets")
291
292  _packaged_js_assets = invoker.packaged_js_assets
293  action_with_pydeps(target_name) {
294    forward_variables_from(invoker,
295                           [
296                             "deps",
297                             "meta_data",
298                             "hap_profile",
299                             "build_mode",
300                             "js2abc",
301                             "ets2abc",
302                             "main_target_name",
303                           ])
304    script = "//build/scripts/build_js_assets.py"
305    depfile = "$target_gen_dir/$target_name.d"
306    outputs = [ _packaged_js_assets ]
307
308    _rebased_metadata = rebase_path(meta_data, root_build_dir)
309
310    if (!defined(deps)) {
311      deps = []
312    }
313    deps += [
314      "//arkcompiler/ets_frontend/es2panda:build_es2abc_for_hap($host_toolchain)",
315      "//arkcompiler/ets_frontend/ts2panda:ark_ts2abc_build($host_toolchain)",
316      "//developtools/ace_ets2bundle:ets_loader_node_modules",
317      "//developtools/ace_js2bundle:ace_loader_node_modules",
318    ]
319    _ace_loader_home =
320        get_label_info("//developtools/ace_js2bundle:ace_loader_node_modules",
321                       "target_out_dir") + "/ace_loader_ark"
322    _webpack_config_js = "${_ace_loader_home}/webpack.rich.config.js"
323    _ets_loader_home =
324        get_label_info("//developtools/ace_ets2bundle:ets_loader_node_modules",
325                       "target_out_dir") + "/ets_loader_ark"
326    _webpack_config_ets = "${_ets_loader_home}/webpack.config.js"
327    _webpack_js = "${_ace_loader_home}/node_modules/webpack/bin/webpack.js"
328    _manifest_file_path = "${target_gen_dir}/manifest_file"
329
330    inputs = [
331      meta_data,
332      nodejs,
333    ]
334
335    args = [
336      "--js-assets-dir=@FileArg($_rebased_metadata:root:js_assets)",
337      "--ets-assets-dir=@FileArg($_rebased_metadata:root:ets_assets)",
338      "--js-forms-dir=@FileArg($_rebased_metadata:root:js_forms)",
339      "--testrunner-dir=@FileArg($_rebased_metadata:root:testrunner)",
340      "--output",
341      rebase_path(_packaged_js_assets, root_build_dir),
342      "--depfile",
343      rebase_path(depfile, root_build_dir),
344      "--nodejs-path",
345      rebase_path(nodejs, root_build_dir),
346      "--webpack-js",
347      rebase_path(_webpack_js, root_build_dir),
348      "--webpack-config-js",
349      rebase_path(_webpack_config_js, root_build_dir),
350      "--webpack-config-ets",
351      rebase_path(_webpack_config_ets, root_build_dir),
352      "--build-mode",
353      build_mode,
354      "--ace-loader-home",
355      rebase_path(_ace_loader_home, root_build_dir),
356      "--ets-loader-home",
357      rebase_path(_ets_loader_home, root_build_dir),
358      "--hap-profile=@FileArg($_rebased_metadata:root:hap_profile)",
359      "--app-profile=@FileArg($_rebased_metadata:root:app_profile)",
360      "--manifest-file-path",
361      rebase_path(_manifest_file_path, root_build_dir),
362    ]
363    if (defined(testonly) && testonly == true) {
364      _js_sources_file = target_gen_dir + "/$main_target_name.sources"
365      args += [
366        "--js-sources-file",
367        rebase_path(_js_sources_file, root_build_dir),
368      ]
369      outputs += [ _js_sources_file ]
370    }
371
372    if (js2abc || ets2abc) {
373      _ts2abc_dir = get_label_info(
374              "//arkcompiler/ets_frontend/ts2panda:ark_ts2abc_build($host_toolchain)",
375              "target_out_dir")
376      _es2abc_dir = get_label_info(
377              "//arkcompiler/ets_frontend/es2panda:es2panda_build($host_toolchain)",
378              "target_out_dir")
379      if (ets2abc) {
380        args += [ "--ets2abc" ]
381      } else if (js2abc) {
382        args += [ "--js2abc" ]
383      }
384      args += [
385        "--ark-ts2abc-dir",
386        rebase_path(_ts2abc_dir, root_build_dir),
387        "--ark-es2abc-dir",
388        rebase_path(_es2abc_dir, root_build_dir),
389      ]
390    }
391
392    if (defined(hap_profile)) {
393      inputs += [ hap_profile ]
394    }
395  }
396}
397