OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2015 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 closure_compiler_wrapper = "closure_compiler.py" | |
6 closure_compiler_path = "//third_party/closure_compiler/compiler/compiler.jar" | |
7 | |
8 # Defines a target that create a JavaScript bundle using the closure compiler. | |
9 # | |
10 # Variables | |
11 # sources: | |
12 # List of JavaScript files to compile into the bundle. | |
13 # | |
14 # closure_entry_point: | |
15 # Name of the entry point closure module. | |
16 # | |
17 # deps (optional) | |
18 # List of targets required by this target. | |
19 # | |
20 # visibility (optional) | |
21 # Visibility restrictions. | |
22 # | |
23 # Generates a single JavaScript bundle file that can be put in the application | |
24 # bundle. | |
25 # | |
26 # TODO(eugenebut): this should uses the same error flags as js_compile_checked. | |
27 template("js_compile_bundle") { | |
28 assert(defined(invoker.sources), | |
29 "Need sources in $target_name listing the js files.") | |
30 | |
31 assert(defined(invoker.closure_entry_point), | |
32 "Need closure_entry_point in $target_name for generated js file.") | |
33 | |
34 action(target_name) { | |
35 forward_variables_from(invoker, | |
36 [ | |
37 "deps", | |
38 "visibility", | |
39 ]) | |
40 | |
41 script = closure_compiler_wrapper | |
42 inputs = [ | |
43 closure_compiler_path, | |
44 ] | |
45 | |
46 outputs = [ | |
47 "$target_gen_dir/$target_name.js", | |
48 ] | |
49 sources = invoker.sources | |
50 | |
51 args = [ | |
52 rebase_path(closure_compiler_path, root_build_dir), | |
53 "--compilation_level", | |
54 "SIMPLE_OPTIMIZATIONS", | |
55 "--js", | |
56 ] + rebase_path(sources, root_build_dir) + [ "--js_output_file" ] + | |
57 rebase_path(outputs, root_build_dir) + | |
58 [ | |
59 "--only_closure_dependencies", | |
60 "--closure_entry_point", | |
61 invoker.closure_entry_point, | |
62 ] | |
63 | |
64 # TODO(sdefresne): add the generated bundle to the list of files to move | |
65 # in the application bundle, equivalent to the following gyp code: | |
66 # | |
67 # "link_settings": { | |
68 # "mac_bundle_resources": [ | |
69 # "<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_NAME).js", | |
70 # ], | |
71 # }, | |
72 } | |
73 } | |
74 | |
75 # Defines a target that compile JavaScript files with error checking using the | |
76 # closure compiler. | |
77 # | |
78 # Variables | |
79 # sources: | |
80 # List of JavaScript files to compile. | |
81 # | |
82 # compile (optional, defaults to true) | |
83 # If false or undefined, the JavaScript files will not be compiled but | |
Eugene But (OOO till 7-30)
2015/10/08 16:10:41
I don't think that this comment is accurate. if in
Dirk Pranke
2015/10/08 17:49:45
Why even have the 'copy' part of this template? Wh
sdefresne
2015/10/09 13:54:45
Removed the comment as I've changed the value to a
| |
84 # just copied to the destination. | |
85 # | |
86 # deps (optional) | |
87 # List of targets required by this target. | |
88 # | |
89 # visibility (optional) | |
90 # Visibility restrictions. | |
91 # | |
92 # TODO(eugenebut): use flags from third_party/closure_compiler/closure_args.gni | |
93 # once they are the same. | |
94 template("js_compile_checked") { | |
95 assert(defined(invoker.sources), | |
96 "Need sources in $target_name listing the js files.") | |
97 | |
98 if (defined(invoker.compile)) { | |
99 compile = invoker.compile | |
100 } else { | |
101 compile = true | |
102 } | |
103 | |
104 if (compile) { | |
105 action_foreach(target_name) { | |
106 forward_variables_from(invoker, | |
107 [ | |
108 "deps", | |
109 "visibility", | |
110 ]) | |
111 | |
112 script = closure_compiler_wrapper | |
113 inputs = [ | |
114 closure_compiler_path, | |
115 ] | |
116 | |
117 sources = invoker.sources | |
118 | |
119 outputs = [ | |
120 "$target_gen_dir/{{source_file_part}}", | |
121 ] | |
122 | |
123 # TODO(eugenebut): need to enable the following compilation checks once | |
124 # the corresponding errors have been fixed: | |
125 # --jscomp_error=checkTypes | |
126 # --jscomp_error=checkVars | |
127 # --jscomp_error=missingProperties | |
128 # --jscomp_error=missingReturn | |
129 # --jscomp_error=undefinedVars | |
130 | |
131 args = [ | |
132 rebase_path(closure_compiler_path, root_build_dir), | |
133 "--compilation_level", | |
134 "SIMPLE_OPTIMIZATIONS", | |
135 "--jscomp_error=accessControls", | |
136 "--jscomp_error=ambiguousFunctionDecl", | |
137 "--jscomp_error=constantProperty", | |
138 "--jscomp_error=deprecated", | |
139 "--jscomp_error=externsValidation", | |
140 "--jscomp_error=globalThis", | |
141 "--jscomp_error=invalidCasts", | |
142 "--jscomp_error=nonStandardJsDocs", | |
143 "--jscomp_error=suspiciousCode", | |
144 "--jscomp_error=undefinedNames", | |
145 "--jscomp_error=unknownDefines", | |
146 "--jscomp_error=uselessCode", | |
147 "--jscomp_error=visibility", | |
148 "--js", | |
149 "{{source}}", | |
150 "--js_output_file", | |
151 rebase_path("$target_gen_dir/{{source_file_part}}", root_build_dir), | |
152 ] | |
153 | |
154 # TODO(sdefresne): add the generated bundle to the list of files to move | |
155 # in the application bundle, equivalent to the following gyp code: | |
156 # | |
157 # "link_settings": { | |
158 # "mac_bundle_resources": [ | |
159 # "<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_NAME).js", | |
160 # ], | |
161 # }, | |
162 } | |
163 } else { | |
164 copy(target_name) { | |
165 forward_variables_from(invoker, | |
166 [ | |
167 "deps", | |
168 "visibility", | |
169 ]) | |
170 | |
171 sources = invoker.sources | |
172 outputs = [ | |
173 "$target_gen_dir/{{source_file_part}}", | |
174 ] | |
175 | |
176 # TODO(sdefresne): add the generated bundle to the list of files to move | |
177 # in the application bundle, equivalent to the following gyp code: | |
178 # | |
179 # "link_settings": { | |
180 # "mac_bundle_resources": [ | |
181 # "<(SHARED_INTERMEDIATE_DIR)/<(RULE_INPUT_NAME).js", | |
182 # ], | |
183 # }, | |
184 } | |
185 } | |
186 } | |
OLD | NEW |