Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3606)

Unified Diff: build/android/gyp/util/build_utils.py

Issue 2567393003: [Chromecast] Fix for building Android Cast builds with virtualenv. (Closed)
Patch Set: Ensure sys.modules is stabilized before getting the final list of modules. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/util/build_utils.py
diff --git a/build/android/gyp/util/build_utils.py b/build/android/gyp/util/build_utils.py
index 65bd07b351ca6aaaf65b5f4a8aa050145d99d8f9..8b395131c57f2d45643c5cfef80d7dbdda98ff87 100644
--- a/build/android/gyp/util/build_utils.py
+++ b/build/android/gyp/util/build_utils.py
@@ -406,8 +406,7 @@ def GetPythonDependencies():
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.
"""
- module_paths = (m.__file__ for m in sys.modules.itervalues()
- if m is not None and hasattr(m, '__file__'))
+ module_paths = GetModulePaths()
abs_module_paths = map(os.path.abspath, module_paths)
@@ -424,6 +423,30 @@ def GetPythonDependencies():
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):
# TODO(agrieve): Get rid of this once we've moved to argparse.
if hasattr(parser, 'add_option'):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698