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 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 args += ["--%s" % arg for arg in closure_args] | 214 args += ["--%s" % arg for arg in closure_args] |
215 | 215 |
216 args_file_content = " %s" % " ".join(args) | 216 args_file_content = " %s" % " ".join(args) |
217 self._log_debug("Args: %s" % args_file_content.strip()) | 217 self._log_debug("Args: %s" % args_file_content.strip()) |
218 | 218 |
219 args_file = self._create_temp_file(args_file_content) | 219 args_file = self._create_temp_file(args_file_content) |
220 self._log_debug("Args file: %s" % args_file) | 220 self._log_debug("Args file: %s" % args_file) |
221 | 221 |
222 processed_runner_args = ["--%s" % arg for arg in runner_args or []] | 222 processed_runner_args = ["--%s" % arg for arg in runner_args or []] |
223 processed_runner_args += ["--compiler-args-file=%s" % args_file] | 223 processed_runner_args += ["--compiler-args-file=%s" % args_file] |
224 _, stderr = self._run_jar(self._runner_jar, processed_runner_args) | 224 return_code, stderr = self._run_jar(self._runner_jar, processed_runner_args) |
225 | 225 |
226 errors = stderr.strip().split("\n\n") | 226 errors = stderr.strip().split("\n\n") |
227 maybe_summary = errors.pop() | 227 maybe_summary = errors.pop() |
228 | 228 |
229 if re.search(".*error.*warning.*typed", maybe_summary): | 229 if return_code == 0: |
230 self._log_debug("Summary: %s" % maybe_summary) | 230 self._log_debug("Summary: %s" % maybe_summary) |
231 else: | 231 else: |
232 # Not a summary. Running the jar failed. Bail. | 232 # Running the jar failed. |
233 self._log_error(stderr) | 233 self._log_error(stderr) |
234 self._nuke_temp_files() | 234 self._nuke_temp_files() |
235 sys.exit(1) | |
236 | 235 |
237 if errors and out_file: | 236 if errors and out_file: |
238 if os.path.exists(out_file): | 237 if os.path.exists(out_file): |
239 os.remove(out_file) | 238 os.remove(out_file) |
240 if os.path.exists(self._MAP_FILE_FORMAT % out_file): | 239 if os.path.exists(self._MAP_FILE_FORMAT % out_file): |
241 os.remove(self._MAP_FILE_FORMAT % out_file) | 240 os.remove(self._MAP_FILE_FORMAT % out_file) |
242 | 241 |
243 return errors, stderr | 242 return errors, stderr |
244 | 243 |
245 def check(self, source_file, out_file=None, depends=None, externs=None, | 244 def check(self, source_file, out_file=None, depends=None, externs=None, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 else: | 370 else: |
372 found_errors, stderr = checker.check_multiple( | 371 found_errors, stderr = checker.check_multiple( |
373 sources, | 372 sources, |
374 out_file=opts.out_file, | 373 out_file=opts.out_file, |
375 externs=externs, | 374 externs=externs, |
376 runner_args=opts.runner_args, | 375 runner_args=opts.runner_args, |
377 closure_args=opts.closure_args) | 376 closure_args=opts.closure_args) |
378 if found_errors: | 377 if found_errors: |
379 print stderr | 378 print stderr |
380 sys.exit(1) | 379 sys.exit(1) |
OLD | NEW |