# Copyright (c) 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("//build/config/python.gni")
import("//build/templates/common/copy.gni")

template("ohos_parameter_to_h") {
  assert(defined(invoker.sources),
         "sources must be defined for ${target_name}.")
  assert(defined(invoker.output), "output must be defined for ${target_name}.")

  _fixed_parameter_file = target_gen_dir + "/" + invoker.output

  action_with_pydeps(target_name) {
    deps = []
    script = "//plugins/device_info/etc/script/parameter_fixer.py"
    depfile = "${target_gen_dir}/${target_name}.d"
    args = [
      "--output",
      rebase_path(_fixed_parameter_file, root_build_dir),
      "--depfile",
      rebase_path(depfile, root_build_dir),
    ]
    foreach(source, invoker.sources) {
      args += [
        "--source-file",
        rebase_path(source, root_build_dir),
      ]
    }

    if (defined(invoker.extra_parameter_cfgs)) {
      foreach(extra, invoker.extra_parameter_cfgs) {
        args += [
          "--extra_parameter_cfg",
          extra,
        ]
      }
    }
    outputs = [ _fixed_parameter_file ]
  }
}