# Copyright (c) 2022 Project CHIP Authors
#
# 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_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")

import("$dir_pw_build/python.gni")
import("${chip_root}/scripts/py_matter_idl/files.gni")

declare_args() {
  # Location where code has been pre-generated
  chip_code_pre_generated_directory = ""
}

# Code generation that will happen at build time.
#
# uses `scripts/codegen.py` for code generation.
template("_chip_build_time_codegen") {
  _name = target_name
  _generator = invoker.generator

  config("${_name}_config") {
    include_dirs = [ target_gen_dir ]
  }

  pw_python_action("${_name}_codegen") {
    script = "${chip_root}/scripts/codegen.py"

    # TODO: this seems to touch internals. Is this ok? speeds up builds!
    _pw_internal_run_in_venv = false

    _idl_file = invoker.input
    _expected_outputs = "${target_gen_dir}/${_name}.expected.outputs"

    write_file(_expected_outputs, invoker.outputs, "list lines")

    args = [
      "--generator",
      _generator,
      "--output-dir",
      rebase_path(target_gen_dir, root_build_dir),
      "--expected-outputs",
      rebase_path(_expected_outputs, root_build_dir),
    ]

    if (defined(invoker.options)) {
      foreach(option, invoker.options) {
        args += [
          "--option",
          option,
        ]
      }
    }

    args += [ rebase_path(_idl_file, root_build_dir) ]

    inputs = [
      _idl_file,
      _expected_outputs,
    ]

    # ensure any change in codegen files will result in a rebuild
    inputs += matter_idl_generator_files

    sources = [ _idl_file ]

    outputs = []
    foreach(name, invoker.outputs) {
      outputs += [ "${target_gen_dir}/${name}" ]
    }
  }

  source_set(_name) {
    sources = []
    foreach(name, invoker.outputs) {
      sources += [ "${target_gen_dir}/${name}" ]
    }

    public_configs = [ ":${_name}_config" ]

    if (defined(invoker.public_configs)) {
      public_configs += invoker.public_configs
    }

    forward_variables_from(invoker, [ "deps" ])

    if (!defined(deps)) {
      deps = []
    }
    deps += [ ":${_name}_codegen" ]
  }
}

# Code generation that will happen at build time.
#
# variables:
#   input
#     The ".zap" file to use to start the code generation
#
#   generator
#     Name of the generator to use. Supported variants:
#        - "app-templates"
#
#
#
#   deps, public_configs
#     Forwarded to the resulting source set
#
#
# uses `zap` for code generation.
template("_chip_build_time_zapgen") {
  _name = target_name
  _generator = invoker.generator

  config("${_name}_config") {
    include_dirs = [ "${target_gen_dir}/zapgen/" ]
  }

  assert(_generator == "app-templates")

  if (_generator == "app-templates") {
    _template_path =
        rebase_path("${chip_root}/src/app/zap-templates/app-templates.json")

    _partials_dir = "${chip_root}/src/app/zap-templates/partials"
    _template_dir = "${chip_root}/src/app/zap-templates/templates/app"

    # TODO: unclear how to maintain these: there is no parser that can figure
    #       out links of template files and zap files and such
    _extra_dependencies = [
      "${_partials_dir}/header.zapt",

      # Application templates, actually generating files
      "${_template_dir}/access.zapt",
      "${_template_dir}/CHIPClusters.zapt",
      "${_template_dir}/endpoint_config.zapt",
      "${_template_dir}/gen_config.zapt",
      "${_template_dir}/im-cluster-command-handler.zapt",
    ]

    _output_subdir = "zap-generated"
  }

  pw_python_action("${_name}_zap_pregen") {
    script = "${chip_root}/scripts/tools/zap/generate.py"

    # TODO: this seems to touch internals. Is this ok? speeds up builds!
    _pw_internal_run_in_venv = false

    _idl_file = invoker.input

    args = [
      "--no-prettify-output",
      "--templates",
      _template_path,
      "--output-dir",
      rebase_path(target_gen_dir) + "/zap_pregen/" + _output_subdir,

      # TODO: lock file support should be removed as this serializes zap
      # (slower), however this is currently done because on Darwin zap startup
      # may conflict and error out with:
      #    Error: EEXIST: file already exists, mkdir '/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pkg/465fcc8a6282e28dc7a166859d5814d34e2fb94249a72fa9229033b5b32dff1a'
      "--lock-file",
      rebase_path("${root_out_dir}/zap_gen.lock"),
      "--parallel",
      _idl_file,
    ]

    inputs = [
      _idl_file,
      _template_path,
    ]
    inputs += _extra_dependencies

    # ensure any change in codegen files will result in a rebuild
    inputs += matter_idl_generator_files

    sources = [ _idl_file ]

    outputs = []
    foreach(name, invoker.outputs) {
      outputs += [ "${target_gen_dir}/zap_pregen/${name}" ]
    }

    forward_variables_from(invoker, [ "prune_outputs" ])
    if (defined(prune_outputs)) {
      foreach(name, prune_outputs) {
        outputs += [ "${target_gen_dir}/zap_pregen/${name}" ]
      }
    }
  }

  # This action ensures that any "extra" files generated by zap codegen
  # are actually deleted.
  #
  # This is to avoid double-codegen of configurations like endpoint config
  # or access credentials being generated for both "controller client" and
  # application-specific
  pw_python_action("${_name}_files") {
    # TODO: this seems to touch internals. Is this ok? speeds up builds!
    _pw_internal_run_in_venv = false

    script = "${chip_root}/scripts/tools/zap/prune_outputs.py"

    _keep_file = rebase_path("${target_gen_dir}/${_name}.keep.outputs")
    write_file(_keep_file, invoker.outputs, "list lines")

    args = [
      "--keep",
      _keep_file,
      "--input-dir",
      rebase_path("${target_gen_dir}/zap_pregen/"),
      "--output-dir",
      rebase_path("${target_gen_dir}/zapgen/"),
    ]

    inputs = []
    foreach(name, invoker.outputs) {
      inputs += [ "${target_gen_dir}/zap_pregen/${name}" ]
    }

    outputs = []
    foreach(name, invoker.outputs) {
      outputs += [ "${target_gen_dir}/zapgen/${name}" ]
    }

    deps = [ ":${_name}_zap_pregen" ]
  }

  source_set(_name) {
    sources = []
    foreach(name, invoker.outputs) {
      sources += [ "${target_gen_dir}/zapgen/${name}" ]
    }

    public_configs = [ ":${_name}_config" ]

    if (defined(invoker.public_configs)) {
      public_configs += invoker.public_configs
    }

    forward_variables_from(invoker, [ "deps" ])

    if (!defined(public_deps)) {
      public_deps = []
    }
    public_deps += [
      ":${_name}_files",
      ":${_name}_zap_pregen",
    ]
  }
}

