OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 JavaScript files to check for errors and produce | 6 """Runs Closure compiler on JavaScript files to check for errors and produce |
7 minified output.""" | 7 minified output.""" |
8 | 8 |
9 import argparse | 9 import argparse |
10 import os | 10 import os |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 externs = filter(is_extern, externs_and_deps) | 218 externs = filter(is_extern, externs_and_deps) |
219 deps = filter(lambda f: not is_extern(f), externs_and_deps) | 219 deps = filter(lambda f: not is_extern(f), externs_and_deps) |
220 | 220 |
221 assert externs or deps or self._target | 221 assert externs or deps or self._target |
222 | 222 |
223 self._log_debug("Externs: %s" % externs) | 223 self._log_debug("Externs: %s" % externs) |
224 self._log_debug("Dependencies: %s" % deps) | 224 self._log_debug("Dependencies: %s" % deps) |
225 self._log_debug("Target: %s" % self._target) | 225 self._log_debug("Target: %s" % self._target) |
226 | 226 |
227 js_args = deps + [self._target] if self._target else [] | 227 js_args = deps + ([self._target] if self._target else []) |
228 | 228 |
229 if not custom_sources: | 229 if not custom_sources: |
230 # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg | 230 # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg |
231 # and moves these files to a different AST tree. However, because we use | 231 # and moves these files to a different AST tree. However, because we use |
232 # one big funky <include> meta-file, it thinks all the code is one big | 232 # one big funky <include> meta-file, it thinks all the code is one big |
233 # externs. Just use --js when <include> dies. | 233 # externs. Just use --js when <include> dies. |
234 | 234 |
235 cwd, tmp_dir = os.getcwd(), tempfile.gettempdir() | 235 cwd, tmp_dir = os.getcwd(), tempfile.gettempdir() |
236 rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f) | 236 rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f) |
237 contents = ['<include src="%s">' % rel_path(f) for f in js_args] | 237 contents = ['<include src="%s">' % rel_path(f) for f in js_args] |
(...skipping 25 matching lines...) Expand all Loading... |
263 | 263 |
264 args_file = self._create_temp_file(args_file_content) | 264 args_file = self._create_temp_file(args_file_content) |
265 self._log_debug("Args file: %s" % args_file) | 265 self._log_debug("Args file: %s" % args_file) |
266 | 266 |
267 runner_args = ["--compiler-args-file=%s" % args_file] | 267 runner_args = ["--compiler-args-file=%s" % args_file] |
268 _, stderr = self._run_jar(self._runner_jar, runner_args) | 268 _, stderr = self._run_jar(self._runner_jar, runner_args) |
269 | 269 |
270 errors = stderr.strip().split("\n\n") | 270 errors = stderr.strip().split("\n\n") |
271 maybe_summary = errors.pop() | 271 maybe_summary = errors.pop() |
272 | 272 |
273 if re.search(".*error.*warning.*typed", maybe_summary): | 273 if re.search(".*error.*warning", maybe_summary): |
274 self._log_debug("Summary: %s" % maybe_summary) | 274 self._log_debug("Summary: %s" % maybe_summary) |
275 else: | 275 else: |
276 # Not a summary. Running the jar failed. Bail. | 276 # Not a summary. Running the jar failed. Bail. |
277 self._log_error(stderr) | 277 self._log_error(stderr) |
278 self._nuke_temp_files() | 278 self._nuke_temp_files() |
279 sys.exit(1) | 279 sys.exit(1) |
280 | 280 |
281 if errors and out_file: | 281 if errors and out_file: |
282 if os.path.exists(out_file): | 282 if os.path.exists(out_file): |
283 os.remove(out_file) | 283 os.remove(out_file) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 checker = Checker(verbose=opts.verbose) | 317 checker = Checker(verbose=opts.verbose) |
318 | 318 |
319 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, | 319 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, |
320 closure_args=opts.closure_args, | 320 closure_args=opts.closure_args, |
321 custom_sources=opts.custom_sources) | 321 custom_sources=opts.custom_sources) |
322 | 322 |
323 if found_errors: | 323 if found_errors: |
324 if opts.custom_sources: | 324 if opts.custom_sources: |
325 print stderr | 325 print stderr |
326 sys.exit(1) | 326 sys.exit(1) |
OLD | NEW |