# Copyright 2014 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("//tools/grit/grit_rule.gni")

interfaces_bindings_gen_dir = "$root_gen_dir/mojo/public/interfaces/bindings"

action("bindings") {
  bindings_js_files = [
    # This must be the first file in the list, because it initializes global
    # variable |mojo| that the others need to refer to.
    "base.js",

    "bindings.js",
    "interface_types.js",
    "lib/buffer.js",
    "lib/codec.js",
    "lib/connector.js",
    "lib/control_message_handler.js",
    "lib/control_message_proxy.js",
    "lib/interface_endpoint_client.js",
    "lib/interface_endpoint_handle.js",
    "lib/pipe_control_message_handler.js",
    "lib/pipe_control_message_proxy.js",
    "lib/router.js",
    "lib/unicode.js",
    "lib/validator.js",

    # These two needs to refer to codec.js.
    "$interfaces_bindings_gen_dir/interface_control_messages.mojom.js",
    "$interfaces_bindings_gen_dir/pipe_control_messages.mojom.js",
  ]
  compiled_file = "$target_gen_dir/mojo_bindings.js"

  # TODO(yzshen): Eventually we would like to use Closure Compiler to minify the
  # bindings instead of simply concatenating the files.
  script = "//v8/tools/concatenate-files.py"

  sources = bindings_js_files
  outputs = [
    compiled_file,
  ]

  args = rebase_path(bindings_js_files, root_build_dir)
  args += [ rebase_path(compiled_file, root_build_dir) ]

  deps = [
    "//mojo/public/interfaces/bindings:bindings_js__generator",
  ]
}

grit("resources") {
  source = "mojo_bindings_resources.grd"

  # The .grd contains references to generated files.
  source_is_generated = true

  outputs = [
    "grit/mojo_bindings_resources.h",
    "grit/mojo_bindings_resources_map.cc",
    "grit/mojo_bindings_resources_map.h",
    "mojo_bindings_resources.pak",
  ]
  grit_flags = [
    "-E",
    "root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
  ]
  deps = [
    ":bindings",
  ]
}