| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 ast | 5 import ast |
| 6 import contextlib | 6 import contextlib |
| 7 import fnmatch | 7 import fnmatch |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import pipes | 10 import pipes |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 | 192 |
| 193 def ExtractAll(zip_path, path=None, no_clobber=True): | 193 def ExtractAll(zip_path, path=None, no_clobber=True): |
| 194 if path is None: | 194 if path is None: |
| 195 path = os.getcwd() | 195 path = os.getcwd() |
| 196 elif not os.path.exists(path): | 196 elif not os.path.exists(path): |
| 197 MakeDirectory(path) | 197 MakeDirectory(path) |
| 198 | 198 |
| 199 with zipfile.ZipFile(zip_path) as z: | 199 with zipfile.ZipFile(zip_path) as z: |
| 200 for name in z.namelist(): | 200 for name in z.namelist(): |
| 201 if name.endswith('/'): |
| 202 continue |
| 201 CheckZipPath(name) | 203 CheckZipPath(name) |
| 202 if no_clobber: | 204 if no_clobber: |
| 203 output_path = os.path.join(path, name) | 205 output_path = os.path.join(path, name) |
| 204 if os.path.exists(output_path): | 206 if os.path.exists(output_path): |
| 205 raise Exception( | 207 raise Exception( |
| 206 'Path already exists from zip: %s %s %s' | 208 'Path already exists from zip: %s %s %s' |
| 207 % (zip_path, name, output_path)) | 209 % (zip_path, name, output_path)) |
| 208 | 210 |
| 209 z.extractall(path=path) | 211 z.extractall(path=path) |
| 210 | 212 |
| 211 | 213 |
| 212 def DoZip(inputs, output, base_dir): | 214 def DoZip(inputs, output, base_dir): |
| 213 with zipfile.ZipFile(output, 'w') as outfile: | 215 with zipfile.ZipFile(output, 'w') as outfile: |
| 214 for f in inputs: | 216 for f in inputs: |
| 215 CheckZipPath(os.path.relpath(f, base_dir)) | 217 CheckZipPath(os.path.relpath(f, base_dir)) |
| 216 outfile.write(f, os.path.relpath(f, base_dir)) | 218 outfile.write(f, os.path.relpath(f, base_dir)) |
| 217 | 219 |
| 218 | 220 |
| 221 def ZipDir(output, base_dir): |
| 222 with zipfile.ZipFile(output, 'w') as outfile: |
| 223 for root, _, files in os.walk(base_dir): |
| 224 for f in files: |
| 225 path = os.path.join(root, f) |
| 226 archive_path = os.path.relpath(path, base_dir) |
| 227 CheckZipPath(archive_path) |
| 228 outfile.write(path, archive_path) |
| 229 |
| 230 |
| 219 def PrintWarning(message): | 231 def PrintWarning(message): |
| 220 print 'WARNING: ' + message | 232 print 'WARNING: ' + message |
| 221 | 233 |
| 222 | 234 |
| 223 def PrintBigWarning(message): | 235 def PrintBigWarning(message): |
| 224 print '***** ' * 8 | 236 print '***** ' * 8 |
| 225 PrintWarning(message) | 237 PrintWarning(message) |
| 226 print '***** ' * 8 | 238 print '***** ' * 8 |
| 227 | 239 |
| 228 | 240 |
| 241 def GetSortedTransitiveDependencies(top, deps_func): |
| 242 """Gets the list of all transitive dependencies in sorted order. |
| 243 |
| 244 There should be no cycles in the dependency graph. |
| 245 |
| 246 Args: |
| 247 top: a list of the top level nodes |
| 248 deps_func: A function that takes a node and returns its direct dependencies. |
| 249 Returns: |
| 250 A list of all transitive dependencies of nodes in top, in order (a node will |
| 251 appear in the list at a higher index than all of its dependencies). |
| 252 """ |
| 253 def Node(dep): |
| 254 return (dep, deps_func(dep)) |
| 255 |
| 256 # First: find all deps |
| 257 unchecked_deps = list(top) |
| 258 all_deps = set(top) |
| 259 while unchecked_deps: |
| 260 dep = unchecked_deps.pop() |
| 261 new_deps = deps_func(dep).difference(all_deps) |
| 262 unchecked_deps.extend(new_deps) |
| 263 all_deps = all_deps.union(new_deps) |
| 264 |
| 265 # Then: simple, slow topological sort. |
| 266 sorted_deps = [] |
| 267 unsorted_deps = dict(map(Node, all_deps)) |
| 268 while unsorted_deps: |
| 269 for library, dependencies in unsorted_deps.items(): |
| 270 if not dependencies.intersection(unsorted_deps.keys()): |
| 271 sorted_deps.append(library) |
| 272 del unsorted_deps[library] |
| 273 |
| 274 return sorted_deps |
| 275 |
| 276 |
| 229 def GetPythonDependencies(): | 277 def GetPythonDependencies(): |
| 230 """Gets the paths of imported non-system python modules. | 278 """Gets the paths of imported non-system python modules. |
| 231 | 279 |
| 232 A path is assumed to be a "system" import if it is outside of chromium's | 280 A path is assumed to be a "system" import if it is outside of chromium's |
| 233 src/. The paths will be relative to the current directory. | 281 src/. The paths will be relative to the current directory. |
| 234 """ | 282 """ |
| 235 module_paths = (m.__file__ for m in sys.modules.itervalues() | 283 module_paths = (m.__file__ for m in sys.modules.itervalues() |
| 236 if m is not None and hasattr(m, '__file__')) | 284 if m is not None and hasattr(m, '__file__')) |
| 237 | 285 |
| 238 abs_module_paths = map(os.path.abspath, module_paths) | 286 abs_module_paths = map(os.path.abspath, module_paths) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 if not file_path in file_jsons: | 344 if not file_path in file_jsons: |
| 297 file_jsons[file_path] = ReadJson(file_path) | 345 file_jsons[file_path] = ReadJson(file_path) |
| 298 | 346 |
| 299 expansion = file_jsons[file_path] | 347 expansion = file_jsons[file_path] |
| 300 for k in lookup_path[1:]: | 348 for k in lookup_path[1:]: |
| 301 expansion = expansion[k] | 349 expansion = expansion[k] |
| 302 | 350 |
| 303 new_args[i] = arg[:start] + str(expansion) + arg[end + 1:] | 351 new_args[i] = arg[:start] + str(expansion) + arg[end + 1:] |
| 304 return new_args | 352 return new_args |
| 305 | 353 |
| OLD | NEW |