# 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("//base/update/updater/updater_default_cfg.gni")
import("//build/ohos.gni")

updater_path = rebase_path("${updater_absolutely_path}", ".")

updater_normal_path = "${updater_path}/services/etc/updater_normal.cfg"
if (!ohos_indep_compiler_enable) {
  updater_usb_init_cfg_path = "//base/startup/init/services/etc/init.usb.cfg"
  if (updater_use_init_usb_configfs_cfg) {
    updater_init_usb_configfs_path_cfg =
        "//drivers/peripheral/usb/cfg/init.usb.configfs.cfg"
  }
  updater_faultloggerd_cfg =
      "//base/hiviewdfx/faultloggerd/services/config/faultloggerd.cfg"

  ohos_prebuilt_etc("updater_faultloggerd.cfg") {
    source = "${updater_faultloggerd_cfg}"
    install_images = [ "updater" ]
    subsystem_name = "updater"
    part_name = "updater"
  }
}

ohos_prebuilt_etc("updater_common.cfg") {
  source = "updater_common.cfg"
  install_images = [ "updater" ]
  subsystem_name = "updater"
  part_name = "updater"
}

ohos_prebuilt_etc("updater_hdcd.cfg") {
  source = "updater_hdcd.cfg"
  install_images = [ "updater" ]
  subsystem_name = "updater"
  part_name = "updater"
}
if (!ohos_indep_compiler_enable) {
  ohos_prebuilt_etc("updater_init_usb.cfg") {
    source = "${updater_usb_init_cfg_path}"
    install_images = [ "updater" ]
    subsystem_name = "updater"
    part_name = "updater"
  }

  if (updater_use_init_usb_configfs_cfg) {
    ohos_prebuilt_etc("updater_init_usb_configfs.cfg") {
      source = "${updater_init_usb_configfs_path_cfg}"
      install_images = [ "updater" ]
      subsystem_name = "updater"
      part_name = "updater"
    }
  }
}

ohos_prebuilt_etc("updater_normal.cfg") {
  source = "${updater_normal_path}"
  module_install_dir = "etc/init"
  install_images = [ "system" ]
  subsystem_name = "updater"
  part_name = "updater"
}

group("updater_files") {
  deps = [
    ":updater_common.cfg",
    ":updater_normal.cfg",
  ]
  if (!ohos_indep_compiler_enable) {
    deps += [
      ":updater_faultloggerd.cfg",
      ":updater_init_usb.cfg",
    ]
    if (updater_use_init_usb_configfs_cfg) {
      deps += [
        ":updater_init_usb_configfs.cfg",
      ]
    }
  }
  if (build_variant == "root") {
    deps += [ ":updater_hdcd.cfg" ]
  }
}