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/components/ets_frontend/ets_frontend_config.gni")
15
16es2abc_root = "//arkcompiler/ets_frontend/es2panda"
17es2abc_build_path = ""
18es2abc_build_deps = []
19es2abc_out_root = ""
20es2abc_indep_path =
21    "//binarys/arkcompiler/ets_frontend/innerapis/es2panda/clang_x64/libs"
22
23if (ohos_indep_compiler_enable) {
24  es2abc_build_path = es2abc_indep_path
25} else {
26  if (host_toolchain == toolchain_mac) {
27    es2abc_out_root =
28        get_label_info("$es2abc_root:es2panda($toolchain_mac)", "root_out_dir")
29    es2abc_build_deps += [ "$es2abc_root:es2panda($toolchain_mac)" ]
30  } else if (host_toolchain == toolchain_win) {
31    es2abc_out_root =
32        get_label_info("$es2abc_root:es2panda($toolchain_win)", "root_out_dir")
33    es2abc_build_deps += [ "$es2abc_root:es2panda($toolchain_win)" ]
34  } else {
35    es2abc_out_root = get_label_info("$es2abc_root:es2panda($toolchain_linux)",
36                                     "root_out_dir")
37    es2abc_build_deps += [ "$es2abc_root:es2panda($toolchain_linux)" ]
38  }
39  es2abc_build_path = es2abc_out_root + "/arkcompiler/ets_frontend"
40}
41
42# Generate abc.
43#
44# Mandatory arguments:
45# plugin_path -- plugin js file path
46# plugin_name -- name of js file, ex: BatteryPlugin.js
47# generat_file -- name of generated file
48# package_name -- name of generated file's package
49# extra_dependencies -- a list of files that should be considered as dependencies, must be label
50# out_puts
51template("es2abc_gen_abc") {
52  assert(defined(invoker.src_js), "src_js is required!")
53  assert(defined(invoker.dst_file), "dst_file is required!")
54  assert(defined(invoker.out_puts), "out_puts is required!")
55
56  extra_dependencies = []
57  if (defined(invoker.extra_dependencies)) {
58    extra_dependencies += invoker.extra_dependencies
59  }
60
61  action("$target_name") {
62    if (defined(invoker.extra_visibility)) {
63      visibility = invoker.extra_visibility
64    }
65
66    script = "//build/scripts/generate_js_bytecode.py"
67
68    deps = extra_dependencies
69    deps += es2abc_build_deps
70
71    args = [
72      "--src-js",
73      invoker.src_js,
74      "--dst-file",
75      invoker.dst_file,
76      "--frontend-tool-path",
77      rebase_path("${es2abc_build_path}"),
78    ]
79
80    if (defined(invoker.extension)) {
81      args += [
82        "--extension",
83        invoker.extension,
84      ]
85    }
86
87    if (defined(invoker.dump_symbol_table)) {
88      args += [
89        "--dump-symbol-table",
90        invoker.dump_symbol_table,
91      ]
92    }
93    if (defined(invoker.input_symbol_table)) {
94      args += [
95        "--input-symbol-table",
96        invoker.input_symbol_table,
97      ]
98    }
99
100    if (defined(invoker.extra_args)) {
101      args += invoker.extra_args
102    }
103
104    if (defined(invoker.in_puts)) {
105      inputs = invoker.in_puts
106    }
107
108    outputs = invoker.out_puts
109  }
110}
111
112template("es2abc_gen_newest_abc") {
113  assert(defined(invoker.src_js), "src_js is required!")
114  assert(defined(invoker.dst_file), "dst_file is required!")
115  assert(defined(invoker.out_puts), "out_puts is required!")
116
117  extra_dependencies = []
118  if (defined(invoker.extra_dependencies)) {
119    extra_dependencies += invoker.extra_dependencies
120  }
121
122  action("$target_name") {
123    if (defined(invoker.extra_visibility)) {
124      visibility = invoker.extra_visibility
125    }
126
127    script = "//build/scripts/generate_js_bytecode.py"
128
129    deps = extra_dependencies
130    deps += es2abc_build_deps
131
132    args = [
133      "--src-js",
134      invoker.src_js,
135      "--dst-file",
136      invoker.dst_file,
137      "--frontend-tool-path",
138      rebase_path("${es2abc_build_path}"),
139    ]
140
141    if (defined(invoker.extension)) {
142      args += [
143        "--extension",
144        invoker.extension,
145      ]
146    }
147
148    if (defined(invoker.dump_symbol_table)) {
149      args += [
150        "--dump-symbol-table",
151        invoker.dump_symbol_table,
152      ]
153    }
154    if (defined(invoker.input_symbol_table)) {
155      args += [
156        "--input-symbol-table",
157        invoker.input_symbol_table,
158      ]
159    }
160
161    if (defined(invoker.extra_args)) {
162      args += invoker.extra_args
163    }
164
165    if (defined(invoker.in_puts)) {
166      inputs = invoker.in_puts
167    }
168
169    args += [ "--target-api-sub-version=beta3" ]
170
171    outputs = invoker.out_puts
172  }
173}
174