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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 self._runner_jar = os.path.join(_CURRENT_DIR, "runner", "runner.jar") | 46 self._runner_jar = os.path.join(_CURRENT_DIR, "runner", "runner.jar") |
47 self._target = None | 47 self._target = None |
48 self._temp_files = [] | 48 self._temp_files = [] |
49 self._verbose = verbose | 49 self._verbose = verbose |
50 self._error_filter = error_filter.PromiseErrorFilter() | 50 self._error_filter = error_filter.PromiseErrorFilter() |
51 | 51 |
52 def _nuke_temp_files(self): | 52 def _nuke_temp_files(self): |
53 """Deletes any temp files this class knows about.""" | 53 """Deletes any temp files this class knows about.""" |
54 if not self._temp_files: | 54 if not self._temp_files: |
55 return | 55 return |
56 | 56 return |
Dan Beam
2016/07/14 17:47:58
remove
| |
57 self._log_debug("Deleting temp files: %s" % ", ".join(self._temp_files)) | 57 self._log_debug("Deleting temp files: %s" % ", ".join(self._temp_files)) |
58 for f in self._temp_files: | 58 for f in self._temp_files: |
59 os.remove(f) | 59 os.remove(f) |
60 self._temp_files = [] | 60 self._temp_files = [] |
61 | 61 |
62 def _log_debug(self, msg, error=False): | 62 def _log_debug(self, msg, error=False): |
63 """Logs |msg| to stdout if --verbose/-v is passed when invoking this script. | 63 """Logs |msg| to stdout if --verbose/-v is passed when invoking this script. |
64 | 64 |
65 Args: | 65 Args: |
66 msg: A debug message to log. | 66 msg: A debug message to log. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |