| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Utility for static analysis test of dart packages generated by dart-pkg""" | 7 """Utility for static analysis test of dart packages generated by dart-pkg""" |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import errno | 10 import errno |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 return e.returncode | 40 return e.returncode |
| 41 return 0 | 41 return 0 |
| 42 | 42 |
| 43 | 43 |
| 44 def analyze_package(dart_sdk, package_root, package): | 44 def analyze_package(dart_sdk, package_root, package): |
| 45 package_name = package[0] | 45 package_name = package[0] |
| 46 package_entrypoints = package[1] | 46 package_entrypoints = package[1] |
| 47 print('Analyzing dart-pkg %s ' % package_name) | 47 print('Analyzing dart-pkg %s ' % package_name) |
| 48 return analyze_entrypoints(dart_sdk, package_root, package_entrypoints) | 48 return analyze_entrypoints(dart_sdk, package_root, package_entrypoints) |
| 49 | 49 |
| 50 # Filter entrypoints for files that exist. |
| 51 def filter_entrypoints(package_name, entrypoints): |
| 52 result = [] |
| 53 for entrypoint in entrypoints: |
| 54 if os.path.isfile(entrypoint): |
| 55 result.append(entrypoint) |
| 56 else: |
| 57 print('WARNING: Could not find %s from %s ' % (entrypoint, package_name)) |
| 58 return result |
| 59 |
| 50 def main(): | 60 def main(): |
| 51 parser = argparse.ArgumentParser(description='Generate a dart-pkg') | 61 parser = argparse.ArgumentParser(description='Generate a dart-pkg') |
| 52 parser.add_argument('--dart-sdk', | 62 parser.add_argument('--dart-sdk', |
| 53 action='store', | 63 action='store', |
| 54 metavar='dart_sdk', | 64 metavar='dart_sdk', |
| 55 help='Path to the Dart SDK.') | 65 help='Path to the Dart SDK.') |
| 56 parser.add_argument('--dart-pkg-dir', | 66 parser.add_argument('--dart-pkg-dir', |
| 57 action='store', | 67 action='store', |
| 58 metavar='dart_pkg_dir', | 68 metavar='dart_pkg_dir', |
| 59 help='Directory of dart packages', | 69 help='Directory of dart packages', |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 print "Pass --dart-sdk, or define the DART_SDK environment variable" | 85 print "Pass --dart-sdk, or define the DART_SDK environment variable" |
| 76 return 1 | 86 return 1 |
| 77 | 87 |
| 78 jobs = [] | 88 jobs = [] |
| 79 # Determine which packages to analyze | 89 # Determine which packages to analyze |
| 80 for filename in os.listdir(args.dart_pkg_dir): | 90 for filename in os.listdir(args.dart_pkg_dir): |
| 81 if filename.endswith('.entries'): | 91 if filename.endswith('.entries'): |
| 82 if not args.package_name or (filename == args.package_name + '.entries'): | 92 if not args.package_name or (filename == args.package_name + '.entries'): |
| 83 with open(os.path.join(args.dart_pkg_dir, filename)) as f: | 93 with open(os.path.join(args.dart_pkg_dir, filename)) as f: |
| 84 entrypoints = f.read().splitlines() | 94 entrypoints = f.read().splitlines() |
| 95 package_name = os.path.splitext(filename)[0] |
| 96 entrypoints = filter_entrypoints(package_name, entrypoints) |
| 85 if entrypoints != []: | 97 if entrypoints != []: |
| 86 jobs.append([os.path.splitext(filename)[0], entrypoints]) | 98 jobs.append([package_name, entrypoints]) |
| 87 | 99 |
| 88 # Create a process pool. | 100 # Create a process pool. |
| 89 pool = multiprocessing.Pool(multiprocessing.cpu_count()) | 101 pool = multiprocessing.Pool(multiprocessing.cpu_count()) |
| 90 # Spawn jobs. | 102 # Spawn jobs. |
| 91 for job in jobs: | 103 for job in jobs: |
| 92 pool.apply_async(analyze_package, | 104 pool.apply_async(analyze_package, |
| 93 args = (dart_sdk, args.package_root, job, ), | 105 args = (dart_sdk, args.package_root, job, ), |
| 94 callback = collect_result) | 106 callback = collect_result) |
| 95 # Wait for them to complete. | 107 # Wait for them to complete. |
| 96 pool.close(); | 108 pool.close(); |
| 97 pool.join(); | 109 pool.join(); |
| 98 | 110 |
| 99 # Return the error code if any packages failed. | 111 # Return the error code if any packages failed. |
| 100 for result in result_list: | 112 for result in result_list: |
| 101 if result != 0: | 113 if result != 0: |
| 102 return result | 114 return result |
| 103 | 115 |
| 104 return 0 | 116 return 0 |
| 105 | 117 |
| 106 if __name__ == '__main__': | 118 if __name__ == '__main__': |
| 107 sys.exit(main()) | 119 sys.exit(main()) |
| OLD | NEW |