13af6ab5fSopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd.
23af6ab5fSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
33af6ab5fSopenharmony_ci# you may not use this file except in compliance with the License.
43af6ab5fSopenharmony_ci# You may obtain a copy of the License at
53af6ab5fSopenharmony_ci#
63af6ab5fSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
73af6ab5fSopenharmony_ci#
83af6ab5fSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
93af6ab5fSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
103af6ab5fSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113af6ab5fSopenharmony_ci# See the License for the specific language governing permissions and
123af6ab5fSopenharmony_ci# limitations under the License.
133af6ab5fSopenharmony_ci
143af6ab5fSopenharmony_ciimport("//arkcompiler/ets_frontend/ets_frontend_config.gni")
153af6ab5fSopenharmony_ci
163af6ab5fSopenharmony_ciets2abc_root = "//arkcompiler/ets_frontend/ets2panda/aot"
173af6ab5fSopenharmony_ciets2abc_build_path = ""
183af6ab5fSopenharmony_ciets2abc_build_deps = ""
193af6ab5fSopenharmony_ciets2abc_out_root = ""
203af6ab5fSopenharmony_ci
213af6ab5fSopenharmony_ciif (host_toolchain == toolchain_mac) {
223af6ab5fSopenharmony_ci  ets2abc_out_root =
233af6ab5fSopenharmony_ci      get_label_info("$ets2abc_root:ets2panda($toolchain_mac)", "root_out_dir")
243af6ab5fSopenharmony_ci  ets2abc_build_deps = [ "$ets2abc_root:ets2panda($toolchain_mac)" ]
253af6ab5fSopenharmony_ci} else if (host_toolchain == toolchain_win) {
263af6ab5fSopenharmony_ci  ets2abc_out_root =
273af6ab5fSopenharmony_ci      get_label_info("$ets2abc_root:ets2panda($toolchain_win)", "root_out_dir")
283af6ab5fSopenharmony_ci  ets2abc_build_deps = [ "$ets2abc_root:ets2panda($toolchain_win)" ]
293af6ab5fSopenharmony_ci} else {
303af6ab5fSopenharmony_ci  ets2abc_out_root = get_label_info("$ets2abc_root:ets2panda($toolchain_linux)",
313af6ab5fSopenharmony_ci                                    "root_out_dir")
323af6ab5fSopenharmony_ci  ets2abc_build_deps = [ "$ets2abc_root:ets2panda($toolchain_linux)" ]
333af6ab5fSopenharmony_ci}
343af6ab5fSopenharmony_ciets2abc_build_path = ets2abc_out_root + "/arkcompiler/ets_frontend"
353af6ab5fSopenharmony_ci
363af6ab5fSopenharmony_ci# Generate abc.
373af6ab5fSopenharmony_ci#
383af6ab5fSopenharmony_ci# Mandatory arguments:
393af6ab5fSopenharmony_ci# plugin_path -- plugin js file path
403af6ab5fSopenharmony_ci# plugin_name -- name of js file, ex: BatteryPlugin.js
413af6ab5fSopenharmony_ci# generat_file -- name of generated file
423af6ab5fSopenharmony_ci# package_name -- name of generated file's package
433af6ab5fSopenharmony_ci# extra_dependencies -- a list of files that should be considered as dependencies, must be label
443af6ab5fSopenharmony_ci# out_puts
453af6ab5fSopenharmony_citemplate("ets2abc_gen_abc") {
463af6ab5fSopenharmony_ci  assert(defined(invoker.src_ets), "src_ets is required!")
473af6ab5fSopenharmony_ci  assert(defined(invoker.dst_file), "dst_file is required!")
483af6ab5fSopenharmony_ci  assert(defined(invoker.out_puts), "out_puts is required!")
493af6ab5fSopenharmony_ci
503af6ab5fSopenharmony_ci  extra_dependencies = []
513af6ab5fSopenharmony_ci  if (defined(invoker.extra_dependencies)) {
523af6ab5fSopenharmony_ci    extra_dependencies += invoker.extra_dependencies
533af6ab5fSopenharmony_ci  }
543af6ab5fSopenharmony_ci
553af6ab5fSopenharmony_ci  action("$target_name") {
563af6ab5fSopenharmony_ci    if (defined(invoker.extra_visibility)) {
573af6ab5fSopenharmony_ci      visibility = invoker.extra_visibility
583af6ab5fSopenharmony_ci    }
593af6ab5fSopenharmony_ci
603af6ab5fSopenharmony_ci    script = "//arkcompiler/ets_runtime/script/run_ark_executable.py"
613af6ab5fSopenharmony_ci
623af6ab5fSopenharmony_ci    deps = extra_dependencies
633af6ab5fSopenharmony_ci    deps += ets2abc_build_deps
643af6ab5fSopenharmony_ci
653af6ab5fSopenharmony_ci    args = [
663af6ab5fSopenharmony_ci      "--script-file",
673af6ab5fSopenharmony_ci      rebase_path("${ets2abc_build_path}/es2panda"),
683af6ab5fSopenharmony_ci      "--script-args",
693af6ab5fSopenharmony_ci      "--ets-module --output " + invoker.dst_file + " " + invoker.src_ets,
703af6ab5fSopenharmony_ci      "--env-path",
713af6ab5fSopenharmony_ci      rebase_path("${ets2abc_out_root}/arkcompiler/runtime_core/") + ":" +
723af6ab5fSopenharmony_ci          rebase_path("${ets2abc_out_root}/arkcompiler/ets_frontend/") + ":" +
733af6ab5fSopenharmony_ci          rebase_path("${ets2abc_out_root}/arkcompiler/ets_runtime/") + ":" +
743af6ab5fSopenharmony_ci          rebase_path("${ets2abc_out_root}/thirdparty/zlib/") + ":" +
753af6ab5fSopenharmony_ci          rebase_path("${ets2abc_out_root}/thirdparty/icu/"),
763af6ab5fSopenharmony_ci      "--expect-output",
773af6ab5fSopenharmony_ci      "0",
783af6ab5fSopenharmony_ci    ]
793af6ab5fSopenharmony_ci
803af6ab5fSopenharmony_ci    if (defined(invoker.in_puts)) {
813af6ab5fSopenharmony_ci      inputs = invoker.in_puts
823af6ab5fSopenharmony_ci    }
833af6ab5fSopenharmony_ci
843af6ab5fSopenharmony_ci    outputs = invoker.out_puts
853af6ab5fSopenharmony_ci  }
863af6ab5fSopenharmony_ci}
87