| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import fnmatch | 5 import fnmatch |
| 6 import imp | 6 import imp |
| 7 import logging | 7 import logging |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 return [] | 29 return [] |
| 30 deps_paths = bootstrap.ListAllDepsPaths(deps_file) | 30 deps_paths = bootstrap.ListAllDepsPaths(deps_file) |
| 31 return set(os.path.realpath(os.path.join( | 31 return set(os.path.realpath(os.path.join( |
| 32 path.GetChromiumSrcDir(), os.pardir, deps_path)) | 32 path.GetChromiumSrcDir(), os.pardir, deps_path)) |
| 33 for deps_path in deps_paths) | 33 for deps_path in deps_paths) |
| 34 | 34 |
| 35 | 35 |
| 36 def FindPythonDependencies(module_path): | 36 def FindPythonDependencies(module_path): |
| 37 logging.info('Finding Python dependencies of %s' % module_path) | 37 logging.info('Finding Python dependencies of %s' % module_path) |
| 38 | 38 |
| 39 # Load the module to inherit its sys.path modifications. | 39 sys_path = sys.path |
| 40 imp.load_source( | 40 sys.path = list(sys_path) |
| 41 os.path.splitext(os.path.basename(module_path))[0], module_path) | 41 try: |
| 42 # Load the module to inherit its sys.path modifications. |
| 43 sys.path.insert(0, os.path.abspath(os.path.dirname(module_path))) |
| 44 imp.load_source( |
| 45 os.path.splitext(os.path.basename(module_path))[0], module_path) |
| 42 | 46 |
| 43 # Analyze the module for its imports. | 47 # Analyze the module for its imports. |
| 44 graph = modulegraph.ModuleGraph() | 48 graph = modulegraph.ModuleGraph() |
| 45 graph.run_script(module_path) | 49 graph.run_script(module_path) |
| 46 | 50 |
| 47 # Filter for only imports in Chromium. | 51 # Filter for only imports in Chromium. |
| 48 for node in graph.nodes(): | 52 for node in graph.nodes(): |
| 49 if not node.filename: | 53 if not node.filename: |
| 50 continue | 54 continue |
| 51 module_path = os.path.realpath(node.filename) | 55 module_path = os.path.realpath(node.filename) |
| 52 | 56 |
| 53 _, incoming_edges = graph.get_edges(node) | 57 _, incoming_edges = graph.get_edges(node) |
| 54 message = 'Discovered %s (Imported by: %s)' % ( | 58 message = 'Discovered %s (Imported by: %s)' % ( |
| 55 node.filename, ', '.join( | 59 node.filename, ', '.join( |
| 56 d.filename for d in incoming_edges | 60 d.filename for d in incoming_edges |
| 57 if d is not None and d.filename is not None)) | 61 if d is not None and d.filename is not None)) |
| 58 logging.info(message) | 62 logging.info(message) |
| 59 | 63 |
| 60 # This check is done after the logging/printing above to make sure that we | 64 # This check is done after the logging/printing above to make sure that |
| 61 # also print out the dependency edges that include python packages that are | 65 # we also print out the dependency edges that include python packages |
| 62 # not in chromium. | 66 # that are not in chromium. |
| 63 if not path.IsSubpath(module_path, path.GetChromiumSrcDir()): | 67 if not path.IsSubpath(module_path, path.GetChromiumSrcDir()): |
| 64 continue | 68 continue |
| 65 | 69 |
| 66 yield module_path | 70 yield module_path |
| 67 if node.packagepath is not None: | 71 if node.packagepath is not None: |
| 68 for p in node.packagepath: | 72 for p in node.packagepath: |
| 69 yield p | 73 yield p |
| 74 |
| 75 finally: |
| 76 sys.path = sys_path |
| 70 | 77 |
| 71 | 78 |
| 72 def FindPageSetDependencies(base_dir): | 79 def FindPageSetDependencies(base_dir): |
| 73 logging.info('Finding page sets in %s' % base_dir) | 80 logging.info('Finding page sets in %s' % base_dir) |
| 74 | 81 |
| 75 # Add base_dir to path so our imports relative to base_dir will work. | 82 # Add base_dir to path so our imports relative to base_dir will work. |
| 76 sys.path.append(base_dir) | 83 sys.path.append(base_dir) |
| 77 tests = discover.DiscoverClasses(base_dir, base_dir, benchmark.Benchmark, | 84 tests = discover.DiscoverClasses(base_dir, base_dir, benchmark.Benchmark, |
| 78 index_by_class_name=True) | 85 index_by_class_name=True) |
| 79 | 86 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 233 |
| 227 def Run(self, args): | 234 def Run(self, args): |
| 228 target_paths = args.positional_args | 235 target_paths = args.positional_args |
| 229 dependencies = FindDependencies(target_paths, args) | 236 dependencies = FindDependencies(target_paths, args) |
| 230 if args.zip: | 237 if args.zip: |
| 231 ZipDependencies(target_paths, dependencies, args) | 238 ZipDependencies(target_paths, dependencies, args) |
| 232 print 'Zip archive written to %s.' % args.zip | 239 print 'Zip archive written to %s.' % args.zip |
| 233 else: | 240 else: |
| 234 print '\n'.join(sorted(dependencies)) | 241 print '\n'.join(sorted(dependencies)) |
| 235 return 0 | 242 return 0 |
| OLD | NEW |