Bug 920353 - Use PYCOMMANDPATH paths as site packages in pymake, and set it to the virtualenv site packages instead of $(topsrcdir)/config. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 26 Sep 2013 16:43:53 +0900
changeset 148790 0c459362695e1c3a7510d2f372c97264884788fd
parent 148789 9c12830ce02f0e445b511c27578cb2dea634e552
child 148791 7da79387b24d4d73d2ef3d67578d066f0bd42820
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs920353
milestone27.0a1
Bug 920353 - Use PYCOMMANDPATH paths as site packages in pymake, and set it to the virtualenv site packages instead of $(topsrcdir)/config. r=gps
build/autoconf/python-virtualenv.m4
build/pymake/pymake/process.py
config/config.mk
js/src/build/autoconf/python-virtualenv.m4
js/src/config/config.mk
--- a/build/autoconf/python-virtualenv.m4
+++ b/build/autoconf/python-virtualenv.m4
@@ -69,10 +69,17 @@ fi
 AC_SUBST(PYTHON)
 
 AC_MSG_CHECKING([Python environment is Mozilla virtualenv])
 $PYTHON -c "import mozbuild.base"
 if test "$?" != 0; then
     AC_MSG_ERROR([Python environment does not appear to be sane.])
 fi
 AC_MSG_RESULT([yes])
+
+PYTHON_SITE_PACKAGES=`$PYTHON -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib()"`
+if test -z "$PYTHON_SITE_PACKAGES"; then
+    AC_MSG_ERROR([Could not determine python site packages directory.])
+fi
+AC_SUBST([PYTHON_SITE_PACKAGES])
+
 ])
 
--- a/build/pymake/pymake/process.py
+++ b/build/pymake/pymake/process.py
@@ -1,16 +1,17 @@
 """
 Skipping shell invocations is good, when possible. This wrapper around subprocess does dirty work of
 parsing command lines into argv and making sure that no shell magic is being used.
 """
 
 #TODO: ship pyprocessing?
 import multiprocessing
 import subprocess, shlex, re, logging, sys, traceback, os, imp, glob
+import site
 from collections import deque
 # XXXkhuey Work around http://bugs.python.org/issue1731717
 subprocess._cleanup = lambda: None
 import command, util
 if sys.platform=='win32':
     import win32process
 
 _log = logging.getLogger('pymake.process')
@@ -342,38 +343,29 @@ class PythonException(Exception):
         self.message = message
         self.exitcode = exitcode
 
     def __str__(self):
         return self.message
 
 def load_module_recursive(module, path):
     """
-    Emulate the behavior of __import__, but allow
-    passing a custom path to search for modules.
+    Like __import__, but allow passing a custom path to search for modules.
     """
-    bits = module.split('.')
     oldsyspath = sys.path
-    for i, bit in enumerate(bits):
-        dotname = '.'.join(bits[:i+1])
-        try:
-          f, path, desc = imp.find_module(bit, path)
-          # Add the directory the module was found in to sys.path
-          if path != '':
-              abspath = os.path.abspath(path)
-              if not os.path.isdir(abspath):
-                  abspath = os.path.dirname(path)
-              sys.path = [abspath] + sys.path
-          m = imp.load_module(dotname, f, path, desc)
-          if f is None:
-              path = m.__path__
-        except ImportError:
-            return
-        finally:
-            sys.path = oldsyspath
+    sys.path = []
+    for p in path:
+        site.addsitedir(p)
+    sys.path.extend(oldsyspath)
+    try:
+        __import__(module)
+    except ImportError:
+        return
+    finally:
+        sys.path = oldsyspath
 
 class PythonJob(Job):
     """
     A job that calls a Python method.
     """
     def __init__(self, module, method, argv, env, cwd, pycommandpath=None):
         self.module = module
         self.method = method
--- a/config/config.mk
+++ b/config/config.mk
@@ -127,17 +127,17 @@ endif # _MSC_VER
 
 CC := $(CC_WRAPPER) $(CC)
 CXX := $(CXX_WRAPPER) $(CXX)
 MKDIR ?= mkdir
 SLEEP ?= sleep
 TOUCH ?= touch
 
 ifdef .PYMAKE
-PYCOMMANDPATH += $(topsrcdir)/config
+PYCOMMANDPATH += $(PYTHON_SITE_PACKAGES)
 endif
 
 PYTHON_PATH = $(PYTHON) $(topsrcdir)/config/pythonpath.py
 
 # determine debug-related options
 _DEBUG_ASFLAGS :=
 _DEBUG_CFLAGS :=
 _DEBUG_LDFLAGS :=
--- a/js/src/build/autoconf/python-virtualenv.m4
+++ b/js/src/build/autoconf/python-virtualenv.m4
@@ -69,10 +69,17 @@ fi
 AC_SUBST(PYTHON)
 
 AC_MSG_CHECKING([Python environment is Mozilla virtualenv])
 $PYTHON -c "import mozbuild.base"
 if test "$?" != 0; then
     AC_MSG_ERROR([Python environment does not appear to be sane.])
 fi
 AC_MSG_RESULT([yes])
+
+PYTHON_SITE_PACKAGES=`$PYTHON -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib()"`
+if test -z "$PYTHON_SITE_PACKAGES"; then
+    AC_MSG_ERROR([Could not determine python site packages directory.])
+fi
+AC_SUBST([PYTHON_SITE_PACKAGES])
+
 ])
 
--- a/js/src/config/config.mk
+++ b/js/src/config/config.mk
@@ -127,17 +127,17 @@ endif # _MSC_VER
 
 CC := $(CC_WRAPPER) $(CC)
 CXX := $(CXX_WRAPPER) $(CXX)
 MKDIR ?= mkdir
 SLEEP ?= sleep
 TOUCH ?= touch
 
 ifdef .PYMAKE
-PYCOMMANDPATH += $(topsrcdir)/config
+PYCOMMANDPATH += $(PYTHON_SITE_PACKAGES)
 endif
 
 PYTHON_PATH = $(PYTHON) $(topsrcdir)/config/pythonpath.py
 
 # determine debug-related options
 _DEBUG_ASFLAGS :=
 _DEBUG_CFLAGS :=
 _DEBUG_LDFLAGS :=