| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 args += ["--create_source_map=%s" % (self._MAP_FILE_FORMAT % out_file)] | 260 args += ["--create_source_map=%s" % (self._MAP_FILE_FORMAT % out_file)] |
| 261 | 261 |
| 262 args_file_content = " %s" % " ".join(args) | 262 args_file_content = " %s" % " ".join(args) |
| 263 self._log_debug("Args: %s" % args_file_content.strip()) | 263 self._log_debug("Args: %s" % args_file_content.strip()) |
| 264 | 264 |
| 265 args_file = self._create_temp_file(args_file_content) | 265 args_file = self._create_temp_file(args_file_content) |
| 266 self._log_debug("Args file: %s" % args_file) | 266 self._log_debug("Args file: %s" % args_file) |
| 267 | 267 |
| 268 processed_runner_args = ["--%s" % arg for arg in runner_args or []] | 268 processed_runner_args = ["--%s" % arg for arg in runner_args or []] |
| 269 processed_runner_args += ["--compiler-args-file=%s" % args_file] | 269 processed_runner_args += ["--compiler-args-file=%s" % args_file] |
| 270 return_code, stderr = self._run_jar(self._runner_jar, processed_runner_args) | 270 _, stderr = self._run_jar(self._runner_jar, processed_runner_args) |
| 271 | 271 |
| 272 errors = stderr.strip().split("\n\n") | 272 errors = stderr.strip().split("\n\n") |
| 273 maybe_summary = errors.pop() | 273 maybe_summary = errors.pop() |
| 274 | 274 |
| 275 if return_code == 0: | 275 summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary) |
| 276 if summary: |
| 276 self._log_debug("Summary: %s" % maybe_summary) | 277 self._log_debug("Summary: %s" % maybe_summary) |
| 277 else: | 278 else: |
| 278 # Running the jar failed. Bail. | 279 # Not a summary. Running the jar failed. Bail. |
| 279 self._log_error(stderr) | 280 self._log_error(stderr) |
| 280 self._nuke_temp_files() | 281 self._nuke_temp_files() |
| 281 sys.exit(1) | 282 sys.exit(1) |
| 282 | 283 |
| 283 summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary) | |
| 284 if summary.group('error_count') != "0" and out_file: | 284 if summary.group('error_count') != "0" and out_file: |
| 285 if os.path.exists(out_file): | 285 if os.path.exists(out_file): |
| 286 os.remove(out_file) | 286 os.remove(out_file) |
| 287 if os.path.exists(self._MAP_FILE_FORMAT % out_file): | 287 if os.path.exists(self._MAP_FILE_FORMAT % out_file): |
| 288 os.remove(self._MAP_FILE_FORMAT % out_file) | 288 os.remove(self._MAP_FILE_FORMAT % out_file) |
| 289 | 289 |
| 290 if not custom_sources: | 290 if not custom_sources: |
| 291 filtered_errors = self._filter_errors(errors) | 291 filtered_errors = self._filter_errors(errors) |
| 292 errors = map(self._clean_up_error, filtered_errors) | 292 errors = map(self._clean_up_error, filtered_errors) |
| 293 output = self._format_errors(errors) | 293 output = self._format_errors(errors) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 323 | 323 |
| 324 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, | 324 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, |
| 325 closure_args=opts.closure_args, | 325 closure_args=opts.closure_args, |
| 326 runner_args=opts.runner_args, | 326 runner_args=opts.runner_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 |