| 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 # To integrate dartanalyze with out build system, we take an input file, run | 6 # To integrate dartanalyze with out build system, we take an input file, run |
| 7 # the analyzer on it, and write a stamp file if it passed. | 7 # the analyzer on it, and write a stamp file if it passed. |
| 8 # | 8 # |
| 9 # The first argument to this script is a reference to this build's gen | 9 # The first argument to this script is a reference to this build's gen |
| 10 # directory, which we treat as the package root. The second is the stamp file | 10 # directory, which we treat as the package root. The second is the stamp file |
| 11 # to touch if we succeed. The rest are passed to the analyzer verbatim. | 11 # to touch if we succeed. The rest are passed to the analyzer verbatim. |
| 12 | 12 |
| 13 import glob | 13 import glob |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import shutil | 16 import shutil |
| 17 import subprocess | 17 import subprocess |
| 18 import sys | 18 import sys |
| 19 import tempfile | 19 import tempfile |
| 20 import zipfile | 20 import zipfile |
| 21 | 21 |
| 22 _ANALYZING_PATTERN = re.compile(r'^Analyzing \[') | 22 _IGNORED_PATTERNS = [ |
| 23 _NO_ISSUES_FOUND_PATTERN = re.compile(r'^No issues found') | 23 # Ignored because they're not indicative of specific errors. |
| 24 _PART_WARNINGS_PATTERN = re.compile( | 24 re.compile(r'^$'), |
| 25 r'.*is a part and can not|^Only libraries can be analyzed') | 25 re.compile(r'^Analyzing \['), |
| 26 _ERRORS_AND_WARNINGS_PATTERN = re.compile( | 26 re.compile(r'^No issues found'), |
| 27 r'^[0-9]+ errors? and [0-9]+ warnings? found.') | 27 re.compile(r'^[0-9]+ errors? and [0-9]+ warnings? found.'), |
| 28 _ERRORS_PATTERN = re.compile(r'^([0-9]+|No) (error|warning|issue)s? found.') | 28 re.compile(r'^([0-9]+|No) (error|warning|issue)s? found.'), |
| 29 |
| 30 # TODO: It seems like this should be re-enabled evenutally. |
| 31 re.compile(r'.*is a part and can not|^Only libraries can be analyzed'), |
| 32 ] |
| 29 | 33 |
| 30 def _success(stamp_file): | 34 def _success(stamp_file): |
| 31 # We passed cleanly, so touch the stamp file so that we don't run again. | 35 # We passed cleanly, so touch the stamp file so that we don't run again. |
| 32 with open(stamp_file, 'a'): | 36 with open(stamp_file, 'a'): |
| 33 os.utime(stamp_file, None) | 37 os.utime(stamp_file, None) |
| 34 return 0 | 38 return 0 |
| 35 | 39 |
| 36 def main(args): | 40 def main(args): |
| 37 dartzip_file = args.pop(0) | 41 dartzip_file = args.pop(0) |
| 38 stamp_file = args.pop(0) | 42 stamp_file = args.pop(0) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 56 dart_files = glob.glob(os.path.join(temp_dir, "*.dart")) | 60 dart_files = glob.glob(os.path.join(temp_dir, "*.dart")) |
| 57 | 61 |
| 58 if not dart_files: | 62 if not dart_files: |
| 59 return _success(stamp_file) | 63 return _success(stamp_file) |
| 60 | 64 |
| 61 cmd.extend(dart_files) | 65 cmd.extend(dart_files) |
| 62 cmd.extend(args) | 66 cmd.extend(args) |
| 63 cmd.append("--package-root=%s" % temp_dir) | 67 cmd.append("--package-root=%s" % temp_dir) |
| 64 cmd.append("--fatal-warnings") | 68 cmd.append("--fatal-warnings") |
| 65 | 69 |
| 66 passed = True | 70 errors = 0 |
| 67 try: | 71 try: |
| 68 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) | 72 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) |
| 69 except subprocess.CalledProcessError as e: | 73 except subprocess.CalledProcessError as e: |
| 70 # Perform post processing on the output. Filter out non-error messages and | 74 errors = set(l for l in e.output.split('\n') |
| 71 # known problem patterns that we're working on. | 75 if not any(p.match(l) for p in _IGNORED_PATTERNS)) |
| 72 raw_lines = e.output.split('\n') | 76 for error in sorted(errors): |
| 73 # Remove the last empty line | 77 print >> sys.stderr, error.replace(temp_dir + "/", dartzip_basename) |
| 74 raw_lines.pop() | |
| 75 filtered_lines = [i for i in raw_lines if ( | |
| 76 not re.match(_ANALYZING_PATTERN, i) and | |
| 77 not re.match(_NO_ISSUES_FOUND_PATTERN, i) and | |
| 78 not re.match(_PART_WARNINGS_PATTERN, i) and | |
| 79 not re.match(_ERRORS_AND_WARNINGS_PATTERN, i) and | |
| 80 not re.match(_ERRORS_PATTERN, i))] | |
| 81 for line in filtered_lines: | |
| 82 passed = False | |
| 83 print >> sys.stderr, line.replace(temp_dir + "/", dartzip_basename) | |
| 84 | 78 |
| 85 if passed: | 79 if not errors: |
| 86 return _success(stamp_file) | 80 return _success(stamp_file) |
| 87 else: | 81 return min(255, len(errors)) |
| 88 return -2 | |
| 89 finally: | 82 finally: |
| 90 shutil.rmtree(temp_dir) | 83 shutil.rmtree(temp_dir) |
| 91 | 84 |
| 92 if __name__ == '__main__': | 85 if __name__ == '__main__': |
| 93 sys.exit(main(sys.argv[1:])) | 86 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |