# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//arkcompiler/ets_runtime/js_runtime_config.gni")

action("es2abc_parser_tests") {
  script = "${es2abc_root}/test/runner.py"

  deps = es2abc_build_deps

  args = [
    "--no-progress",
    "--regression",
    rebase_path("${es2abc_build_path}"),
  ]

  outputs = [ "${es2abc_build_path}/keep_es2abc_parser_tests_run" ]
}

action("es2abc_parser_tsc_tests") {
  script = "${es2abc_root}/test/runner.py"

  deps = es2abc_build_deps

  tsc_path = rebase_path("//third_party/typescript/")

  args = [
    "--no-progress",
    "--tsc",
    "--tsc-path",
    tsc_path,
    rebase_path("${es2abc_build_path}"),
  ]

  outputs = [ "${es2abc_build_path}/keep_es2abc_parser_tsc_tests_run" ]
}

action("es2abc_compiler_tests") {
  script = "${es2abc_root}/test/runner.py"

  deps = es2abc_build_deps
  deps += [ "${js_root}:ark_js_host_linux_tools_packages" ]

  host_jsvm_target = "${js_root}/ecmascript/js_vm:ark_js_vm(${host_toolchain})"
  root_out_dir = get_label_info(host_jsvm_target, "root_out_dir")
  ark_js_runtime_dir = rebase_path("${root_out_dir}/arkcompiler/ets_runtime")

  if (is_standard_system) {
    icu_path = "thirdparty/icu"
  } else {
    icu_path = "global/i18n"
  }
  icu_dir = rebase_path("${root_out_dir}/${icu_path}")

  llvm_lib_dir = rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/")

  zlib_dir = rebase_path("${root_out_dir}/thirdparty/zlib")

  ld_library_path =
      "${ark_js_runtime_dir}:${icu_dir}:${llvm_lib_dir}:${zlib_dir}"

  args = [
    "--no-progress",
    "--js-runtime",
    ark_js_runtime_dir,
    "--LD_LIBRARY_PATH",
    ld_library_path,
    "--compiler",
    rebase_path("${es2abc_build_path}"),
  ]

  outputs = [ "${es2abc_build_path}/keep_es2abc_compiler_tests_run" ]
}

action("es2abc_patch_tests") {
  script = "${es2abc_root}/test/runner.py"

  deps = es2abc_build_deps

  args = [
    "--no-progress",
    "--hotfix",
    "--coldfix",
    "--hotreload",
    rebase_path("${es2abc_build_path}"),
  ]

  outputs = [ "${es2abc_build_path}/keep_es2abc_patch_tests_run" ]
}

action("es2abc_base64_tests") {
  script = "${es2abc_root}/test/runner.py"

  deps = es2abc_build_deps

  args = [
    "--no-progress",
    "--base64",
    rebase_path("${es2abc_build_path}"),
  ]

  outputs = [ "${es2abc_build_path}/keep_es2abc_base64_tests_run" ]
}

action("es2abc_bytecode_tests") {
  script = "${es2abc_root}/test/runner.py"

  deps = es2abc_build_deps

  args = [
    "--no-progress",
    "--bytecode",
    rebase_path("${es2abc_build_path}"),
  ]

  outputs = [ "${es2abc_build_path}/keep_es2abc_bytecode_tests_run" ]
}