# Copyright (c) 2021 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/config/components/idl_tool/idl.gni")
import("//build/ohos.gni")
import("../../services/engine/engine_sa.gni")

idl_interface_sources = [ "${target_gen_dir}/update_service_stub.cpp" ]

idl_include = [
  "${target_gen_dir}",
  "${target_gen_dir}/callback",
]

idl_gen_interface("update_service_interface") {
  src_idl = rebase_path(updateengine_idl_path + "/" + "IUpdateService.idl")
  sources_callback = [ "callback/IUpdateCallback.idl" ]
  dst_file = string_join(",", idl_interface_sources)
  log_domainid = "0xD002E00"
  log_tag = "UPDATE_SERVICE_KITS"
}

ohos_prebuilt_etc("dupdate_config.json") {
  source = "$update_service_dupdate_config_path"
  relative_install_dir = "update"
  install_images = [
    "updater",
    "system",
  ]
  part_name = "$updateengine_part_name"
  subsystem_name = "updater"
}

ohos_prebuilt_etc("updater_sa.cfg") {
  source = "$update_service_updater_sa_cfg_path"
  relative_install_dir = "init"
  part_name = "$updateengine_part_name"
  subsystem_name = "updater"
}

ohos_shared_library("$updateengine_library_name") {
  sanitize = {
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = false
    blocklist = "./cfi_blocklist.txt"
  }
  branch_protector_ret = "pac_ret"
  shlib_type = "sa"
  include_dirs = sa_include_dirs
  include_dirs += idl_include
  sources = sa_sources
  output_values = get_target_outputs(":update_service_interface")
  sources += filter_include(output_values, [ "*_stub.cpp" ])
  deps = sa_deps
  deps += [ ":update_service_interface" ]
  external_deps = sa_external_deps
  part_name = "$updateengine_part_name"
  subsystem_name = "updater"
  defines = sa_defines
  cflags = sa_cflags
}