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 (host_toolchain == toolchain_mac) {
24  es2abc_out_root =
25      get_label_info("$es2abc_root:es2panda($toolchain_mac)", "root_out_dir")
26  es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_mac)" ]
27} else if (host_toolchain == toolchain_win) {
28  es2abc_out_root =
29      get_label_info("$es2abc_root:es2panda($toolchain_win)", "root_out_dir")
30  es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_win)" ]
31} else {
32  es2abc_out_root =
33      get_label_info("$es2abc_root:es2panda($toolchain_linux)", "root_out_dir")
34  es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_linux)" ]
35}
36if (ohos_indep_compiler_enable) {
37  es2abc_build_path = es2abc_indep_path
38} else {
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