# Copyright 2021 The Chromium 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("./copy.gni")

template("devtools_pre_built") {
  _copy_to_gen_target_name = target_name + "-copy-gen-javascript"
  _copy_gen_target_dep = ":$_copy_to_gen_target_name"

  copy_to_gen(_copy_to_gen_target_name) {
    sources = invoker.sources

    deps = invoker.deps
  }

  _target_outputs = get_target_outputs(_copy_gen_target_dep)
  _javascript_implementation_files =
      invoker.data + filter_include(_target_outputs,
                                    [
                                      "*.js",
                                      "*.mjs",
                                    ])

  group(target_name) {
    public_deps = [ _copy_gen_target_dep ] + invoker.deps

    data = _javascript_implementation_files +
           filter_include(_target_outputs, [ "*.map" ])
    if (invoker.sources_are_release || is_debug) {
      metadata = {
        grd_files = _javascript_implementation_files
      }
    }
  }
}

set_defaults("devtools_pre_built") {
  deps = []
  data = []
  sources_are_release = true
}
