# Copyright (c) 2021-2025 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("//build/test.gni")
import("//build/ohos/cli/ohos_cli_executable.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")

config("cc_command_config") {
  include_dirs = [
    "include",
    "${ability_runtime_innerkits_path}/ability_manager/include",
    "${ability_runtime_innerkits_path}/app_manager/include/appmgr",
    "${ability_runtime_services_path}/abilitymgr/include",
  ]
}

config("cc_command_exception_config") {
  cflags_cc = [ "-fexceptions" ]
}

ohos_static_library("tools_cc_source_set") {
  sources = [
    "src/cc_command.cpp",
    "src/cc_param_parser.cpp",
    "${ability_runtime_path}/tools/aa/src/shell_command.cpp",
  ]

  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
  }

  public_configs = [
    ":cc_command_config",
    ":cc_command_exception_config",
    "${ability_runtime_services_path}/abilitymgr:abilityms_config",
    "${ability_runtime_services_path}/common:common_config",
  ]

  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }

  deps = [
    "${ability_runtime_innerkits_path}/ability_manager:ability_manager",
    "${ability_runtime_abilitymgr_path}/:abilityms",
  ]

  external_deps = [
    "ability_base:base",
    "ability_base:want",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
    "json:nlohmann_json_static",
    "samgr:samgr_proxy",
  ]

  subsystem_name = "ability"
  part_name = "ability_runtime"
}

ohos_cli_executable("ohos-claw-cc") {
  sources = [ "src/main.cpp" ]

  sanitize = {
    integer_overflow = true
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
  }

  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }

  deps = [
    ":tools_cc_source_set",
    "${ability_runtime_innerkits_path}/ability_manager:ability_manager",
  ]

  external_deps = [
    "ability_base:base",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
  ]

  defines = []

  install_enable = true
  install_images = [ "system" ]
  cli_config_file = "ohos-claw-cc.json"

  subsystem_name = "ability"
  part_name = "ability_runtime"
}

group("tools_cc") {
  deps = [
    ":ohos-claw-cc",
  ]
}