# 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/python.gni")
import("//build/ohos/build_var.gni")
import("//build/ohos_var.gni")

template("ohos_hisysevent_install_info") {
  assert(defined(invoker.system_install_info_file))
  assert(defined(invoker.hisysevent_install_info_file))

  forward_variables_from(invoker,
                         [
                           "system_install_info_file",
                           "hisysevent_install_info_file",
                         ])

  _deps = []
  if (defined(invoker.deps)) {
    _deps += invoker.deps
  }

  if (is_system_component) {
    config_install_dir = "${system_base_dir}/etc/hiview"
  } else {
    config_install_dir = "${vendor_base_dir}/etc/hiview"
  }

  action_with_pydeps(target_name) {
    deps = _deps
    script = "//build/ohos/hisysevent/hisysevent_process.py"
    hisysevent_config_file =
        "${build_configs_path}/parts_info/hisysevent_configs.json"
    sources = [ system_install_info_file ]
    outputs = [ hisysevent_install_info_file ]
    depfile = "$target_gen_dir/$target_name.d"
    args = [
      "--parts-config-file",
      rebase_path(hisysevent_config_file, root_build_dir),
      "--system-install-info-file",
      rebase_path(system_install_info_file, root_build_dir),
      "--config-install-dest-dir",
      config_install_dir,
      "--hisysevent-install-info-file",
      rebase_path(hisysevent_install_info_file, root_build_dir),
      "--depfile",
      rebase_path(depfile, root_build_dir),
      "--source-root-dir",
      rebase_path("//"),
      "--gn-root-build-dir",
      rebase_path(root_build_dir),
    ]
  }
}