1# Copyright (c) 2024 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("//arkcompiler/ets_frontend/ets_frontend_config.gni")
15
16ets2abc_root = "//arkcompiler/ets_frontend/ets2panda/aot"
17ets2abc_build_path = ""
18ets2abc_build_deps = ""
19ets2abc_out_root = ""
20
21if (host_toolchain == toolchain_mac) {
22  ets2abc_out_root =
23      get_label_info("$ets2abc_root:ets2panda($toolchain_mac)", "root_out_dir")
24  ets2abc_build_deps = [ "$ets2abc_root:ets2panda($toolchain_mac)" ]
25} else if (host_toolchain == toolchain_win) {
26  ets2abc_out_root =
27      get_label_info("$ets2abc_root:ets2panda($toolchain_win)", "root_out_dir")
28  ets2abc_build_deps = [ "$ets2abc_root:ets2panda($toolchain_win)" ]
29} else {
30  ets2abc_out_root = get_label_info("$ets2abc_root:ets2panda($toolchain_linux)",
31                                    "root_out_dir")
32  ets2abc_build_deps = [ "$ets2abc_root:ets2panda($toolchain_linux)" ]
33}
34ets2abc_build_path = ets2abc_out_root + "/arkcompiler/ets_frontend"
35
36# Generate abc.
37#
38# Mandatory arguments:
39# plugin_path -- plugin js file path
40# plugin_name -- name of js file, ex: BatteryPlugin.js
41# generat_file -- name of generated file
42# package_name -- name of generated file's package
43# extra_dependencies -- a list of files that should be considered as dependencies, must be label
44# out_puts
45template("ets2abc_gen_abc") {
46  assert(defined(invoker.src_ets), "src_ets is required!")
47  assert(defined(invoker.dst_file), "dst_file is required!")
48  assert(defined(invoker.out_puts), "out_puts is required!")
49
50  extra_dependencies = []
51  if (defined(invoker.extra_dependencies)) {
52    extra_dependencies += invoker.extra_dependencies
53  }
54
55  action("$target_name") {
56    if (defined(invoker.extra_visibility)) {
57      visibility = invoker.extra_visibility
58    }
59
60    script = "//arkcompiler/ets_runtime/script/run_ark_executable.py"
61
62    deps = extra_dependencies
63    deps += ets2abc_build_deps
64
65    args = [
66      "--script-file",
67      rebase_path("${ets2abc_build_path}/es2panda"),
68      "--script-args",
69      "--ets-module --output " + invoker.dst_file + " " + invoker.src_ets,
70      "--env-path",
71      rebase_path("${ets2abc_out_root}/arkcompiler/runtime_core/") + ":" +
72          rebase_path("${ets2abc_out_root}/arkcompiler/ets_frontend/") + ":" +
73          rebase_path("${ets2abc_out_root}/arkcompiler/ets_runtime/") + ":" +
74          rebase_path("${ets2abc_out_root}/thirdparty/zlib/") + ":" +
75          rebase_path("${ets2abc_out_root}/thirdparty/icu/"),
76      "--expect-output",
77      "0",
78    ]
79
80    if (defined(invoker.in_puts)) {
81      inputs = invoker.in_puts
82    }
83
84    outputs = invoker.out_puts
85  }
86}
87