| 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 _FINAL_REPORT_PATTERN = re.compile(r'^[0-9]+ errors and [0-9]+ warnings found.') | 23 _ERRORS_AND_WARNINGS_PATTERN = re.compile( |
| 24 r'^[0-9]+ errors? and [0-9]+ warnings? found.') |
| 25 _ERRORS_PATTERN = re.compile(r'^[0-9]+ errors? found.') |
| 26 _WARNINGS_PATTERN = re.compile(r'^[0-9]+ warnings? found.') |
| 24 | 27 |
| 25 _NATIVE_ERROR_PATTERN = re.compile( | 28 _NATIVE_ERROR_PATTERN = re.compile( |
| 26 r'^\[error\] Native functions can only be declared in the SDK and code that ' | 29 r'^\[error\] Native functions can only be declared in the SDK and code that ' |
| 27 r'is loaded through native extensions') | 30 r'is loaded through native extensions') |
| 28 _WARNING_PATTERN = re.compile(r'^\[warning\]') | |
| 29 _THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN = re.compile( | |
| 30 r'^\[error\] The name \'close\' is already defined') | |
| 31 | |
| 32 | 31 |
| 33 def main(args): | 32 def main(args): |
| 34 dartzip_file = args.pop(0) | 33 dartzip_file = args.pop(0) |
| 35 stamp_file = args.pop(0) | 34 stamp_file = args.pop(0) |
| 36 | 35 |
| 37 dartzip_basename = os.path.basename(dartzip_file) + ":" | 36 dartzip_basename = os.path.basename(dartzip_file) + ":" |
| 38 | 37 |
| 39 # Unzip |dartzip_file| to a temporary directory. | 38 # Unzip |dartzip_file| to a temporary directory. |
| 40 try: | 39 try: |
| 41 temp_dir = tempfile.mkdtemp() | 40 temp_dir = tempfile.mkdtemp() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 try: | 55 try: |
| 57 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) | 56 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) |
| 58 except subprocess.CalledProcessError as e: | 57 except subprocess.CalledProcessError as e: |
| 59 # 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 |
| 60 # known problem patterns that we're working on. | 59 # known problem patterns that we're working on. |
| 61 raw_lines = e.output.split('\n') | 60 raw_lines = e.output.split('\n') |
| 62 # Remove the last empty line | 61 # Remove the last empty line |
| 63 raw_lines.pop() | 62 raw_lines.pop() |
| 64 filtered_lines = [i for i in raw_lines if ( | 63 filtered_lines = [i for i in raw_lines if ( |
| 65 not re.match(_ANALYZING_PATTERN, i) and | 64 not re.match(_ANALYZING_PATTERN, i) and |
| 66 not re.match(_FINAL_REPORT_PATTERN, i) and | 65 not re.match(_ERRORS_AND_WARNINGS_PATTERN, i) and |
| 66 not re.match(_ERRORS_PATTERN, i) and |
| 67 not re.match(_WARNINGS_PATTERN, i) and |
| 67 # TODO(erg): Remove the rest of these as fixes land: | 68 # TODO(erg): Remove the rest of these as fixes land: |
| 68 not re.match(_WARNING_PATTERN, i) and | 69 not re.match(_NATIVE_ERROR_PATTERN, i))] |
| 69 not re.match(_NATIVE_ERROR_PATTERN, i) and | |
| 70 not re.match(_THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN, i))] | |
| 71 for line in filtered_lines: | 70 for line in filtered_lines: |
| 72 passed = False | 71 passed = False |
| 73 print >> sys.stderr, line.replace(temp_dir + "/", dartzip_basename) | 72 print >> sys.stderr, line.replace(temp_dir + "/", dartzip_basename) |
| 74 | 73 |
| 75 if passed: | 74 if passed: |
| 76 # We passed cleanly, so touch the stamp file so that we don't run again. | 75 # We passed cleanly, so touch the stamp file so that we don't run again. |
| 77 with open(stamp_file, 'a'): | 76 with open(stamp_file, 'a'): |
| 78 os.utime(stamp_file, None) | 77 os.utime(stamp_file, None) |
| 79 return 0 | 78 return 0 |
| 80 else: | 79 else: |
| 81 return -2 | 80 return -2 |
| 82 finally: | 81 finally: |
| 83 shutil.rmtree(temp_dir) | 82 shutil.rmtree(temp_dir) |
| 84 | 83 |
| 85 | 84 |
| 86 if __name__ == '__main__': | 85 if __name__ == '__main__': |
| 87 sys.exit(main(sys.argv[1:])) | 86 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |