# Copyright (C) 2022 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")

template("perfetto_tp_tables") {
  config_name = target_name + "_config"
  action_name = target_name
  relative_args = [
    "--relative-input-dir",
    rebase_path(perfetto_root_path, root_build_dir),
  ]

  config(config_name) {
    include_dirs = [ root_gen_dir ]
  }

  action(action_name) {
    sources = invoker.sources
    script = "${perfetto_root_path}/tools/gen_tp_table_headers.py"

    outputs = []
    foreach(table, invoker.sources) {
      outputs += [ "$target_gen_dir/" + string_replace(table, ".py", "_py.h") ]
    }

    deps = [ "$perfetto_root_path/python:trace_processor_table_generator" ]
    if (defined(invoker.deps)) {
      deps += invoker.deps
    }
    public_configs = [ ":$config_name" ]

    gen_args = [
      "--gen-dir",
      rebase_path("$root_gen_dir/$perfetto_root_path", root_build_dir),
    ]
    input_args = [ "--inputs" ] + rebase_path(invoker.sources, root_build_dir)
    args = gen_args + input_args + relative_args

    metadata = {
      perfetto_action_type_for_generator = [ "tp_tables" ]
    }
  }

  if (defined(invoker.generate_docs) && invoker.generate_docs &&
      perfetto_build_standalone) {
    docs_name = target_name + "_docs"
    action(docs_name) {
      sources = invoker.sources
      script = "$perfetto_root_path/tools/gen_tp_table_docs.py"
      deps = [ "$perfetto_root_path/python:trace_processor_table_generator" ]
      outputs = [ "$target_gen_dir/$docs_name.json" ]
      args = [ "--out" ] + rebase_path(outputs, root_build_dir) +
             rebase_path(invoker.sources, root_build_dir) + relative_args
    }
  }
}
