# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Logic separated out from config.gni so that it can be used by compiler.gni
# without introducing a circular dependency.

assert(is_ohos)

declare_args() {
  # Adds instrumentation to each function. Writes a file with the order that
  # functions are called at startup.
  use_order_profiling = false

  # Only effective if use_order_profiling = true. When this is true,
  # instrumentation switches from startup profiling after a delay, and
  # then waits for a devtools memory dump request to dump all
  # profiling information. When false, the same delay is used to switch from
  # startup, and then after a second delay all profiling information is dumped.
  devtools_instrumentation_dumping = false

  # Builds secondary abi for APPs, supports build 32-bit arch as secondary
  # abi in 64-bit Monochrome and WebView.
  build_app_secondary_abi = true
}

assert(!devtools_instrumentation_dumping || use_order_profiling,
       "devtools_instrumentation_dumping requires use_order_profiling")

if (current_cpu == "x86") {
  ohos_app_abi = "x86"
} else if (current_cpu == "arm") {
  import("//build/config/arm.gni")
  if (arm_version < 7) {
    ohos_app_abi = "armeabi"
  } else {
    ohos_app_abi = "armeabi-v7a"
  }
} else if (current_cpu == "x86_64") {
  ohos_app_abi = "x86_64"
} else if (current_cpu == "arm64") {
  ohos_app_abi = "arm64-v8a"
} else if (current_cpu == "mipsel") {
  ohos_app_abi = "mips"
} else if (current_cpu == "riscv64") {
  ohos_app_abi = "riscv64"
} else if (current_cpu == "riscv32") {
  ohos_app_abi = "riscv32"
} else if (current_cpu == "loongarch64") {
  ohos_app_abi = "loongarch64"
} else {
  assert(false, "Unknown ABI: " + current_cpu)
}

if (target_cpu == "arm64" || target_cpu == "x86_64" ||
    target_cpu == "loongarch64" || target_cpu == "riscv64") {
  ohos_64bit_target_cpu = true
} else if (target_cpu == "arm" || target_cpu == "x86" ||
           target_cpu == "mipsel" || target_cpu == "riscv32") {
  ohos_64bit_target_cpu = false
} else {
  assert(false, "Unknown target CPU: $target_cpu")
}

# Intentionally do not define ohos_app_secondary_abi_cpu and
# ohos_app_secondary_abi for 32-bit target_cpu, since they are not used.
if (target_cpu == "arm64") {
  ohos_secondary_abi_cpu = "arm"
  ohos_app_secondary_abi = "armeabi-v7a"
} else if (target_cpu == "x64") {
  ohos_secondary_abi_cpu = "x86"
  ohos_app_secondary_abi = "x86"
} else if (target_cpu == "mipsel") {
  ohos_secondary_abi_cpu = "mips"
  ohos_app_secondary_abi = "mips"
} else if (target_cpu == "riscv64") {
  ohos_secondary_abi_cpu = "riscv64"
  ohos_app_secondary_abi = "riscv64"
}

if (defined(ohos_secondary_abi_cpu)) {
  ohos_secondary_abi_toolchain =
      "//build/toolchain/ohos:ohos_clang_${ohos_secondary_abi_cpu}"
}