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

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: update comments 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
« no previous file with comments | « third_party/closure_compiler/compile2.py ('k') | third_party/closure_compiler/js_binary.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = [
42 output_file,
43 ]
44 args = [ "--output" ] + [ rebase_path(output_file, root_build_dir) ]
45 if (defined(sources)) {
46 args += [ "--sources" ] + rebase_path(sources, root_build_dir)
47 }
48 if (defined(deps)) {
49 args += [ "--deps" ]
50 foreach(dep, deps) {
51 # Get the output path for each dep
52 dep_gen_dir = get_label_info(dep, "target_gen_dir")
53 dep_name = get_label_info(dep, "name")
54 dep_output_path = "$dep_gen_dir/$dep_name.js_library"
55 args += [ rebase_path(dep_output_path, root_build_dir) ]
56 }
57 }
58 }
59 }
60
61 # Defines a target that compiles javascript files using the Closure compiler.
62 # This will produce a minified javascript output file. Additional checks and
63 # optimizations can be configured using the closure_flags attribute.
64 #
65 # Variables:
66 # sources:
67 # List of .js files to compile
68 #
69 # deps:
70 # List of js_library rules to depend on
71 #
72 # outputs:
73 # A file to write the compiled .js to.
74 # Only takes in a single file, but must be placed in a list
75 #
76 # bootstrap_file:
77 # A .js files to include before all others
78 #
79 # config_files:
80 # A list of .js files to include after the bootstrap_file but before all
81 # others
82 #
83 # closure_flags:
84 # A list of custom flags to pass to the Closure compiler. Do not include
85 # the leading dashes
86 #
87 # externs_list:
88 # A list of .js files to pass to the compiler as externs
89 #
90 # Example:
91 # js_binary("tree") {
92 # sources = ["tree_main.js"]
93 # deps = [":apple_tree"]
94 # outputs = [ "$target_gen_dir/tree.js" ]
95 # bootstrap_file = "bootstrap.js"
96 # config_files = [
97 # "config1.js",
98 # "config2.js",
99 # ]
100 # closure_flags = ["jscomp_error=undefinedVars"]
101 # externs_list = [ "externs.js" ]
102 # }
103
104 template("js_binary") {
105 assert(defined(invoker.sources) || defined(invoker.deps),
106 "Need sources or deps in $target_name for js_binary")
107 assert(defined(invoker.outputs), "Need outputs in $target_name for js_binary")
108
109 action(target_name) {
110 script = "$script_path/js_binary.py"
111 forward_variables_from(invoker,
112 [
113 "sources",
114 "deps",
115 "outputs",
116 "bootstrap_file",
117 "config_files",
118 "closure_flags",
119 "externs_list",
120 ])
121 args = [
122 "--compiler",
123 rebase_path(compiler_path, root_build_dir),
124 ]
125 args += [ "--output" ] + rebase_path(outputs, root_build_dir)
126 if (defined(sources)) {
127 args += [ "--sources" ] + rebase_path(sources, root_build_dir)
128 } else {
129 sources = []
130 }
131 if (defined(deps)) {
132 args += [ "--deps" ]
133 foreach(dep, deps) {
134 # Get the output path for each dep
135 dep_gen_dir = get_label_info(dep, "target_gen_dir")
136 dep_name = get_label_info(dep, "name")
137 dep_output_path = "$dep_gen_dir/$dep_name.js_library"
138 args += [ rebase_path(dep_output_path, root_build_dir) ]
139 }
140 }
141 if (defined(bootstrap_file)) {
142 args += [
143 "--bootstrap",
144 rebase_path(bootstrap_file, root_build_dir),
145 ]
146 sources += [ bootstrap_file ]
147 }
148 if (defined(config_files)) {
149 args += [ "--config" ] + rebase_path(config_files, root_build_dir)
150 sources += config_files
151 }
152
153 # |minifying_closure_args| from
154 # //third_party/closure_compiler/closure_args.gni
155 args += [ "--flags" ] + minifying_closure_args
156 if (defined(closure_flags)) {
157 args += closure_flags
158 }
159 if (defined(externs_list)) {
160 args += [ "--externs" ]
161 args += rebase_path(externs_list, root_build_dir)
162 sources += externs_list
163 }
164 }
165 }
OLDNEW
« no previous file with comments | « third_party/closure_compiler/compile2.py ('k') | third_party/closure_compiler/js_binary.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698