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 | 31 |
32 | 32 |
33 def main(args): | 33 def main(args): |
34 dartzip_file = args.pop(0) | 34 dartzip_file = args.pop(0) |
35 stamp_file = args.pop(0) | 35 stamp_file = args.pop(0) |
36 | 36 |
37 dartzip_basename = os.path.basename(dartzip_file) + ":" | 37 dartzip_basename = os.path.basename(dartzip_file) + ":" |
38 | 38 |
39 # Unzip |dartzip_file| to a temporary directory. | 39 # Unzip |dartzip_file| to a temporary directory. |
40 try: | 40 try: |
(...skipping 15 matching lines...) Expand all Loading... |
56 try: | 56 try: |
57 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) | 57 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) |
58 except subprocess.CalledProcessError as e: | 58 except subprocess.CalledProcessError as e: |
59 # Perform post processing on the output. Filter out non-error messages and | 59 # Perform post processing on the output. Filter out non-error messages and |
60 # known problem patterns that we're working on. | 60 # known problem patterns that we're working on. |
61 raw_lines = e.output.split('\n') | 61 raw_lines = e.output.split('\n') |
62 # Remove the last empty line | 62 # Remove the last empty line |
63 raw_lines.pop() | 63 raw_lines.pop() |
64 filtered_lines = [i for i in raw_lines if ( | 64 filtered_lines = [i for i in raw_lines if ( |
65 not re.match(_ANALYZING_PATTERN, i) and | 65 not re.match(_ANALYZING_PATTERN, i) and |
66 not re.match(_FINAL_REPORT_PATTERN, i) and | 66 not re.match(_ERRORS_AND_WARNINGS_PATTERN, i) and |
| 67 not re.match(_ERRORS_PATTERN, i) and |
| 68 not re.match(_WARNINGS_PATTERN, i) and |
67 # TODO(erg): Remove the rest of these as fixes land: | 69 # TODO(erg): Remove the rest of these as fixes land: |
68 not re.match(_WARNING_PATTERN, i) and | 70 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: | 71 for line in filtered_lines: |
72 passed = False | 72 passed = False |
73 print >> sys.stderr, line.replace(temp_dir + "/", dartzip_basename) | 73 print >> sys.stderr, line.replace(temp_dir + "/", dartzip_basename) |
74 | 74 |
75 if passed: | 75 if passed: |
76 # We passed cleanly, so touch the stamp file so that we don't run again. | 76 # We passed cleanly, so touch the stamp file so that we don't run again. |
77 with open(stamp_file, 'a'): | 77 with open(stamp_file, 'a'): |
78 os.utime(stamp_file, None) | 78 os.utime(stamp_file, None) |
79 return 0 | 79 return 0 |
80 else: | 80 else: |
81 return -2 | 81 return -2 |
82 finally: | 82 finally: |
83 shutil.rmtree(temp_dir) | 83 shutil.rmtree(temp_dir) |
84 | 84 |
85 | 85 |
86 if __name__ == '__main__': | 86 if __name__ == '__main__': |
87 sys.exit(main(sys.argv[1:])) | 87 sys.exit(main(sys.argv[1:])) |
OLD | NEW |