OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Runs Closure compiler on a JavaScript file to check for errors.""" | 6 """Runs Closure compiler on a JavaScript file to check for errors.""" |
7 | 7 |
8 import argparse | 8 import argparse |
9 import os | 9 import os |
10 import re | 10 import re |
11 import subprocess | 11 import subprocess |
12 import sys | 12 import sys |
13 import tempfile | 13 import tempfile |
| 14 |
| 15 import build.inputs |
14 import processor | 16 import processor |
15 | 17 |
16 | 18 |
17 class Checker(object): | 19 class Checker(object): |
18 """Runs the Closure compiler on a given source file and returns the | 20 """Runs the Closure compiler on a given source file and returns the |
19 success/errors.""" | 21 success/errors.""" |
20 | 22 |
21 _COMMON_CLOSURE_ARGS = [ | 23 _COMMON_CLOSURE_ARGS = [ |
22 "--accept_const_keyword", | 24 "--accept_const_keyword", |
23 "--jscomp_error=accessControls", | 25 "--jscomp_error=accessControls", |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 source_file: A file to check. | 163 source_file: A file to check. |
162 depends: Other files that would be included with a <script> earlier in | 164 depends: Other files that would be included with a <script> earlier in |
163 the page. | 165 the page. |
164 externs: @extern files that inform the compiler about custom globals. | 166 externs: @extern files that inform the compiler about custom globals. |
165 | 167 |
166 Returns: | 168 Returns: |
167 (exitcode, output) The exit code of the Closure compiler (as a number) | 169 (exitcode, output) The exit code of the Closure compiler (as a number) |
168 and its output (as a string). | 170 and its output (as a string). |
169 """ | 171 """ |
170 depends = depends or [] | 172 depends = depends or [] |
171 externs = externs or [] | 173 externs = externs or set() |
172 | 174 |
173 if not self._check_java_path(): | 175 if not self._check_java_path(): |
174 return 1, "" | 176 return 1, "" |
175 | 177 |
176 self._debug("FILE: %s" % source_file) | 178 self._debug("FILE: %s" % source_file) |
177 | 179 |
178 if source_file.endswith("_externs.js"): | 180 if source_file.endswith("_externs.js"): |
179 self._debug("Skipping externs: %s" % source_file) | 181 self._debug("Skipping externs: %s" % source_file) |
180 return | 182 return |
181 | 183 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 help="Path to a source file to typecheck") | 228 help="Path to a source file to typecheck") |
227 parser.add_argument("-d", "--depends", nargs=argparse.ZERO_OR_MORE) | 229 parser.add_argument("-d", "--depends", nargs=argparse.ZERO_OR_MORE) |
228 parser.add_argument("-e", "--externs", nargs=argparse.ZERO_OR_MORE) | 230 parser.add_argument("-e", "--externs", nargs=argparse.ZERO_OR_MORE) |
229 parser.add_argument("-o", "--out_file", help="A place to output results") | 231 parser.add_argument("-o", "--out_file", help="A place to output results") |
230 parser.add_argument("-v", "--verbose", action="store_true", | 232 parser.add_argument("-v", "--verbose", action="store_true", |
231 help="Show more information as this script runs") | 233 help="Show more information as this script runs") |
232 opts = parser.parse_args() | 234 opts = parser.parse_args() |
233 | 235 |
234 checker = Checker(verbose=opts.verbose) | 236 checker = Checker(verbose=opts.verbose) |
235 for source in opts.sources: | 237 for source in opts.sources: |
236 exit, _ = checker.check(source, depends=opts.depends, externs=opts.externs) | 238 depends, externs = build.inputs.resolve_recursive_dependencies( |
| 239 source, |
| 240 opts.depends, |
| 241 opts.externs) |
| 242 exit, _ = checker.check(source, depends=depends, externs=externs) |
237 if exit != 0: | 243 if exit != 0: |
238 sys.exit(exit) | 244 sys.exit(exit) |
239 | 245 |
240 if opts.out_file: | 246 if opts.out_file: |
241 out_dir = os.path.dirname(opts.out_file) | 247 out_dir = os.path.dirname(opts.out_file) |
242 if not os.path.exists(out_dir): | 248 if not os.path.exists(out_dir): |
243 os.makedirs(out_dir) | 249 os.makedirs(out_dir) |
244 # TODO(dbeam): write compiled file to |opts.out_file|. | 250 # TODO(dbeam): write compiled file to |opts.out_file|. |
245 open(opts.out_file, "w").write("") | 251 open(opts.out_file, "w").write("") |
OLD | NEW |