| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 print "(INFO) %s" % msg | 68 print "(INFO) %s" % msg |
| 69 | 69 |
| 70 def _log_error(self, msg): | 70 def _log_error(self, msg): |
| 71 """Logs |msg| to stderr regardless of --flags. | 71 """Logs |msg| to stderr regardless of --flags. |
| 72 | 72 |
| 73 Args: | 73 Args: |
| 74 msg: An error message to log. | 74 msg: An error message to log. |
| 75 """ | 75 """ |
| 76 print >> sys.stderr, "(ERROR) %s" % msg | 76 print >> sys.stderr, "(ERROR) %s" % msg |
| 77 | 77 |
| 78 def _run_jar(self, jar, args): | 78 def run_jar(self, jar, args): |
| 79 """Runs a .jar from the command line with arguments. | 79 """Runs a .jar from the command line with arguments. |
| 80 | 80 |
| 81 Args: | 81 Args: |
| 82 jar: A file path to a .jar file | 82 jar: A file path to a .jar file |
| 83 args: A list of command line arguments to be passed when running the .jar. | 83 args: A list of command line arguments to be passed when running the .jar. |
| 84 | 84 |
| 85 Return: | 85 Return: |
| 86 (exit_code, stderr) The exit code of the command (e.g. 0 for success) and | 86 (exit_code, stderr) The exit code of the command (e.g. 0 for success) and |
| 87 the stderr collected while running |jar| (as a string). | 87 the stderr collected while running |jar| (as a string). |
| 88 """ | 88 """ |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 os.makedirs(out_dir) | 257 os.makedirs(out_dir) |
| 258 | 258 |
| 259 checks_only = 'checks_only' in closure_args | 259 checks_only = 'checks_only' in closure_args |
| 260 | 260 |
| 261 if not checks_only: | 261 if not checks_only: |
| 262 args += ["--js_output_file=%s" % out_file] | 262 args += ["--js_output_file=%s" % out_file] |
| 263 args += ["--create_source_map=%s" % (self._MAP_FILE_FORMAT % out_file)] | 263 args += ["--create_source_map=%s" % (self._MAP_FILE_FORMAT % out_file)] |
| 264 | 264 |
| 265 self._log_debug("Args: %s" % " ".join(args)) | 265 self._log_debug("Args: %s" % " ".join(args)) |
| 266 | 266 |
| 267 _, stderr = self._run_jar(self._compiler_jar, args) | 267 _, stderr = self.run_jar(self._compiler_jar, args) |
| 268 | 268 |
| 269 errors = stderr.strip().split("\n\n") | 269 errors = stderr.strip().split("\n\n") |
| 270 maybe_summary = errors.pop() | 270 maybe_summary = errors.pop() |
| 271 | 271 |
| 272 summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary) | 272 summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary) |
| 273 if summary: | 273 if 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) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 checker = Checker(verbose=opts.verbose) | 323 checker = Checker(verbose=opts.verbose) |
| 324 | 324 |
| 325 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, | 325 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, |
| 326 closure_args=opts.closure_args, | 326 closure_args=opts.closure_args, |
| 327 custom_sources=opts.custom_sources) | 327 custom_sources=opts.custom_sources) |
| 328 | 328 |
| 329 if found_errors: | 329 if found_errors: |
| 330 if opts.custom_sources: | 330 if opts.custom_sources: |
| 331 print stderr | 331 print stderr |
| 332 sys.exit(1) | 332 sys.exit(1) |
| OLD | NEW |