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