Chromium Code Reviews| Index: mojo/public/tools/dart_analyze.py |
| diff --git a/mojo/public/tools/dart_analyze.py b/mojo/public/tools/dart_analyze.py |
| index 8b8117e205cd0f6a282ba4102bd0ec0987fc8a91..179ec16aa127487ab4327931ee0a23f0772a1590 100755 |
| --- a/mojo/public/tools/dart_analyze.py |
| +++ b/mojo/public/tools/dart_analyze.py |
| @@ -10,10 +10,13 @@ |
| # directory, which we treat as the package root. The second is the stamp file |
| # to touch if we succeed. The rest are passed to the analyzer verbatim. |
| +import glob |
| import os |
| +import re |
| import subprocess |
| +import shutil |
|
tonyg
2015/03/09 21:44:21
nit: alphabetize
|
| import sys |
| -import re |
| +import tempfile |
| _ANALYZING_PATTERN = re.compile(r'^Analyzing \[') |
| _FINAL_REPORT_PATTERN = re.compile(r'^[0-9]+ errors and [0-9]+ warnings found.') |
| @@ -25,43 +28,60 @@ _WARNING_PATTERN = re.compile(r'^\[warning\]') |
| _THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN = re.compile( |
| r'^\[error\] The name \'close\' is already defined') |
| -def main(args): |
| - cmd = [ |
| - "../../third_party/dart-sdk/dart-sdk/bin/dartanalyzer", |
| - ] |
| - gen_dir = args.pop(0) |
| +def main(args): |
| + 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'
|
| stamp_file = args.pop(0) |
| - cmd.extend(args) |
| - cmd.append("--package-root=%s" % gen_dir) |
| - passed = True |
| + # Unzip |dartzip_file| to a temporary directory. |
| try: |
| - subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) |
| - except subprocess.CalledProcessError as e: |
| - # Perform post processing on the output. Filter out non-error messages and |
| - # known problem patterns that we're working on. |
| - raw_lines = e.output.split('\n') |
| - # Remove the last empty line |
| - raw_lines.pop() |
| - filtered_lines = [i for i in raw_lines if ( |
| - not re.match(_ANALYZING_PATTERN, i) and |
| - not re.match(_FINAL_REPORT_PATTERN, i) and |
| - # TODO(erg): Remove the rest of these as fixes land: |
| - not re.match(_WARNING_PATTERN, i) and |
| - not re.match(_NATIVE_ERROR_PATTERN, i) and |
| - not re.match(_THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN, i))] |
| - for line in filtered_lines: |
| - passed = False |
| - print >> sys.stderr, line |
| + temp_dir = tempfile.mkdtemp() |
| + 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
|
| + if subprocess.call(unzip_command, shell=False) != 0: |
| + print "Failed to unzip dart archive '%s' during analyze." % dartzip_file |
| + return -2 |
| + |
| + cmd = [ |
| + "../../third_party/dart-sdk/dart-sdk/bin/dartanalyzer", |
| + ] |
| + |
| + # Grab all the toplevel dart files in the archive. |
| + dart_files = glob.glob(os.path.join(temp_dir, "*.dart")) |
| + |
| + cmd.extend(dart_files) |
| + cmd.extend(args) |
| + cmd.append("--package-root=%s" % temp_dir) |
| + |
| + passed = True |
| + try: |
| + subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) |
| + except subprocess.CalledProcessError as e: |
| + # Perform post processing on the output. Filter out non-error messages and |
| + # known problem patterns that we're working on. |
| + raw_lines = e.output.split('\n') |
| + # Remove the last empty line |
| + raw_lines.pop() |
| + filtered_lines = [i for i in raw_lines if ( |
| + not re.match(_ANALYZING_PATTERN, i) and |
| + not re.match(_FINAL_REPORT_PATTERN, i) and |
| + # TODO(erg): Remove the rest of these as fixes land: |
| + not re.match(_WARNING_PATTERN, i) and |
| + not re.match(_NATIVE_ERROR_PATTERN, i) and |
| + not re.match(_THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN, i))] |
| + for line in filtered_lines: |
| + passed = False |
| + print >> sys.stderr, line |
| + |
| + if passed: |
| + # We passed cleanly, so touch the stamp file so that we don't run again. |
| + with open(stamp_file, 'a'): |
| + os.utime(stamp_file, None) |
| + return 0 |
| + else: |
| + return -2 |
| + finally: |
| + shutil.rmtree(temp_dir) |
| - if passed: |
| - # We passed cleanly, so touch the stamp file so that we don't run again. |
| - with open(stamp_file, 'a'): |
| - os.utime(stamp_file, None) |
| - return 0 |
| - else: |
| - return -2 |
| if __name__ == '__main__': |
| sys.exit(main(sys.argv[1:])) |