# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("config/config.gni")

# TODO(akbiggs): Delete this, symbol-index no longer exists, it has been
# replaced with ffx debug symbol-index. I don't think this build rule is being
# used because it would be failing if it was, so it can probably be removed
# safely.
#
# Template for running the symbol-index tool for registering symbols with the symbolizer.
#
# Parameters
#   symbols - the build_id or ids.txt file to add to the index
#   build_dir - optional, the root of the build id used to resolve
#       relative source code paths found in the symbols.
#
# Forwarded parameters
#       testonly
#       deps
#       public_deps
#       visibility
template("fuchsia_symbol_index_tool") {
  forward_variables_from(invoker, [ "*" ])
  action(target_name) {
    forward_variables_from(invoker,
                           [
                             "testonly",
                             "deps",
                             "public_deps",
                             "visibility",
                           ])
    assert(defined(invoker.symbols), "symbols is required.")
    _symbol_file = invoker.symbols

    _build_root_dir = root_build_dir
    if (defined(invoker.build_root_dir)) {
      _build_root_dir = invoker.build_root_dir
    }

    _stamp_file = "$target_gen_dir/$target_name.symbol_index.stamp"
    outputs = [ _stamp_file ]

    # tool path
    _tool_path = "${fuchsia_tool_dir}/symbol-index"
    script = "//build/gn_run_binary.py"

    inputs = [
      # Depend on the SDK hash, to ensure rebuild if the SDK tools change.
      _symbol_file,
      _tool_path,
    ]
    args = [
      "--stamp",
      rebase_path(_stamp_file, root_build_dir),
      rebase_path(_tool_path, root_build_dir),
      "add",
      rebase_path(_symbol_file, root_build_dir),
      rebase_path(_build_root_dir, root_build_dir),
    ]
  }
}
