# Copyright (C) 2017 The Android Open Source Project
#
# 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("perfetto.gni")

# This gni file defines rules for proto generation. There are various types of
# proto targets that can be defined in our codebase:
# "lite" targets: these use the standard libprotobuf library. They are used
#     mainly for tests and readback.
# "zero" targets: these use the protozero library and its protoc plugin. They
#     are used pretty much everywhere.
# "descriptor" targets: they are used to generate a proto-encoded reflection
#     descriptor that describes the schema of the proto using protobuf itself.
# All these targets can be generated using the perfetto_proto_library rule. It
# wraps the instantiation of several proto targets using a convenience template.
#
# For instance:
# perfetto_proto_library("xxx_@TYPE@") {
#   proto_generators = [ "lite", "zero" ]  # lite+zero is the default value.
#   sources = [ "one.proto", "two.proto" ]
#   deps = [ "dep:@TYPE@" ]
# }
#
# Is the equivalent of:
# proto_library("xxx_lite")     { sources = [...], deps = [ "dep:lite"] }
# protozero_library("xxx_zero") { sources = [...], deps = [ "dep:zero"] }

# Load the protobuf's proto_library() definition.
if (!defined(perfetto_protobuf_target_prefix)) {
  if (perfetto_root_path == "//") {
    perfetto_protobuf_target_prefix = "//buildtools"
  } else {
    perfetto_protobuf_target_prefix = "//third_party/protobuf"
  }
}
if (!defined(perfetto_protobuf_gni)) {
  if (perfetto_root_path == "//") {
    perfetto_protobuf_gni = "//gn/standalone/proto_library.gni"
  } else {
    perfetto_protobuf_gni = "//third_party/protobuf/proto_library.gni"
  }
}
import(perfetto_protobuf_gni)

# Equivalent to proto_library (generation of .h/.cc from .proto files) but
# enables also generation using the protozero plugin.
# The generated files will have the .pbzero.{cc,h} suffix, as opposed to the
# .pb.{cc,h} of the official proto library.
# DO NOT use this target directly, use perfetto_proto_library() below.
template("protozero_library") {
  proto_library(target_name) {
    perfetto_root_path = invoker.perfetto_root_path

    generate_cc = false
    generate_python = false
    generator_plugin_label =
        perfetto_root_path + "src/protozero/protoc_plugin:protozero_plugin"
    generator_plugin_suffix = ".pbzero"
    if (build_with_chromium) {
      component_build_force_source_set = true
    }

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

    deps += [ perfetto_root_path + "src/protozero" ]

    forward_variables_from(invoker,
                           [
                             "defines",
                             "generator_plugin_options",
                             "include_dirs",
                             "proto_in_dir",
                             "proto_out_dir",
                             "sources",
                             "testonly",
                             "visibility",
                             "generate_descriptor",
                           ])
  }
}

# This template generates .gen.cc/h files from .proto files. The generated
# sources are actual C++ classes that can be moved and copied around, very
# similar to the libprotobuf generated ones API-wise, but use protozero under
# the hoods, without any zero-copy benefit though.
# They are mainly used for the perfetto IPC layer and tests.
template("protozero_cpp_library") {
  proto_library(target_name) {
    perfetto_root_path = invoker.perfetto_root_path

    generate_cc = false
    generate_python = false
    generator_plugin_label =
        perfetto_root_path + "src/protozero/protoc_plugin:cppgen_plugin"
    generator_plugin_suffix = ".gen"
    if (build_with_chromium) {
      component_build_force_source_set = true
    }

    deps = [
      "$perfetto_root_path/gn:default_deps",
      "$perfetto_root_path/include/perfetto/base",
    ]

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

    forward_variables_from(invoker,
                           [
                             "defines",
                             "generator_plugin_options",
                             "include_dirs",
                             "proto_in_dir",
                             "proto_out_dir",
                             "sources",
                             "testonly",
                             "visibility",
                             "generate_descriptor",
                           ])
  }
}

# The template used everywhere in the codebase.
template("perfetto_proto_library") {
  if (defined(invoker.proto_generators)) {
    proto_generators = invoker.proto_generators
  } else {
    proto_generators = [
      "zero",
      "lite",
      "cpp",
    ]
  }

  # proto imports and C++ #includes are relative to this path.
  if (defined(invoker.proto_path)) {
    proto_path = invoker.proto_path
  } else {
    proto_path = perfetto_root_path
  }

  vars_to_forward = [
    "sources",
    "visibility",
    "testonly",
  ]
  expansion_token = "@TYPE@"

  foreach(gen_type, proto_generators) {
    target_name_ = string_replace(target_name, expansion_token, gen_type)

    # Translate deps from xxx:@TYPE@ to xxx:lite/zero.
    deps_ = []
    if (defined(invoker.deps)) {
      foreach(dep, invoker.deps) {
        deps_ += [ string_replace(dep, expansion_token, gen_type) ]
      }
    }

    if (gen_type == "zero") {
      protozero_library(target_name_) {
        proto_in_dir = proto_path
        proto_out_dir = proto_path
        generator_plugin_options = "wrapper_namespace=pbzero"
        deps = deps_
        forward_variables_from(invoker, vars_to_forward)
      }
    } else if (gen_type == "cpp") {
      lite_target_name_ = string_replace(target_name, expansion_token, "lite")
      protozero_cpp_library(target_name_) {
        proto_in_dir = proto_path
        proto_out_dir = proto_path
        deps = deps_ + [ ":$lite_target_name_" ]
        forward_variables_from(invoker, vars_to_forward)
      }
    } else if (gen_type == "lite") {
      proto_library(target_name_) {
        proto_in_dir = proto_path
        proto_out_dir = proto_path
        generate_python = false
        deps = deps_
        forward_variables_from(invoker, vars_to_forward)
      }
    } else if (gen_type == "descriptor") {
      proto_library(target_name_) {
        proto_in_dir = proto_path
        proto_out_dir = proto_path
        generate_python = false
        generate_cc = false
        generate_descriptor = invoker.generate_descriptor
        deps = deps_
        forward_variables_from(invoker, vars_to_forward)
      }
    } else {
      assert(false, "Invalid 'proto_generators' value.")
    }
  }
}