# Defines a target that runs code generation based on
# scripts/codegen.py
#
# Arguments:
#   input
#     The ".matter" file to use to start the code generation
#
#   generator
#     Name of the generator to use (e.g. java-jni, java-class, cpp-app)
#
#   outputs
#     Explicit names of the expected outputs. Enforced to validate that
#     expected outputs are generated when processing input files.
#
#   deps, public_configs
#     Forwarded to the resulting source set
#
# Command line parameters:
#
#  chip_code_pre_generated_directory:
#     - If this is set, generation will NOT happen at compile time but rather
#       the code generation is assumed to have already happened and reside in
#       the given location.
#     - The TOP LEVEL directory is assumed to be given. Actual location for
#       individual generators is expected to be of the form
#       <top_dir>/<matter_path>/<generator>
#
# NOTE: content of "outputs" is verified to match the output of codegen.py
#       exactly. It is not inferred on purpose, to make build-rules explicit
#       and verifiable (even though codegen.py can at runtime report its outputs)
#
#       To find the list of generated files, you can run codegen.py with the
#       "--name-only" argument
#
# NOTE:
#   the result of the target_name WILL BE a `source_set`. Treat it as such.
#
# Example usage:
#
#  chip_codegen("java-jni-generate") {
#    input = "controller-clusters.matter"
#    generator = "java-jni"
#
#    outputs = [
#       "jni/IdentifyClient-ReadImpl.cpp",
#       "jni/IdentifyClient-InvokeSubscribeImpl.cpp",
#       # ... more to follow
#    ]
#  }
#
template("chip_codegen") {
  if (chip_code_pre_generated_directory == "") {
    _chip_build_time_codegen(target_name) {
      forward_variables_from(invoker,
                             [
                               "deps",
                               "generator",
                               "input",
                               "outputs",
                               "options",
                               "public_configs",
                             ])
    }
  } else {
    _name = target_name

    not_needed(invoker, [ "options" ])

    # This constructs a path like:
    #  FROM all-clusters-app.matter (inside examples/all-clusters-app/all-clusters-common/)
    #  USING "cpp-app" for generator:
    #    => ${pregen_dir}/examples/all-clusters-app/all-clusters-common/all-clusters-app/codegen/cpp-app
    _generation_dir =
        chip_code_pre_generated_directory + "/" +
        string_replace(rebase_path(invoker.input, chip_root), ".matter", "") +
        "/codegen/" + invoker.generator

    config("${_name}_config") {
      include_dirs = [ "${_generation_dir}" ]
    }

    source_set(_name) {
      public_configs = [ ":${_name}_config" ]

      if (defined(invoker.public_configs)) {
        public_configs += invoker.public_configs
      }

      forward_variables_from(invoker, [ "deps" ])

      sources = []
      foreach(name, invoker.outputs) {
        sources += [ "${_generation_dir}/${name}" ]
      }
    }
  }
}

