Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: third_party/closure_compiler/compile_js.gni

Issue 2800833004: Create js_library and js_binary templates for closure compiling. (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import("//third_party/closure_compiler/closure_args.gni")
6
7 script_path = "//third_party/closure_compiler"
8 compiler_path = "$script_path/compiler/compiler.jar"
9
10 # Defines a target that creates an ordering for .js files to be used by
11 # js_binary to compile.
12 #
13 # Variables:
14 # sources:
15 # List of Javascript files to include in the library
16 #
17 # deps:
18 # List of js_library targets to depend on
19 #
20 # Example:
21 # js_library("apple_tree") {
22 # sources = ["tree_main.js"]
23 # deps = [
24 # ":branch",
25 # ":trunk",
26 # ":root",
27 # ]
28 # }
29
30 template("js_library") {
31 assert(defined(invoker.sources) || defined(invoker.deps),
32 "Need sources or deps in $target_name for js_library")
33 action(target_name) {
34 script = "$script_path/js_library.py"
35 forward_variables_from(invoker,
36 [
37 "sources",
38 "deps",
39 ])
40 output_file = "$target_gen_dir/$target_name.js_library"
41 outputs = [ output_file ]
42 args = [ "--output" ] + [ rebase_path(output_file, root_build_dir) ]
43 if (defined(sources)) {
44 args += [ "--sources" ] + rebase_path(sources, root_build_dir)
45 }
46 if (defined(deps)) {
47 args += [ "--deps" ]
48 foreach(dep, deps) {
49 # Get the output path for each dep
50 dep_gen_dir = get_label_info(dep, "target_gen_dir")
51 dep_name = get_label_info(dep, "name")
52 dep_output_path = "$dep_gen_dir/$dep_name.js_library"
53 args += [ rebase_path(dep_output_path, root_build_dir) ]
54 }
55 }
56 }
57 }
58
59 # Defines a target that compiles javascript files using the closure compiler.
60 # This will produce a minified and optimized javascript output file, and will
61 # peform error, syntax, and type checking. Additional checks and options
62 # can be configured using the defs attribute.
63 #
64 # Variables:
65 # sources:
66 # List of .js files to compile
67 #
68 # deps:
69 # List of js_library rules to depend on
70 #
71 # outputs:
72 # A file to write the compiled .js to.
73 # Only takes in a single file, but should be placed in a list
mbjorge 2017/04/10 20:07:59 must be
74 #
75 # bootstrap_file:
76 # A .js files to include before all others
77 #
78 # config_files:
79 # A list of .js files to include after the bootstrap_file but before all
80 # others
81 #
82 # defs:
83 # A list of custom flags to pass to the closure compiler. Do not include
84 # the leading dashes
85 #
86 # externs_list:
87 # A list of .js files to pass to the compiler as externs
88 #
89 # Example:
90 # js_binary("tree") {
91 # sources = ["tree_main.js"]
92 # deps = [":apple_tree"]
93 # outputs = [ "$target_gen_dir/tree.js" ]
94 # bootstrap_file = "bootstrap.js"
95 # config_files = [
96 # "config1.js",
97 # "config2.js",
98 # ]
99 # defs = ["jscomp_error=undefinedVars"]
100 # externs_list = [ "externs.js" ]
101 # }
102
103 template("js_binary") {
104 assert(defined(invoker.sources) || defined(invoker.deps),
105 "Need sources or deps in $target_name for js_binary")
106 assert(defined(invoker.outputs), "Need outputs in $target_name for js_binary")
107
108 action(target_name) {
109 script = "$script_path/js_binary.py"
110 forward_variables_from(invoker, "*")
111 args = [
112 "--compiler",
113 rebase_path(compiler_path, root_build_dir),
114 ]
115 args += [ "--output" ] + rebase_path(outputs, root_build_dir)
116 if (defined(sources)) {
117 args += [ "--sources" ] + rebase_path(sources, root_build_dir)
118 }
119 if (defined(deps)) {
120 args += [ "--deps" ]
121 foreach(dep, deps) {
122 # Get the output path for each dep
123 dep_gen_dir = get_label_info(dep, "target_gen_dir")
124 dep_name = get_label_info(dep, "name")
125 dep_output_path = "$dep_gen_dir/$dep_name.js_library"
126 args += [ rebase_path(dep_output_path, root_build_dir) ]
127 }
128 }
129 if (defined(bootstrap_file)) {
130 args += [
131 "--bootstrap",
132 rebase_path(bootstrap_file, root_build_dir),
133 ]
134 }
135 if (defined(config_files)) {
136 args += [ "--config" ] + rebase_path(config_files, root_build_dir)
137 }
138 # |default_closure_args| from //third_party/closure_compiler/closure_args.gn i
139 args += [ "--defs" ] + default_closure_args
140 if (defined(defs)) {
141 args += defs
142 }
143 args +=
144 [ "--externs" ] +
145 [ rebase_path("$script_path/externs/polymer-1.0.js", root_build_dir) ]
146 if (defined(externs_list)) {
147 args += rebase_path(externs_list, root_build_dir)
148 }
149 }
150 }
OLDNEW
« no previous file with comments | « no previous file | third_party/closure_compiler/js_binary.py » ('j') | third_party/closure_compiler/js_library.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698