summaryrefslogtreecommitdiff
path: root/chromium/mojo/public/js/BUILD.gn
blob: 47ee85363976de8a8db64a8275236943eacc250b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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("//mojo/public/tools/bindings/mojom.gni")
import("//third_party/closure_compiler/closure_args.gni")
import("//third_party/closure_compiler/compile_js.gni")
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 = "//mojo/public/tools/bindings/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" ]
}

bindings_lite_sources = [
  "bindings_lite.js",
  "interface_support.js",
]

bindings_lite_compiled_file = "$target_gen_dir/mojo_bindings_lite.js"

js_library("bindings_lite_sources") {
  sources = [ "compile_preamble.js" ] + bindings_lite_sources
  deps = [ "//mojo/public/interfaces/bindings:bindings_js_library_for_compile" ]
}

if (enable_mojom_closure_compile || enable_js_type_check) {
  js_binary("bindings_lite") {
    outputs = [ bindings_lite_compiled_file ]
    deps = [ ":bindings_lite_sources" ]
    externs_list = [
      "$externs_path/mojo_core.js",
      "$externs_path/pending.js",
    ]
    closure_flags = strict_error_checking_closure_args + [
                      "compilation_level=ADVANCED_OPTIMIZATIONS",
                      "language_in=ECMASCRIPT_2017",
                      "language_out=ECMASCRIPT_2015",
                      "generate_exports",
                      "export_local_property_definitions",
                      "isolation_mode=IIFE",
                    ]
  }
} else {
  action("bindings_lite") {
    all_sources = bindings_lite_sources + [ "$root_gen_dir/mojo/public/interfaces/bindings/interface_control_messages.mojom-lite.js" ]
    script = "//mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py"
    sources = all_sources
    outputs = [ bindings_lite_compiled_file ]
    args = rebase_path(all_sources, root_build_dir) +
           [ rebase_path(bindings_lite_compiled_file, root_build_dir) ]
    deps = [ "//mojo/public/interfaces/bindings:bindings_js__generator" ]
  }
}

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

  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",
    ":bindings_lite",
    "//mojo/public/mojom/base:base_js",
  ]
}

group("tests") {
  deps = [ "//mojo/public/js/test:compile_test" ]
}