Chromium Code Reviews| 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 os | 14 import os |
| 15 import re | |
| 14 import subprocess | 16 import subprocess |
| 17 import shutil | |
|
tonyg
2015/03/09 21:44:21
nit: alphabetize
| |
| 15 import sys | 18 import sys |
| 16 import re | 19 import tempfile |
| 17 | 20 |
| 18 _ANALYZING_PATTERN = re.compile(r'^Analyzing \[') | 21 _ANALYZING_PATTERN = re.compile(r'^Analyzing \[') |
| 19 _FINAL_REPORT_PATTERN = re.compile(r'^[0-9]+ errors and [0-9]+ warnings found.') | 22 _FINAL_REPORT_PATTERN = re.compile(r'^[0-9]+ errors and [0-9]+ warnings found.') |
| 20 | 23 |
| 21 _NATIVE_ERROR_PATTERN = re.compile( | 24 _NATIVE_ERROR_PATTERN = re.compile( |
| 22 r'^\[error\] Native functions can only be declared in the SDK and code that ' | 25 r'^\[error\] Native functions can only be declared in the SDK and code that ' |
| 23 r'is loaded through native extensions') | 26 r'is loaded through native extensions') |
| 24 _WARNING_PATTERN = re.compile(r'^\[warning\]') | 27 _WARNING_PATTERN = re.compile(r'^\[warning\]') |
| 25 _THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN = re.compile( | 28 _THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN = re.compile( |
| 26 r'^\[error\] The name \'close\' is already defined') | 29 r'^\[error\] The name \'close\' is already defined') |
| 27 | 30 |
| 31 | |
| 28 def main(args): | 32 def main(args): |
| 29 cmd = [ | 33 dartzip_file = args.pop(0) |
|
tonyg
2015/03/09 21:44:21
This existed before your patch, but argparse.Argum
Elliot Glaysher
2015/03/09 22:18:48
I'm not entirely sure how to do this because they'
| |
| 30 "../../third_party/dart-sdk/dart-sdk/bin/dartanalyzer", | 34 stamp_file = args.pop(0) |
| 31 ] | |
| 32 | 35 |
| 33 gen_dir = args.pop(0) | 36 # Unzip |dartzip_file| to a temporary directory. |
| 34 stamp_file = args.pop(0) | 37 try: |
| 35 cmd.extend(args) | 38 temp_dir = tempfile.mkdtemp() |
| 36 cmd.append("--package-root=%s" % gen_dir) | 39 unzip_command = ['unzip', '-o', '-q', dartzip_file, '-d', temp_dir] |
|
tonyg
2015/03/09 21:44:21
Using python's zipfile package would make this cod
| |
| 40 if subprocess.call(unzip_command, shell=False) != 0: | |
| 41 print "Failed to unzip dart archive '%s' during analyze." % dartzip_file | |
| 42 return -2 | |
| 37 | 43 |
| 38 passed = True | 44 cmd = [ |
| 39 try: | 45 "../../third_party/dart-sdk/dart-sdk/bin/dartanalyzer", |
| 40 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) | 46 ] |
| 41 except subprocess.CalledProcessError as e: | |
| 42 # Perform post processing on the output. Filter out non-error messages and | |
| 43 # known problem patterns that we're working on. | |
| 44 raw_lines = e.output.split('\n') | |
| 45 # Remove the last empty line | |
| 46 raw_lines.pop() | |
| 47 filtered_lines = [i for i in raw_lines if ( | |
| 48 not re.match(_ANALYZING_PATTERN, i) and | |
| 49 not re.match(_FINAL_REPORT_PATTERN, i) and | |
| 50 # TODO(erg): Remove the rest of these as fixes land: | |
| 51 not re.match(_WARNING_PATTERN, i) and | |
| 52 not re.match(_NATIVE_ERROR_PATTERN, i) and | |
| 53 not re.match(_THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN, i))] | |
| 54 for line in filtered_lines: | |
| 55 passed = False | |
| 56 print >> sys.stderr, line | |
| 57 | 47 |
| 58 if passed: | 48 # Grab all the toplevel dart files in the archive. |
| 59 # We passed cleanly, so touch the stamp file so that we don't run again. | 49 dart_files = glob.glob(os.path.join(temp_dir, "*.dart")) |
| 60 with open(stamp_file, 'a'): | 50 |
| 61 os.utime(stamp_file, None) | 51 cmd.extend(dart_files) |
| 62 return 0 | 52 cmd.extend(args) |
| 63 else: | 53 cmd.append("--package-root=%s" % temp_dir) |
| 64 return -2 | 54 |
| 55 passed = True | |
| 56 try: | |
| 57 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) | |
| 58 except subprocess.CalledProcessError as e: | |
| 59 # Perform post processing on the output. Filter out non-error messages and | |
| 60 # known problem patterns that we're working on. | |
| 61 raw_lines = e.output.split('\n') | |
| 62 # Remove the last empty line | |
| 63 raw_lines.pop() | |
| 64 filtered_lines = [i for i in raw_lines if ( | |
| 65 not re.match(_ANALYZING_PATTERN, i) and | |
| 66 not re.match(_FINAL_REPORT_PATTERN, i) and | |
| 67 # 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) and | |
| 70 not re.match(_THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN, i))] | |
| 71 for line in filtered_lines: | |
| 72 passed = False | |
| 73 print >> sys.stderr, line | |
| 74 | |
| 75 if passed: | |
| 76 # We passed cleanly, so touch the stamp file so that we don't run again. | |
| 77 with open(stamp_file, 'a'): | |
| 78 os.utime(stamp_file, None) | |
| 79 return 0 | |
| 80 else: | |
| 81 return -2 | |
| 82 finally: | |
| 83 shutil.rmtree(temp_dir) | |
| 84 | |
| 65 | 85 |
| 66 if __name__ == '__main__': | 86 if __name__ == '__main__': |
| 67 sys.exit(main(sys.argv[1:])) | 87 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |