• 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.gni")
15import("//foundation/ace/ace_engine/ace_config.gni")
16
17prebuilt_js_path =
18    get_label_info(":gen_jsf_c", "target_out_dir") + "/dist/strip.native.min.js"
19prebuilt_js_api_mock_path = get_label_info(":gen_jsf_c", "target_out_dir") +
20                            "/dist/jsMockSystemPlugin.js"
21
22action("gen_node_modules") {
23  script = "//third_party/jsframework/prebuild_env.sh"
24  args = []
25  inputs = [
26    "package.json",
27    "package-lock.json",
28  ]
29  outputs = [ "$root_out_dir/jsframework/node_modules" ]
30}
31
32action("gen_snapshot") {
33  script = "//third_party/jsframework/js_framework_build.sh"
34
35  js_framework = "//third_party/jsframework/runtime"
36  is_mac = "false"
37
38  if (is_standard_system || is_cross_platform_build) {
39    node_modules = "//prebuilts/build-tools/common/js-framework/node_modules"
40    if (use_mac) {
41      nodejs_path =
42          "//prebuilts/build-tools/common/nodejs/node-v12.18.4-darwin-x64"
43      is_mac = "true"
44    } else {
45      nodejs_path =
46          "//prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64"
47      is_mac = "false"
48    }
49  } else {
50    node_modules = "//prebuilts/ace-toolkit/js-framework/node_modules"
51    if (use_mac) {
52      nodejs_path = "//prebuilts/ace-toolkit/nodejs/node-v12.18.4-darwin-x64"
53      is_mac = "true"
54    } else {
55      nodejs_path = "//prebuilts/ace-toolkit/nodejs/node-v12.18.4-linux-x64"
56      is_mac = "false"
57    }
58  }
59
60  buildfile = "//third_party/jsframework/build.js"
61
62  package_file = "//third_party/jsframework/package.json"
63  tsconfig = "//third_party/jsframework/tsconfig.json"
64  eslint = "//third_party/jsframework/.eslintrc"
65  babel = "//third_party/jsframework/.babelrc"
66  test_file = "//third_party/jsframework/test"
67
68  args = [
69    rebase_path(buildfile, root_build_dir),
70    rebase_path(nodejs_path, root_build_dir),
71    rebase_path(js_framework, root_build_dir),
72    rebase_path(node_modules, root_build_dir),
73    rebase_path(package_file, root_build_dir),
74    rebase_path(tsconfig, root_build_dir),
75    rebase_path(eslint, root_build_dir),
76    rebase_path(test_file, root_build_dir),
77    rebase_path(target_out_dir, root_build_dir),
78    rebase_path(babel, root_build_dir),
79    is_mac,
80  ]
81
82  inputs = [
83    # app
84    "runtime/main/app/App.ts",
85    "runtime/main/app/bundle.ts",
86    "runtime/main/app/helper.ts",
87    "runtime/main/app/index.ts",
88    "runtime/main/app/map.ts",
89
90    # plugin
91    "runtime/main/extend/dpi/Dpi.ts",
92    "runtime/main/extend/dpi/index.ts",
93    "runtime/main/extend/i18n/I18n.ts",
94    "runtime/main/extend/i18n/index.ts",
95    "runtime/main/extend/mediaquery/mediaQuery.ts",
96    "runtime/main/extend/mediaquery/pluginMediaQuery.ts",
97    "runtime/main/extend/mediaquery/plugins.ts",
98
99    # manage event
100    "runtime/main/manage/event/bridge.ts",
101    "runtime/main/manage/event/callbackIntercept.ts",
102    "runtime/main/manage/event/CallbackManager.ts",
103    "runtime/main/manage/event/TaskCenter.ts",
104
105    # manage instance
106    "runtime/main/manage/instance/life.ts",
107    "runtime/main/manage/instance/misc.ts",
108    "runtime/main/manage/instance/register.ts",
109
110    # vdom
111    "runtime/main/model/compiler.ts",
112    "runtime/main/model/directive.ts",
113    "runtime/main/model/domHelper.ts",
114    "runtime/main/model/events.ts",
115    "runtime/main/model/index.ts",
116    "runtime/main/model/pageLife.ts",
117    "runtime/main/model/selector.ts",
118    "runtime/main/model/vmOptions.ts",
119
120    # page
121    "runtime/main/page/api/Differ.ts",
122    "runtime/main/page/api/index.ts",
123    "runtime/main/page/api/misc.ts",
124    "runtime/main/page/entry/bundle.ts",
125    "runtime/main/page/entry/init.ts",
126    "runtime/main/page/Image.ts",
127    "runtime/main/page/index.ts",
128    "runtime/main/page/Page.ts",
129    "runtime/main/page/register.ts",
130
131    # third reactivity
132    "runtime/main/reactivity/array.js",
133    "runtime/main/reactivity/dep.js",
134    "runtime/main/reactivity/object.js",
135    "runtime/main/reactivity/observer.js",
136    "runtime/main/reactivity/state.js",
137    "runtime/main/reactivity/watcher.js",
138
139    # third util
140    "runtime/main/util/index.js",
141    "runtime/main/util/props.js",
142    "runtime/main/util/shared.js",
143
144    # framework expose
145    "runtime/main/config.ts",
146    "runtime/main/index.ts",
147
148    # preparation of init framework
149    "runtime/preparation/index.ts",
150    "runtime/preparation/init.ts",
151    "runtime/preparation/methods.ts",
152    "runtime/preparation/service.ts",
153
154    # utils
155    "runtime/utils/index.ts",
156    "runtime/utils/utils.ts",
157
158    # vdom
159    "runtime/vdom/Comment.ts",
160    "runtime/vdom/Document.ts",
161    "runtime/vdom/DocumentElement.ts",
162    "runtime/vdom/Element.ts",
163    "runtime/vdom/index.ts",
164    "runtime/vdom/NativeElementClassFactory.ts",
165    "runtime/vdom/Node.ts",
166
167    # global
168    "runtime/lib.d.ts",
169
170    # config of compiler
171    ".babelrc",
172    ".eslintrc",
173    "build.js",
174    "tsconfig.json",
175    "tslint.json",
176  ]
177  outputs = [
178    prebuilt_js_path,
179    prebuilt_js_api_mock_path,
180  ]
181}
182
183if (!is_standard_system && !is_cross_platform_build) {
184  import("$v8_root/gni/snapshot_toolchain.gni")
185
186  v8_snapshot_bin_path = get_label_info(":v8_snapshot_bin", "target_out_dir") +
187                         "/strip.native.min.js.bin"
188  v8_snapshot_obj_path = get_label_info(":v8_snapshot_bin", "target_out_dir") +
189                         "/strip.native.min.js.o"
190
191  action("gen_snapshot_bin") {
192    visibility = [ ":*" ]  # Only targets in this file can depend on this.
193
194    deps = [ ":gen_snapshot" ]
195    deps += [ "$v8_root:mksnapshot($v8_snapshot_toolchain)" ]
196
197    script = "$v8_root/tools/run.sh"
198
199    args = [
200      rebase_path("${aosp_libs_dir}/ndk/libcxx/linux_x86") + ":" +
201          rebase_path("${aosp_libs_dir}/ndk/libcxx/linux_x86_64"),
202      rebase_path(
203          get_label_info("$v8_root:mksnapshot($v8_snapshot_toolchain)",
204                         "root_out_dir") + "/ace/ace_engine_full/mksnapshot"),
205      rebase_path(prebuilt_js_path),
206      "--startup_blob=" + rebase_path(v8_snapshot_bin_path),
207      "--turbo_instruction_scheduling",
208    ]
209
210    inputs = [ prebuilt_js_path ]
211    outputs = [ v8_snapshot_bin_path ]
212  }
213
214  ohos_prebuilt_etc("v8_snapshot_bin") {
215    deps = [ ":gen_snapshot_bin" ]
216    source = v8_snapshot_bin_path
217    part_name = "ace_engine_full"
218  }
219
220  action("gen_snapshot_obj") {
221    visibility = [ ":*" ]  # Only targets in this file can depend on this.
222
223    if (use_mingw_win) {
224      objcopy_tool = objcopy_mingw
225      script = "$flutter_root/engine/flutter/sky/tools/objcopy_pc_mac.py"
226    } else if (use_mac) {
227      objcopy_tool = objcopy_clang
228      script = "$flutter_root/engine/flutter/sky/tools/objcopy_pc_mac.py"
229    } else if (target_cpu == "x86_64") {
230      objcopy_tool = objcopy_x86_64
231      script = "$flutter_root/engine/flutter/sky/tools/objcopy.py"
232    } else {
233      objcopy_tool = objcopy_aarch64
234      script = "$flutter_root/engine/flutter/sky/tools/objcopy.py"
235    }
236
237    args = [
238      "--objcopy",
239      rebase_path(objcopy_tool),
240      "--input",
241      rebase_path(v8_snapshot_bin_path),
242      "--output",
243      rebase_path(v8_snapshot_obj_path),
244      "--arch",
245      current_cpu,
246    ]
247
248    deps = [ ":gen_snapshot_bin" ]
249
250    inputs = [ v8_snapshot_bin_path ]
251    outputs = [ v8_snapshot_obj_path ]
252  }
253
254  source_set("v8_snapshot_obj") {
255    sources = [ v8_snapshot_obj_path ]
256    deps = [ ":gen_snapshot_obj" ]
257  }
258}
259
260jsfc_path = get_label_info(":jsf", "target_out_dir") + "/src/jsf.c"
261
262action("gen_jsf_c") {
263  visibility = [ ":*" ]  # Only targets in this file can depend on this.
264
265  deps = [ ":gen_snapshot" ]
266  deps += [ "//third_party/quickjs:qjsc(${host_toolchain})" ]
267
268  script = get_label_info("//third_party/quickjs:qjsc(${host_toolchain})",
269                          "root_out_dir") + "/ace/ace_engine_full/qjsc"
270
271  args = [
272    "-o",
273    rebase_path(jsfc_path),
274    "-N",
275    "js_framework",
276    "-c",
277    rebase_path(prebuilt_js_path, "."),
278  ]
279
280  inputs = [ prebuilt_js_path ]
281  outputs = [ jsfc_path ]
282}
283
284ohos_static_library("jsf") {
285  deps = [ ":gen_jsf_c" ]
286  sources = [ jsfc_path ]
287}
288
289if (!is_cross_platform_build) {
290  import("//ark/ts2abc/ts2panda/ts2abc_config.gni")
291  ark_abc_path =
292      get_label_info(":ark_build", "target_out_dir") + "/strip.native.min.abc"
293
294  ts2abc_gen_abc("ark_jsf") {
295    extra_visibility = [ ":*" ]  # Only targets in this file can depend on this
296    extra_dependencies = [ ":gen_snapshot" ]
297
298    src_js = rebase_path(prebuilt_js_path)
299    dst_file = rebase_path(ark_abc_path)
300
301    in_puts = [ prebuilt_js_path ]
302    out_puts = [ ark_abc_path ]
303  }
304
305  ohos_prebuilt_etc("ark_build") {
306    deps = [ ":ark_jsf" ]
307    source = ark_abc_path
308    part_name = "ace_engine_standard"
309  }
310}
311