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 |
11 import zipfile | 11 import zipfile |
12 | 12 |
13 from telemetry import benchmark | 13 from telemetry import benchmark |
14 from telemetry.core import discover | 14 from telemetry.core import discover |
15 from telemetry.internal.util import bootstrap | |
16 from telemetry.internal.util import command_line | 15 from telemetry.internal.util import command_line |
17 from telemetry.internal.util import path | 16 from telemetry.internal.util import path |
18 from telemetry.internal.util import path_set | 17 from telemetry.internal.util import path_set |
19 | 18 |
20 from modulegraph import modulegraph | 19 from modulegraph import modulegraph # pylint: disable=import-error |
21 | 20 |
| 21 from core import bootstrap |
| 22 from core import path_util |
22 | 23 |
23 DEPS_FILE = 'bootstrap_deps' | 24 DEPS_FILE = 'bootstrap_deps' |
24 | 25 |
25 | 26 |
26 def FindBootstrapDependencies(base_dir): | 27 def FindBootstrapDependencies(base_dir): |
27 deps_file = os.path.join(base_dir, DEPS_FILE) | 28 deps_file = os.path.join(base_dir, DEPS_FILE) |
28 if not os.path.exists(deps_file): | 29 if not os.path.exists(deps_file): |
29 return [] | 30 return [] |
30 deps_paths = bootstrap.ListAllDepsPaths(deps_file) | 31 deps_paths = bootstrap.ListAllDepsPaths(deps_file) |
31 return set(os.path.realpath(os.path.join( | 32 return set(os.path.realpath(os.path.join( |
32 path.GetChromiumSrcDir(), '..', deps_path)) | 33 path_util.GetChromiumSrcDir(), '..', deps_path)) |
33 for deps_path in deps_paths) | 34 for deps_path in deps_paths) |
34 | 35 |
35 | 36 |
36 def FindPythonDependencies(module_path): | 37 def FindPythonDependencies(module_path): |
37 logging.info('Finding Python dependencies of %s' % module_path) | 38 logging.info('Finding Python dependencies of %s' % module_path) |
38 | 39 |
39 sys_path = sys.path | 40 sys_path = sys.path |
40 sys.path = list(sys_path) | 41 sys.path = list(sys_path) |
41 try: | 42 try: |
42 # Load the module to inherit its sys.path modifications. | 43 # Load the module to inherit its sys.path modifications. |
(...skipping 14 matching lines...) Expand all Loading... |
57 _, incoming_edges = graph.get_edges(node) | 58 _, incoming_edges = graph.get_edges(node) |
58 message = 'Discovered %s (Imported by: %s)' % ( | 59 message = 'Discovered %s (Imported by: %s)' % ( |
59 node.filename, ', '.join( | 60 node.filename, ', '.join( |
60 d.filename for d in incoming_edges | 61 d.filename for d in incoming_edges |
61 if d is not None and d.filename is not None)) | 62 if d is not None and d.filename is not None)) |
62 logging.info(message) | 63 logging.info(message) |
63 | 64 |
64 # This check is done after the logging/printing above to make sure that | 65 # This check is done after the logging/printing above to make sure that |
65 # we also print out the dependency edges that include python packages | 66 # we also print out the dependency edges that include python packages |
66 # that are not in chromium. | 67 # that are not in chromium. |
67 if not path.IsSubpath(module_path, path.GetChromiumSrcDir()): | 68 if not path.IsSubpath(module_path, path_util.GetChromiumSrcDir()): |
68 continue | 69 continue |
69 | 70 |
70 yield module_path | 71 yield module_path |
71 if node.packagepath is not None: | 72 if node.packagepath is not None: |
72 for p in node.packagepath: | 73 for p in node.packagepath: |
73 yield p | 74 yield p |
74 | 75 |
75 finally: | 76 finally: |
76 sys.path = sys_path | 77 sys.path = sys_path |
77 | 78 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 for target_path in target_paths: | 143 for target_path in target_paths: |
143 if not os.path.exists(target_path): | 144 if not os.path.exists(target_path): |
144 raise ValueError('Path does not exist: %s' % target_path) | 145 raise ValueError('Path does not exist: %s' % target_path) |
145 | 146 |
146 dependencies = path_set.PathSet() | 147 dependencies = path_set.PathSet() |
147 | 148 |
148 # Including Telemetry's major entry points will (hopefully) include Telemetry | 149 # Including Telemetry's major entry points will (hopefully) include Telemetry |
149 # and all its dependencies. If the user doesn't pass any arguments, we just | 150 # and all its dependencies. If the user doesn't pass any arguments, we just |
150 # have Telemetry. | 151 # have Telemetry. |
151 dependencies |= FindPythonDependencies(os.path.realpath( | 152 dependencies |= FindPythonDependencies(os.path.realpath( |
152 os.path.join(path.GetTelemetryDir(), 'telemetry', 'benchmark_runner.py'))) | 153 os.path.join(path_util.GetTelemetryDir(), |
| 154 'telemetry', 'benchmark_runner.py'))) |
153 dependencies |= FindPythonDependencies(os.path.realpath( | 155 dependencies |= FindPythonDependencies(os.path.realpath( |
154 os.path.join(path.GetTelemetryDir(), | 156 os.path.join(path_util.GetTelemetryDir(), |
155 'telemetry', 'testing', 'run_tests.py'))) | 157 'telemetry', 'testing', 'run_tests.py'))) |
156 | 158 |
157 # Add dependencies. | 159 # Add dependencies. |
158 for target_path in target_paths: | 160 for target_path in target_paths: |
159 base_dir = os.path.dirname(os.path.realpath(target_path)) | 161 base_dir = os.path.dirname(os.path.realpath(target_path)) |
160 | 162 |
161 dependencies.add(base_dir) | 163 dependencies.add(base_dir) |
162 dependencies |= FindBootstrapDependencies(base_dir) | 164 dependencies |= FindBootstrapDependencies(base_dir) |
163 dependencies |= FindPythonDependencies(target_path) | 165 dependencies |= FindPythonDependencies(target_path) |
164 if options.include_page_set_data: | 166 if options.include_page_set_data: |
165 dependencies |= FindPageSetDependencies(base_dir) | 167 dependencies |= FindPageSetDependencies(base_dir) |
166 | 168 |
167 # Remove excluded files. | 169 # Remove excluded files. |
168 dependencies -= FindExcludedFiles(set(dependencies), options) | 170 dependencies -= FindExcludedFiles(set(dependencies), options) |
169 | 171 |
170 return dependencies | 172 return dependencies |
171 | 173 |
172 | 174 |
173 def ZipDependencies(target_paths, dependencies, options): | 175 def ZipDependencies(target_paths, dependencies, options): |
174 base_dir = os.path.dirname(os.path.realpath(path.GetChromiumSrcDir())) | 176 base_dir = os.path.dirname(os.path.realpath(path_util.GetChromiumSrcDir())) |
175 | 177 |
176 with zipfile.ZipFile(options.zip, 'w', zipfile.ZIP_DEFLATED) as zip_file: | 178 with zipfile.ZipFile(options.zip, 'w', zipfile.ZIP_DEFLATED) as zip_file: |
177 # Add dependencies to archive. | 179 # Add dependencies to archive. |
178 for dependency_path in dependencies: | 180 for dependency_path in dependencies: |
179 path_in_archive = os.path.join( | 181 path_in_archive = os.path.join( |
180 'telemetry', os.path.relpath(dependency_path, base_dir)) | 182 'telemetry', os.path.relpath(dependency_path, base_dir)) |
181 zip_file.write(dependency_path, path_in_archive) | 183 zip_file.write(dependency_path, path_in_archive) |
182 | 184 |
183 # Add symlinks to executable paths, for ease of use. | 185 # Add symlinks to executable paths, for ease of use. |
184 for target_path in target_paths: | 186 for target_path in target_paths: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 234 |
233 def Run(self, args): | 235 def Run(self, args): |
234 target_paths = args.positional_args | 236 target_paths = args.positional_args |
235 dependencies = FindDependencies(target_paths, args) | 237 dependencies = FindDependencies(target_paths, args) |
236 if args.zip: | 238 if args.zip: |
237 ZipDependencies(target_paths, dependencies, args) | 239 ZipDependencies(target_paths, dependencies, args) |
238 print 'Zip archive written to %s.' % args.zip | 240 print 'Zip archive written to %s.' % args.zip |
239 else: | 241 else: |
240 print '\n'.join(sorted(dependencies)) | 242 print '\n'.join(sorted(dependencies)) |
241 return 0 | 243 return 0 |
OLD | NEW |