# Defines a target that runs code generation based on
# scripts/codegen.py
#
# Arguments:
#   input
#     The ".matter" file to use to start the code generation
#
#   generator
#     Name of the generator to use (e.g. java-jni, java-class, cpp-app)
#
#   outputs
#     Explicit names of the expected outputs. Enforced to validate that
#     expected outputs are generated when processing input files.
#
#   deps, public_configs
#     Forwarded to the resulting source set
#
# Command line parameters:
#
#  chip_code_pre_generated_directory:
#     - If this is set, generation will NOT happen at compile time but rather
#       the code generation is assumed to have already happened and reside in
#       the given location.
#     - The TOP LEVEL directory is assumed to be given. Actual location for
#       individual generators is expected to be of the form
#       <top_dir>/<matter_path>/<generator>
#
# NOTE: content of "outputs" is verified to match the output of codegen.py
#       exactly. It is not inferred on purpose, to make build-rules explicit
#       and verifiable (even though codegen.py can at runtime report its outputs)
#
#       To find the list of generated files, you can run codegen.py with the
#       "--name-only" argument
#
# NOTE:
#   the result of the target_name WILL BE a `source_set`. Treat it as such.
#
# Example usage:
#
#  chip_codegen("java-jni-generate") {
#    input = "controller-clusters.matter"
#    generator = "java-jni"
#
#    outputs = [
#       "jni/IdentifyClient-ReadImpl.cpp",
#       "jni/IdentifyClient-InvokeSubscribeImpl.cpp",
#       # ... more to follow
#    ]
#  }
#
template("chip_zapgen") {
  if (chip_code_pre_generated_directory == "") {
    _chip_build_time_zapgen(target_name) {
      forward_variables_from(invoker,
                             [
                               "deps",
                               "generator",
                               "input",
                               "outputs",
                               "public_configs",
                               "prune_outputs",
                             ])
    }
  } else {
    _name = target_name

    # This contstructs a path like:
    #  FROM all-clusters-app.zap (inside examples/all-clusters-app/all-clusters-common/)
    #  USING "cpp-app" for generator:
    #    => ${pregen_dir}/examples/all-clusters-app/all-clusters-common/all-clusters-app/codegen/cpp-app
    _generation_dir =
        chip_code_pre_generated_directory + "/" +
        string_replace(rebase_path(invoker.input, chip_root), ".zap", "") +
        "/zap/" + invoker.generator

    config("${_name}_config") {
      include_dirs = [ "${_generation_dir}" ]
    }

    # Pick up only the headers and mark them available to use
    # Specifically controller seems to require header files but NOT cpp (does)
    # not want to include cpp compilation of IM command handler data
    source_set("${_name}_headers") {
      sources = []
      foreach(name, invoker.outputs) {
        if (get_path_info(name, "extension") == "h") {
          sources += [ "${_generation_dir}/${name}" ]
        }
      }

      # Ugly, but references WILL reference back into main code.
      check_includes = false
    }

    # need to have consistent naming. Make sure "files" exists
    action("${_name}_files") {
      script = "${chip_root}/scripts/tools/zap/check_file_existence.py"

      _output_name = "${target_gen_dir}/${_name}_files_checked.stamp"

      args = [
        "--touch",
        rebase_path(_output_name),
      ]
      outputs = [ _output_name ]

      foreach(name, invoker.outputs) {
        args += [
          "--exists",
          rebase_path("${_generation_dir}/${name}"),
        ]
      }

      # Depending on the files gets access to the headers
      public_deps = [ ":${_name}_headers" ]
    }

    source_set(_name) {
      forward_variables_from(invoker,
                             [
                               "deps",
                               "public_configs",
                               "prune_outputs",
                             ])
      if (!defined(public_configs)) {
        public_configs = []
      }
      public_configs += [ ":${_name}_config" ]

      sources = []
      foreach(name, invoker.outputs) {
        sources += [ "${_generation_dir}/${name}" ]
      }

      # Ugly, but references WILL reference back into main code.
      check_includes = false
    }
  }
}
