OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import argparse |
| 7 import os |
| 8 import re |
| 9 import subprocess |
| 10 import sys |
| 11 |
| 12 SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 13 SKY_ROOT = os.path.dirname(SKY_TOOLS_DIR) |
| 14 SRC_ROOT = os.path.dirname(SKY_ROOT) |
| 15 |
| 16 _IGNORED_PATTERNS = [ |
| 17 # Ignored because they're not indicative of specific errors. |
| 18 re.compile(r'^$'), |
| 19 re.compile(r'^Analyzing \['), |
| 20 re.compile(r'^No issues found'), |
| 21 re.compile(r'^[0-9]+ errors? and [0-9]+ warnings? found.'), |
| 22 re.compile(r'^([0-9]+|No) (error|warning|issue)s? found.'), |
| 23 |
| 24 # Ignored because they don't affect Sky code |
| 25 re.compile(r'\[hint\] When compiled to JS, this test might return true when th
e left hand side is an int'), |
| 26 |
| 27 # TODO: Remove once sdk-extensions are in place |
| 28 re.compile(r'^\[error\] Native functions can only be declared in'), |
| 29 |
| 30 # TODO: Fix all the warnings in the mojo packages |
| 31 re.compile(r'.*/dart-pkg/mojom/'), |
| 32 re.compile(r'.*/dart-pkg/mojo/'), |
| 33 |
| 34 # TODO: Remove this once Sky no longer generates this warning. |
| 35 # dartbug.com/22836 |
| 36 re.compile(r'.*cannot both be unnamed'), |
| 37 |
| 38 # TODO: Remove this once Sky no longer generates this warning. |
| 39 # dartbug.com/23606 |
| 40 re.compile(r'^\[warning] Missing concrete implementation of \'RenderObject.toS
tring\''), |
| 41 ] |
| 42 |
| 43 def main(): |
| 44 parser = argparse.ArgumentParser(description='Sky Analyzer') |
| 45 parser.add_argument('--congratulate', action="store_true") |
| 46 parser.add_argument('build_dir', type=str) |
| 47 parser.add_argument('app_path', type=str) |
| 48 args = parser.parse_args() |
| 49 build_dir = args.build_dir |
| 50 analyzer_path = os.path.join(SRC_ROOT, 'third_party/dart-sdk/dart-sdk/bin/da
rtanalyzer') |
| 51 dart_sky_path = os.path.join(build_dir, 'gen/sky/bindings/dart_sky.dart') |
| 52 dart_sky_internals_path = os.path.join(SRC_ROOT, 'sky/sdk/lib/internals.dart
') |
| 53 dart_sky_builtin_path = os.path.join(SRC_ROOT, 'sky/engine/bindings/builtin.
dart') |
| 54 packages_root = os.path.join(build_dir, 'gen/dart-pkg/packages') |
| 55 analyzer_args = [analyzer_path, |
| 56 "--url-mapping=dart:sky,%s" % dart_sky_path, |
| 57 "--url-mapping=dart:sky.internals,%s" % dart_sky_internals_path, |
| 58 "--url-mapping=dart:sky_builtin,%s" % dart_sky_builtin_path, |
| 59 "--package-root", packages_root, |
| 60 "--package-warnings", |
| 61 args.app_path |
| 62 ] |
| 63 try: |
| 64 subprocess.check_output(analyzer_args, stderr=subprocess.STDOUT) |
| 65 except subprocess.CalledProcessError as e: |
| 66 errors = [l for l in e.output.split('\n') |
| 67 if not any(p.match(l) for p in _IGNORED_PATTERNS)] |
| 68 if len(errors) > 0: |
| 69 for error in errors: |
| 70 print >> sys.stderr, error |
| 71 # Propagate analyzer error code. |
| 72 return e.returncode |
| 73 # If we do not have any errors left after filtering, return 0. |
| 74 if args.congratulate: |
| 75 print >> sys.stdout, "No analyzer warnings!" |
| 76 return 0 |
| 77 |
| 78 if __name__ == '__main__': |
| 79 sys.exit(main()) |
OLD | NEW |