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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 399 |
400 return sorted_deps | 400 return sorted_deps |
401 | 401 |
402 | 402 |
403 def GetPythonDependencies(): | 403 def GetPythonDependencies(): |
404 """Gets the paths of imported non-system python modules. | 404 """Gets the paths of imported non-system python modules. |
405 | 405 |
406 A path is assumed to be a "system" import if it is outside of chromium's | 406 A path is assumed to be a "system" import if it is outside of chromium's |
407 src/. The paths will be relative to the current directory. | 407 src/. The paths will be relative to the current directory. |
408 """ | 408 """ |
409 module_paths = (m.__file__ for m in sys.modules.itervalues() | 409 module_paths = GetModulePaths() |
410 if m is not None and hasattr(m, '__file__')) | |
411 | 410 |
412 abs_module_paths = map(os.path.abspath, module_paths) | 411 abs_module_paths = map(os.path.abspath, module_paths) |
413 | 412 |
414 assert os.path.isabs(host_paths.DIR_SOURCE_ROOT) | 413 assert os.path.isabs(host_paths.DIR_SOURCE_ROOT) |
415 non_system_module_paths = [ | 414 non_system_module_paths = [ |
416 p for p in abs_module_paths if p.startswith(host_paths.DIR_SOURCE_ROOT)] | 415 p for p in abs_module_paths if p.startswith(host_paths.DIR_SOURCE_ROOT)] |
417 def ConvertPycToPy(s): | 416 def ConvertPycToPy(s): |
418 if s.endswith('.pyc'): | 417 if s.endswith('.pyc'): |
419 return s[:-1] | 418 return s[:-1] |
420 return s | 419 return s |
421 | 420 |
422 non_system_module_paths = map(ConvertPycToPy, non_system_module_paths) | 421 non_system_module_paths = map(ConvertPycToPy, non_system_module_paths) |
423 non_system_module_paths = map(os.path.relpath, non_system_module_paths) | 422 non_system_module_paths = map(os.path.relpath, non_system_module_paths) |
424 return sorted(set(non_system_module_paths)) | 423 return sorted(set(non_system_module_paths)) |
425 | 424 |
426 | 425 |
| 426 def GetModulePaths(): |
| 427 """Returns the paths to all of the modules in sys.modules.""" |
| 428 ForceLazyModulesToLoad() |
| 429 return (m.__file__ for m in sys.modules.itervalues() |
| 430 if m is not None and hasattr(m, '__file__')) |
| 431 |
| 432 |
| 433 def ForceLazyModulesToLoad(): |
| 434 """Forces any lazily imported modules to fully load themselves. |
| 435 |
| 436 Inspecting the modules' __file__ attribute causes lazily imported modules |
| 437 (e.g. from email) to get fully imported and update sys.modules. Iterate |
| 438 over the values until sys.modules stabilizes so that no modules are missed. |
| 439 """ |
| 440 while True: |
| 441 num_modules_before = len(sys.modules.keys()) |
| 442 for m in sys.modules.values(): |
| 443 if m is not None and hasattr(m, '__file__'): |
| 444 _ = m.__file__ |
| 445 num_modules_after = len(sys.modules.keys()) |
| 446 if num_modules_before == num_modules_after: |
| 447 break |
| 448 |
| 449 |
427 def AddDepfileOption(parser): | 450 def AddDepfileOption(parser): |
428 # TODO(agrieve): Get rid of this once we've moved to argparse. | 451 # TODO(agrieve): Get rid of this once we've moved to argparse. |
429 if hasattr(parser, 'add_option'): | 452 if hasattr(parser, 'add_option'): |
430 func = parser.add_option | 453 func = parser.add_option |
431 else: | 454 else: |
432 func = parser.add_argument | 455 func = parser.add_argument |
433 func('--depfile', | 456 func('--depfile', |
434 help='Path to depfile (refer to `gn help depfile`)') | 457 help='Path to depfile (refer to `gn help depfile`)') |
435 | 458 |
436 | 459 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 570 |
548 md5_check.CallAndRecordIfStale( | 571 md5_check.CallAndRecordIfStale( |
549 on_stale_md5, | 572 on_stale_md5, |
550 record_path=record_path, | 573 record_path=record_path, |
551 input_paths=input_paths, | 574 input_paths=input_paths, |
552 input_strings=input_strings, | 575 input_strings=input_strings, |
553 output_paths=output_paths, | 576 output_paths=output_paths, |
554 force=force, | 577 force=force, |
555 pass_changes=True) | 578 pass_changes=True) |
556 | 579 |
OLD | NEW |