xref: /developtools/ace_ets2bundle/BUILD.gn (revision 07ac75b1)
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.gni")
15import("//build/ohos/ace/ace.gni")
16import("//build/ohos_var.gni")
17import("//foundation/arkui/ace_engine/ace_config.gni")
18if (sdk_build_public) {
19  import("//out/sdk-public/public_interface/sdk-js/interface_config.gni")
20} else {
21  import("//interface/sdk-js/interface_config.gni")
22}
23
24ets_loader_lib_dir =
25    get_label_info(":build_ets_loader_library", "target_out_dir") + "/lib"
26ets_loader_declarations_dir = get_label_info(":build_ets_loader_library",
27                                             "target_out_dir") + "/declarations"
28ets_loader_component_config_file =
29    get_label_info(":build_ets_loader_library", "target_out_dir") +
30    "/component_config.json"
31ets_loader_form_config_file =
32    get_label_info(":build_ets_loader_library", "target_out_dir") +
33    "/form_config.json"
34ets_loader_build_config_file =
35    get_label_info(":build_ets_loader_library", "target_out_dir") +
36    "/build_config.json"
37ets_sysResource = get_label_info(":build_ets_sysResource", "target_out_dir") +
38                  "/sysResource.js"
39ets_loader_kit_configs_dir = get_label_info(":build_ets_loader_library",
40                                            "target_out_dir") + "/kit_configs"
41
42action("build_ets_loader_library") {
43  deps = [
44    ":components",
45    ":form_components",
46    ":install_arkguard_tsc",
47    ":server",
48  ]
49  script = "build_ets_loader_library.py"
50  depfile = "$target_gen_dir/$target_name.d"
51  outputs = [
52    ets_loader_lib_dir,
53    ets_loader_declarations_dir,
54    ets_loader_component_config_file,
55    ets_loader_form_config_file,
56    ets_loader_kit_configs_dir,
57    ets_loader_build_config_file,
58  ]
59
60  _ets_loader_dir = "compiler"
61  if (is_standard_system) {
62    _ace_config_dir = "compiler"
63  } else {
64    _ace_config_dir = "//prebuilts/ace-toolkit/ets-loader/compiler"
65  }
66  _declarations_file_dir = "//interface/sdk-js/api/@internal/component/ets"
67  _kit_configs_file_dir = "//interface/sdk-js/kits"
68  _kit_apis_file_dir = "//interface/sdk-js/api"
69  _arkts_apis_file_dir = "//interface/sdk-js/arkts"
70  isPublic = "false"
71  if (sdk_build_public) {
72    _declarations_file_dir =
73        "//out/sdk-public/public_interface/sdk-js/api/@internal/component/ets"
74    _kit_configs_file_dir = "//out/sdk-public/public_interface/sdk-js/kits"
75    _kit_apis_file_dir = "//out/sdk-public/public_interface/sdk-js/api"
76    _arkts_apis_file_dir = "//out/sdk-public/public_interface/sdk-js/arkts"
77    isPublic = "true"
78  }
79
80  _babel_js = _ace_config_dir + "/node_modules/@babel/cli/bin/babel.js"
81  _babel_config_js = _ace_config_dir + "/babel.config.js"
82  _uglify_source_js = _ace_config_dir + "/uglify-source.js"
83  _build_declarations_file_js = _ace_config_dir + "/build_declarations_file.js"
84  _build_kit_configs_file_js = _ace_config_dir + "/build_kitConfigs_file.js"
85
86  inputs = [
87    _babel_config_js,
88    _babel_js,
89    _uglify_source_js,
90    _build_declarations_file_js,
91    _build_kit_configs_file_js,
92  ]
93
94  nodejs_path = "//prebuilts/build-tools/common/nodejs/current/bin/node"
95
96  args = [
97    "--depfile",
98    rebase_path(depfile, root_build_dir),
99    "--node",
100    rebase_path(nodejs_path, root_build_dir),
101    "--babel-js",
102    rebase_path(_babel_js, root_build_dir),
103    "--ets-loader-src-dir",
104    rebase_path(_ets_loader_dir + "/src", root_build_dir),
105    "--babel-config-js",
106    rebase_path(_babel_config_js, root_build_dir),
107    "--uglify-source-js",
108    rebase_path(_uglify_source_js, root_build_dir),
109    "--output-dir",
110    rebase_path(ets_loader_lib_dir, root_build_dir),
111    "--declarations-file-dir",
112    rebase_path(_declarations_file_dir, root_build_dir),
113    "--build-declarations-file-js",
114    rebase_path(_build_declarations_file_js, root_build_dir),
115    "--output-declarations-dir",
116    rebase_path(ets_loader_declarations_dir, root_build_dir),
117    "--output-component-config-file",
118    rebase_path(ets_loader_component_config_file, root_build_dir),
119    "--output-form-config-file",
120    rebase_path(ets_loader_form_config_file, root_build_dir),
121    "--output-build-config-file",
122    rebase_path(ets_loader_build_config_file, root_build_dir),
123    "--kit-configs-file-dir",
124    rebase_path(_kit_configs_file_dir, root_build_dir),
125    "--build-kit-configs-file-js",
126    rebase_path(_build_kit_configs_file_js, root_build_dir),
127    "--output-kit-configs-dir",
128    rebase_path(ets_loader_kit_configs_dir, root_build_dir),
129    "--kit-apis-file-dir",
130    rebase_path(_kit_apis_file_dir, root_build_dir),
131    "--arkts-apis-file-dir",
132    rebase_path(_arkts_apis_file_dir, root_build_dir),
133    "--build-public-sdk",
134    isPublic,
135  ]
136}
137
138action("build_ets_sysResource") {
139  if (is_standard_system) {
140    script = "//developtools/ace_ets2bundle/generateSysResource.py"
141  } else {
142    script = "//foundation/ace/huawei_proprietary/tools/ets-loader/generateSysResource.py"
143  }
144  outputs = [ ets_sysResource ]
145
146  _id_defined_json = "//base/global/system_resources/systemres/main/resources/base/element/id_defined.json"
147  inputs = [ _id_defined_json ]
148
149  args = [
150    "--input-json",
151    rebase_path(_id_defined_json, root_build_dir),
152    "--output-js",
153    rebase_path(ets_sysResource, root_build_dir),
154  ]
155}
156
157ets_loader_sources = [
158  "compiler/compile_plugin.js",
159  "compiler/config/obfuscateWhiteList.json5",
160  "compiler/main.js",
161  "compiler/node_modules",
162  "compiler/npm-install.js",
163  "compiler/package-lock.json",
164  "compiler/package.json",
165  "compiler/rollup.config.js",
166  "compiler/tsconfig.esm.json",
167  "compiler/tsconfig.json",
168  "compiler/webpack.config.js",
169]
170
171ohos_copy("ets_loader") {
172  deps = [
173    ":build_ets_loader_library",
174    ":install_arkguard_tsc",
175  ]
176  sources = ets_loader_sources
177  deps += [ ":build_ets_sysResource" ]
178  sources += [ ets_sysResource ]
179
180  outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
181  module_source_dir = target_out_dir + "/$target_name"
182  module_install_name = ""
183}
184
185ohos_copy("ets_loader_component_config") {
186  deps = [ ":build_ets_loader_library" ]
187  sources = [
188    ets_loader_build_config_file,
189    ets_loader_component_config_file,
190  ]
191
192  outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
193  module_source_dir = target_out_dir + "/$target_name"
194  module_install_name = ""
195}
196
197ohos_copy("ets_loader_form_config") {
198  deps = [ ":build_ets_loader_library" ]
199  sources = [ ets_loader_form_config_file ]
200
201  outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
202  module_source_dir = target_out_dir + "/$target_name"
203  module_install_name = ""
204}
205
206ohos_copy("ets_loader_library") {
207  deps = [ ":build_ets_loader_library" ]
208  sources = [ ets_loader_lib_dir ]
209  outputs = [ target_out_dir + "/$target_name" ]
210  module_source_dir = target_out_dir + "/$target_name"
211  module_install_name = ""
212}
213
214ohos_copy("ets_loader_kit_configs") {
215  deps = [ ":build_ets_loader_library" ]
216  sources = [ ets_loader_kit_configs_dir ]
217  outputs = [ target_out_dir + "/$target_name" ]
218  module_source_dir = target_out_dir + "/$target_name"
219  module_install_name = ""
220}
221
222ohos_copy("components") {
223  sources = [ "compiler/components" ]
224  outputs = [ target_out_dir + "/$target_name" ]
225  module_source_dir = target_out_dir + "/$target_name"
226  module_install_name = ""
227}
228
229ohos_copy("form_components") {
230  sources = [ "compiler/form_components" ]
231  outputs = [ target_out_dir + "/$target_name" ]
232  module_source_dir = target_out_dir + "/$target_name"
233  module_install_name = ""
234}
235
236ohos_copy("server") {
237  sources = [ "compiler/server" ]
238  outputs = [ target_out_dir + "/$target_name" ]
239  module_source_dir = target_out_dir + "/$target_name"
240  module_install_name = ""
241}
242
243ohos_copy("codegen") {
244  sources = [ "compiler/codegen" ]
245  outputs = [ target_out_dir + "/$target_name" ]
246  module_source_dir = target_out_dir + "/$target_name"
247  module_install_name = ""
248}
249
250ohos_copy("ets_loader_declaration") {
251  deps = [ ":build_ets_loader_library" ]
252  sources = [ ets_loader_declarations_dir ]
253  outputs = [ target_out_dir + "/$target_name" ]
254  module_source_dir = target_out_dir + "/$target_name"
255  module_install_name = ""
256}
257
258ohos_copy("ets_loader_ark") {
259  deps = [
260    ":build_ets_loader_library",
261    ":install_arkguard_tsc",
262  ]
263  sources = ets_loader_sources
264  deps += [ ":build_ets_sysResource" ]
265  sources += [ ets_sysResource ]
266  outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
267}
268
269ohos_copy("ets_loader_ark_lib") {
270  deps = [
271    ":build_ets_loader_library",
272    ":ets_loader_ark",
273  ]
274  sources = [ ets_loader_lib_dir ]
275  outputs = [ target_out_dir + "/ets_loader_ark/lib" ]
276}
277
278ohos_copy("ets_loader_ark_declaration") {
279  deps = [
280    ":build_ets_loader_library",
281    ":ets_loader_ark",
282  ]
283  sources = [ ets_loader_declarations_dir ]
284  outputs = [ target_out_dir + "/ets_loader_ark/declarations" ]
285}
286
287ohos_copy("ets_loader_ark_components") {
288  deps = [
289    ":build_ets_loader_library",
290    ":ets_loader_ark",
291  ]
292  sources = [ "compiler/components" ]
293  outputs = [ target_out_dir + "/ets_loader_ark/components" ]
294}
295
296ohos_copy("ets_loader_ark_form_components") {
297  deps = [
298    ":build_ets_loader_library",
299    ":ets_loader_ark",
300  ]
301  sources = [ "compiler/form_components" ]
302  outputs = [ target_out_dir + "/ets_loader_ark/form_components" ]
303}
304
305ohos_copy("ets_loader_ark_server") {
306  deps = [
307    ":build_ets_loader_library",
308    ":ets_loader_ark",
309  ]
310  sources = [ "compiler/server" ]
311  outputs = [ target_out_dir + "/ets_loader_ark/server" ]
312}
313
314ohos_copy("ets_loader_ark_codegen") {
315  deps = [
316    ":build_ets_loader_library",
317    ":ets_loader_ark",
318  ]
319  sources = [ "compiler/codegen" ]
320  outputs = [ target_out_dir + "/ets_loader_ark/codegen" ]
321}
322
323ohos_copy("ohos_declaration_ets_ark") {
324  deps = []
325  if (sdk_build_public) {
326    deps += [ "//out/sdk-public/public_interface/sdk-js:ohos_declaration_ets" ]
327  } else {
328    deps += [ "//interface/sdk-js:ohos_declaration_ets" ]
329  }
330
331  sources = [ root_out_dir + "/ohos_declaration/ohos_declaration_ets" ]
332
333  outputs = [ target_out_dir + "/../api" ]
334}
335
336ohos_copy("ets_loader_ark_hap") {
337  sources = common_api_src
338  deps = [
339    ":ets_loader_ark",
340    ":ets_loader_ark_codegen",
341    ":ets_loader_ark_components",
342    ":ets_loader_ark_declaration",
343    ":ets_loader_ark_form_components",
344    ":ets_loader_ark_lib",
345    ":ets_loader_ark_server",
346    ":ohos_declaration_ets_ark",
347  ]
348  outputs = [ target_out_dir + "/../../developtools/api/{{source_file_part}}" ]
349  module_install_name = ""
350}
351
352typescript_dir = get_label_info("//third_party/typescript:build_typescript",
353                                "target_out_dir")
354
355action("install_arkguard_tsc") {
356  deps = [
357    "//arkcompiler/ets_frontend/arkguard:build_arkguard",
358    "//third_party/typescript:build_typescript",
359  ]
360  script = "install_arkguard_tsc.py"
361  args = [
362    rebase_path("${typescript_dir}/ohos-typescript-4.9.5-r4.tgz"),
363    rebase_path(
364        "${root_out_dir}/obj/arkcompiler/ets_frontend/arkguard/arkguard-1.1.3.tgz"),
365    rebase_path("//developtools/ace_ets2bundle/compiler"),
366    current_os,
367  ]
368  outputs = [ "${target_out_dir}/${target_name}.stamp" ]
369}
370