# Copyright (c) 2026 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/ohos.gni")
import("//build/ohos/cli/ohos_cli_executable.gni")
import("./../../usbmgr.gni")

config("usb_cli_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${usb_manager_path}/interfaces/innerkits/native/include",
    "${utils_path}/native/include",
  ]
}

ohos_cli_executable("ohos-usbManager") {
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }

  branch_protector_ret = "pac_ret"

  cli_config_file = "ohos-usbManager.json"

  sources = [
    "src/usb_cli.cpp",
    "src/usb_cli_serialization.cpp",
  ]

  configs = [
    "${utils_path}:utils_config",
    ":usb_cli_config",
  ]

  deps = [ "${usb_manager_path}/interfaces/innerkits:usbsrv_client" ]
  external_deps = [
    "cJSON:cjson",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_core",
  ]

  install_enable = true
  install_images = [ "system" ]
  relative_install_dir = "cli_tool/executable"

  subsystem_name = "usb"
  part_name = "usb_manager"
}

group("usb_cli") {
  deps = []
  if (usb_manager_feature_support_cli) {
    deps += [ ":ohos-usbManager" ]
  }
}

group("usb_cli_test") {
  testonly = true
  deps = []
  if (usb_manager_feature_support_cli) {
    deps += [ "tests:usb_cli_unittest" ]
  }
}