[Chromecast] Fix for building Android Cast builds with virtualenv.

The Chromecast CQ bots are failing to build the Android builds.
Iterating over sys.modules with itervalues() results in a runtime error
because sys.modules is apparently changing size. Using
sys.modules.values() instead lets sys.modules change without a runtime
error since it makes a copy.

BUG=673915

Review-Url: https://codereview.chromium.org/2567393003
Cr-Original-Commit-Position: refs/heads/master@{#439234}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: d00168a948a32f378a0c05842ee52ca35905c9d5
This commit is contained in:
mbjorge 2016-12-16 15:48:34 -08:00 коммит произвёл Commit bot
Родитель 872ac23152
Коммит d39391f1f6
1 изменённых файлов: 25 добавлений и 2 удалений

Просмотреть файл

@ -406,8 +406,7 @@ def GetPythonDependencies():
A path is assumed to be a "system" import if it is outside of chromium's A path is assumed to be a "system" import if it is outside of chromium's
src/. The paths will be relative to the current directory. src/. The paths will be relative to the current directory.
""" """
module_paths = (m.__file__ for m in sys.modules.itervalues() module_paths = GetModulePaths()
if m is not None and hasattr(m, '__file__'))
abs_module_paths = map(os.path.abspath, module_paths) abs_module_paths = map(os.path.abspath, module_paths)
@ -424,6 +423,30 @@ def GetPythonDependencies():
return sorted(set(non_system_module_paths)) return sorted(set(non_system_module_paths))
def GetModulePaths():
"""Returns the paths to all of the modules in sys.modules."""
ForceLazyModulesToLoad()
return (m.__file__ for m in sys.modules.itervalues()
if m is not None and hasattr(m, '__file__'))
def ForceLazyModulesToLoad():
"""Forces any lazily imported modules to fully load themselves.
Inspecting the modules' __file__ attribute causes lazily imported modules
(e.g. from email) to get fully imported and update sys.modules. Iterate
over the values until sys.modules stabilizes so that no modules are missed.
"""
while True:
num_modules_before = len(sys.modules.keys())
for m in sys.modules.values():
if m is not None and hasattr(m, '__file__'):
_ = m.__file__
num_modules_after = len(sys.modules.keys())
if num_modules_before == num_modules_after:
break
def AddDepfileOption(parser): def AddDepfileOption(parser):
# TODO(agrieve): Get rid of this once we've moved to argparse. # TODO(agrieve): Get rid of this once we've moved to argparse.
if hasattr(parser, 'add_option'): if hasattr(parser, 'add_option'):