# Copyright (c) 2021-2023 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("//base/update/sys_installer/sys_installer_default_cfg.gni")
import("//build/ohos.gni")

sys_installer_path = rebase_path("${sys_installer_absolutely_path}", ".")

config("libsysinstallerkits_exported_headers") {
  visibility = [ ":*" ]
  include_dirs = [
    "${sys_installer_path}/common/include",
    "${sys_installer_path}/include",
    "${sys_installer_path}/interfaces/innerkits",
    "${sys_installer_path}/interfaces/inner_api/include",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/include",
  ]
}

ohos_shared_library("libsysinstaller_shared") {
  defines = [ "SYS_INSTALLER_KITS" ]
  sources = [
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_callback.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_kits_impl.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_load_callback.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_proxy.cpp",
  ]

  include_dirs = [
    "${sys_installer_path}/common/include",
    "${sys_installer_path}/include",
    "${sys_installer_path}/interfaces/innerkits",
    "${sys_installer_path}/interfaces/inner_api/include",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/include",
  ]

  public_configs = [ ":libsysinstallerkits_exported_headers" ]

  deps = []

  external_deps = [
    "bounds_checking_function:libsec_shared",
    "c_utils:utils",
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_core",
    "lz4:liblz4_static",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
    "updater:libupdaterlog",
    "updater:libutils_fs",
    "zlib:shared_libz",
  ]

  innerapi_tags = [
    "platformsdk",
    "sasdk",
  ]

  part_name = "sys_installer"
  subsystem_name = "updater"
}

ohos_static_library("libsysinstallerkits") {
  defines = [ "SYS_INSTALLER_KITS" ]
  sources = [
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_callback.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_kits_impl.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_load_callback.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_proxy.cpp",
  ]

  include_dirs = [
    "${sys_installer_path}/common/include",
    "${sys_installer_path}/include",
    "${sys_installer_path}/interfaces/innerkits",
    "${sys_installer_path}/interfaces/inner_api/include",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/include",
  ]

  public_configs = [ ":libsysinstallerkits_exported_headers" ]

  deps = []

  external_deps = [
    "bounds_checking_function:libsec_static",
    "c_utils:utils",
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
    "updater:libupdaterlog",
    "updater:libutils",
  ]

  part_name = "sys_installer"
  subsystem_name = "updater"
}

ohos_executable("sys_installer_client") {
  sources = [ "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_client.cpp" ]

  include_dirs = [
    "${sys_installer_path}/interfaces/innerkits/ipc_client/include",
    "${sys_installer_path}/interfaces/inner_api/include",
  ]

  deps = [
    "${sys_installer_path}/interfaces/innerkits/ipc_client:libsysinstallerkits",
  ]
  external_deps = [
    "bounds_checking_function:libsec_static",
    "c_utils:utils",
    "hilog:libhilog",
    "init:libbegetutil",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
  install_enable = true
  part_name = "sys_installer"
  subsystem_name = "updater"
}

module_update_gen("module_update") {
  include_dirs = [ "./include" ]

  deps = [ "${sys_installer_path}/interfaces/innerkits/ipc_client:libmodule_update_shared" ]

  public_configs = [ ":exported_header_files" ]

  if (defined(module_update_custom_external_deps)) {
    external_deps = module_update_custom_external_deps
  }

  part_name = "sys_installer"
  subsystem_name = "updater"
}

config("exported_header_files") {
  visibility = [ ":*" ]
  include_dirs = [
    "${sys_installer_path}/services/module_update/util/include",
    "${sys_installer_path}/interfaces/inner_api/include",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/include",
  ]
}

ohos_executable("module_update_client") {
  sources =
      [ "${sys_installer_path}/interfaces/innerkits/ipc_client/src/main.cpp" ]

  include_dirs = [ "./include" ]
  deps = [ "${sys_installer_path}/interfaces/innerkits/ipc_client:libmodule_update_shared" ]
  public_configs = [ ":exported_header_files" ]

  external_deps = [
    "c_utils:utils",
    "ipc:ipc_core",
    "samgr:samgr_proxy",
    "updater:libupdaterlog",
  ]
  install_enable = false
  part_name = "sys_installer"
  subsystem_name = "updater"
}

ohos_static_library("module_update_client_static") {
  sources = [
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/module_update_kits_impl.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/module_update_load_callback.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/module_update_proxy.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_callback.cpp",
    "${sys_installer_path}/services/module_update/util/src/module_ipc_helper.cpp",
  ]

  include_dirs = [ "${sys_installer_path}/common/include" ]

  public_configs = [ ":exported_header_files" ]

  public_external_deps = [ "zlib:shared_libz" ]

  external_deps = [
    "bounds_checking_function:libsec_static",
    "c_utils:utils",
    "init:libbegetutil",
    "ipc:ipc_core",
    "samgr:samgr_proxy",
    "updater:libupdaterlog",
    "zlib:shared_libz",
  ]

  part_name = "sys_installer"
  subsystem_name = "updater"
}

ohos_shared_library("libmodule_update_shared") {
  sources = [
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/module_update_kits_impl.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/module_update_load_callback.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/module_update_proxy.cpp",
    "${sys_installer_path}/interfaces/innerkits/ipc_client/src/sys_installer_callback.cpp",
    "${sys_installer_path}/services/module_update/util/src/module_ipc_helper.cpp",
  ]

  include_dirs = [ "${sys_installer_path}/common/include" ]

  public_configs = [ ":exported_header_files" ]

  public_external_deps = [ "zlib:shared_libz" ]

  external_deps = [
    "bounds_checking_function:libsec_static",
    "c_utils:utils",
    "init:libbegetutil",
    "ipc:ipc_core",
    "samgr:samgr_proxy",
    "updater:libupdaterlog",
    "zlib:shared_libz",
  ]

  innerapi_tags = [
    "platformsdk",
    "sasdk",
  ]

  part_name = "sys_installer"
  subsystem_name = "updater"
}