| 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 _ANALYZING_PATTERN = re.compile(r'^Analyzing \[') |
| 23 _NO_ISSUES_FOUND_PATTERN = re.compile(r'^No issues found') |
| 24 _PART_WARNINGS_PATTERN = re.compile( |
| 25 r'.*is a part and can not|^Only libraries can be analyzed') |
| 23 _ERRORS_AND_WARNINGS_PATTERN = re.compile( | 26 _ERRORS_AND_WARNINGS_PATTERN = re.compile( |
| 24 r'^[0-9]+ errors? and [0-9]+ warnings? found.') | 27 r'^[0-9]+ errors? and [0-9]+ warnings? found.') |
| 25 _ERRORS_PATTERN = re.compile(r'^([0-9]+|No) (error|warning|issue)s? found.') | 28 _ERRORS_PATTERN = re.compile(r'^([0-9]+|No) (error|warning|issue)s? found.') |
| 26 | 29 |
| 27 | 30 |
| 28 def main(args): | 31 def main(args): |
| 29 dartzip_file = args.pop(0) | 32 dartzip_file = args.pop(0) |
| 30 stamp_file = args.pop(0) | 33 stamp_file = args.pop(0) |
| 31 | 34 |
| 32 dartzip_basename = os.path.basename(dartzip_file) + ":" | 35 dartzip_basename = os.path.basename(dartzip_file) + ":" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 try: | 55 try: |
| 53 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) | 56 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) |
| 54 except subprocess.CalledProcessError as e: | 57 except subprocess.CalledProcessError as e: |
| 55 # Perform post processing on the output. Filter out non-error messages and | 58 # Perform post processing on the output. Filter out non-error messages and |
| 56 # known problem patterns that we're working on. | 59 # known problem patterns that we're working on. |
| 57 raw_lines = e.output.split('\n') | 60 raw_lines = e.output.split('\n') |
| 58 # Remove the last empty line | 61 # Remove the last empty line |
| 59 raw_lines.pop() | 62 raw_lines.pop() |
| 60 filtered_lines = [i for i in raw_lines if ( | 63 filtered_lines = [i for i in raw_lines if ( |
| 61 not re.match(_ANALYZING_PATTERN, i) and | 64 not re.match(_ANALYZING_PATTERN, i) and |
| 65 not re.match(_NO_ISSUES_FOUND_PATTERN, i) and |
| 66 not re.match(_PART_WARNINGS_PATTERN, i) and |
| 62 not re.match(_ERRORS_AND_WARNINGS_PATTERN, i) and | 67 not re.match(_ERRORS_AND_WARNINGS_PATTERN, i) and |
| 63 not re.match(_ERRORS_PATTERN, i))] | 68 not re.match(_ERRORS_PATTERN, i))] |
| 64 for line in filtered_lines: | 69 for line in filtered_lines: |
| 65 passed = False | 70 passed = False |
| 66 print >> sys.stderr, line.replace(temp_dir + "/", dartzip_basename) | 71 print >> sys.stderr, line.replace(temp_dir + "/", dartzip_basename) |
| 67 | 72 |
| 68 if passed: | 73 if passed: |
| 69 # We passed cleanly, so touch the stamp file so that we don't run again. | 74 # We passed cleanly, so touch the stamp file so that we don't run again. |
| 70 with open(stamp_file, 'a'): | 75 with open(stamp_file, 'a'): |
| 71 os.utime(stamp_file, None) | 76 os.utime(stamp_file, None) |
| 72 return 0 | 77 return 0 |
| 73 else: | 78 else: |
| 74 return -2 | 79 return -2 |
| 75 finally: | 80 finally: |
| 76 shutil.rmtree(temp_dir) | 81 shutil.rmtree(temp_dir) |
| 77 | 82 |
| 78 | 83 |
| 79 if __name__ == '__main__': | 84 if __name__ == '__main__': |
| 80 sys.exit(main(sys.argv[1:])) | 85 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |