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 |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..23809bc89a30a7c088e3e29c1a701e80135c20b7 |
| --- /dev/null |
| +++ b/mojo/public/tools/dart_analyze.py |
| @@ -0,0 +1,85 @@ |
| +#!/usr/bin/python |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +# To integrate dartanalyze with out build system, we take an input file, run |
| +# the analyzer on it, and write a stamp file if it passed. |
| +# |
| +# The first argument to this script is a reference to this build's gen |
| +# directory. The second is the stamp file to touch if we succeed. The rest are |
| +# passed to the analyzer verbatim. |
| +# |
| +# While it'd be nice to get a list of generated *.mojom.dart files from the gn |
| +# file, AFAICT, that's impossible because the targets are in different |
| +# files. Besides, this won't deal with dependencies correctly. So instead, we |
| +# search the entire gen directory for *.mojom.dart files, and add a url-mapping |
| +# for each found mojom.dart in our build. |
|
Elliot Glaysher
2015/02/24 22:41:53
I suspect that this is what is making it slow, but
zra
2015/02/24 23:04:39
Can you just pass main.dart to the analyzer? Does
Elliot Glaysher
2015/02/24 23:47:48
Using --package-root works.
However, it doesn't s
|
| + |
| +import os |
| +import subprocess |
| +import sys |
| +import re |
| + |
| +_ANALYZING_PATTERN = re.compile(r'^Analyzing \[') |
| +_FINAL_REPORT_PATTERN = re.compile(r'^[0-9]+ errors and [0-9]+ warnings found.') |
| + |
| +_NATIVE_ERROR_PATTERN = re.compile( |
| + r'^\[error\] Native functions can only be declared in the SDK and code that ' |
| + r'is loaded through native extensions') |
| +_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) |
| + gen_dir_len = len(gen_dir) + 1 |
| + stamp_file = args.pop(0) |
| + cmd.extend(args) |
| + |
| + # Recursively walk gen_dir looking for mojom files |
| + mojom_dart_files = [] |
| + for root, _, files in os.walk(gen_dir): |
| + for name in files: |
| + if name.endswith(".mojom.dart"): |
| + mojom_dart_files.append(os.path.join(root, name)) |
| + |
| + # For every file found, add the proper package mappings. |
| + for file_path in mojom_dart_files: |
| + dart_name = file_path[gen_dir_len:] |
| + cmd.append("--url-mapping=package:%s,%s" % (dart_name, file_path)) |
|
zra
2015/02/24 23:04:40
We should either: 1) use the --package-root flag,
|
| + |
| + 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 |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv[1:])) |