Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: mojo/public/tools/dart_analyze.py

Issue 996483003: Run dartanalyze on the dartzip file structure. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: most of tonyg's nits. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/dart/rules.gni ('k') | mojo/tools/mojob.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
16 import shutil
14 import subprocess 17 import subprocess
15 import sys 18 import sys
16 import re 19 import tempfile
20 import zipfile
17 21
18 _ANALYZING_PATTERN = re.compile(r'^Analyzing \[') 22 _ANALYZING_PATTERN = re.compile(r'^Analyzing \[')
19 _FINAL_REPORT_PATTERN = re.compile(r'^[0-9]+ errors and [0-9]+ warnings found.') 23 _FINAL_REPORT_PATTERN = re.compile(r'^[0-9]+ errors and [0-9]+ warnings found.')
20 24
21 _NATIVE_ERROR_PATTERN = re.compile( 25 _NATIVE_ERROR_PATTERN = re.compile(
22 r'^\[error\] Native functions can only be declared in the SDK and code that ' 26 r'^\[error\] Native functions can only be declared in the SDK and code that '
23 r'is loaded through native extensions') 27 r'is loaded through native extensions')
24 _WARNING_PATTERN = re.compile(r'^\[warning\]') 28 _WARNING_PATTERN = re.compile(r'^\[warning\]')
25 _THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN = re.compile( 29 _THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN = re.compile(
26 r'^\[error\] The name \'close\' is already defined') 30 r'^\[error\] The name \'close\' is already defined')
27 31
32
28 def main(args): 33 def main(args):
29 cmd = [ 34 dartzip_file = args.pop(0)
30 "../../third_party/dart-sdk/dart-sdk/bin/dartanalyzer", 35 stamp_file = args.pop(0)
31 ]
32 36
33 gen_dir = args.pop(0) 37 # Unzip |dartzip_file| to a temporary directory.
34 stamp_file = args.pop(0) 38 try:
35 cmd.extend(args) 39 temp_dir = tempfile.mkdtemp()
36 cmd.append("--package-root=%s" % gen_dir) 40 zipfile.ZipFile(dartzip_file).extractall(temp_dir)
37 41
38 passed = True 42 cmd = [
39 try: 43 "../../third_party/dart-sdk/dart-sdk/bin/dartanalyzer",
40 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT) 44 ]
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 45
58 if passed: 46 # 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. 47 dart_files = glob.glob(os.path.join(temp_dir, "*.dart"))
60 with open(stamp_file, 'a'): 48
61 os.utime(stamp_file, None) 49 cmd.extend(dart_files)
62 return 0 50 cmd.extend(args)
63 else: 51 cmd.append("--package-root=%s" % temp_dir)
64 return -2 52
53 passed = True
54 try:
55 subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT)
56 except subprocess.CalledProcessError as e:
57 # Perform post processing on the output. Filter out non-error messages and
58 # known problem patterns that we're working on.
59 raw_lines = e.output.split('\n')
60 # Remove the last empty line
61 raw_lines.pop()
62 filtered_lines = [i for i in raw_lines if (
63 not re.match(_ANALYZING_PATTERN, i) and
64 not re.match(_FINAL_REPORT_PATTERN, i) and
65 # TODO(erg): Remove the rest of these as fixes land:
66 not re.match(_WARNING_PATTERN, i) and
67 not re.match(_NATIVE_ERROR_PATTERN, i) and
68 not re.match(_THAT_ONE_BROKEN_CLOSE_IN_WEB_SOCKETS_PATTERN, i))]
69 for line in filtered_lines:
70 passed = False
71 print >> sys.stderr, line
72
73 if passed:
74 # We passed cleanly, so touch the stamp file so that we don't run again.
75 with open(stamp_file, 'a'):
76 os.utime(stamp_file, None)
77 return 0
78 else:
79 return -2
80 finally:
81 shutil.rmtree(temp_dir)
82
65 83
66 if __name__ == '__main__': 84 if __name__ == '__main__':
67 sys.exit(main(sys.argv[1:])) 85 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « mojo/public/dart/rules.gni ('k') | mojo/tools/mojob.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698