# 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",
      "${_partials_dir}/im_command_handler_cluster_commands.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
    }
  }
}
