Skip to content

Commit

Permalink
Bug 841713 - Add objdir paths to virtualenv; r=ted
Browse files Browse the repository at this point in the history
  • Loading branch information
indygreg committed Mar 26, 2013
1 parent cfdc768 commit 88ff049
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build/autoconf/python-virtualenv.m4
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if test -z $DONT_POPULATE_VIRTUALENV; then
dnl virtualenv is present and up to date. It sanitizes the environment
dnl for us, so we don't need to clean anything out.
$PYTHON $_virtualenv_populate_path \
$_virtualenv_topsrcdir $MOZ_BUILD_ROOT/_virtualenv || exit 1
$_virtualenv_topsrcdir $MOZ_BUILD_ROOT $MOZ_BUILD_ROOT/_virtualenv || exit 1
case "$host_os" in
mingw*)
Expand Down
1 change: 1 addition & 0 deletions build/virtualenv/packages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ mozilla.pth:config
mozilla.pth:xpcom/typelib/xpt/tools
copy:build/buildconfig.py
packages.txt:testing/mozbase/packages.txt
objdir:build
38 changes: 31 additions & 7 deletions build/virtualenv/populate_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
class VirtualenvManager(object):
"""Contains logic for managing virtualenvs for building the tree."""

def __init__(self, topsrcdir, virtualenv_path, log_handle, manifest_path):
def __init__(self, topsrcdir, topobjdir, virtualenv_path, log_handle,
manifest_path):
"""Create a new manager.
Each manager is associated with a source directory, a path where you
want the virtualenv to be created, and a handle to write output to.
"""
assert os.path.isabs(manifest_path), "manifest_path must be an absolute path: %s" % (manifest_path)
self.topsrcdir = topsrcdir
self.topobjdir = topobjdir
self.virtualenv_root = virtualenv_path
self.log_handle = log_handle
self.manifest_path = manifest_path
Expand Down Expand Up @@ -78,6 +80,7 @@ def up_to_date(self):
for submanifest in submanifests:
submanifest = os.path.join(self.topsrcdir, submanifest)
submanager = VirtualenvManager(self.topsrcdir,
self.topobjdir,
self.virtualenv_root,
self.log_handle,
submanifest)
Expand Down Expand Up @@ -151,6 +154,14 @@ def populate(self):
copy -- Copies the given file in the virtualenv site packages
directory.
packages.txt -- Denotes that the specified path is a child manifest. It
will be read and processed as if its contents were concatenated
into the manifest being read.
objdir -- Denotes a relative path in the object directory to add to the
search path. e.g. "objdir:build" will add $topobjdir/build to the
search path.
Note that the Python interpreter running this function should be the
one from the virtualenv. If it is the system Python or if the
environment is not configured properly, packages could be installed
Expand Down Expand Up @@ -185,6 +196,7 @@ def handle_package(package):
src = os.path.join(self.topsrcdir, package[1])
assert os.path.isfile(src), "'%s' does not exist" % src
submanager = VirtualenvManager(self.topsrcdir,
self.topobjdir,
self.virtualenv_root,
self.log_handle,
src)
Expand Down Expand Up @@ -212,6 +224,15 @@ def handle_package(package):
file=self.log_handle)
return False

if package[0] == 'objdir':
assert len(package) == 2
path = os.path.join(self.topobjdir, package[1])

with open(os.path.join(python_lib, 'objdir.pth'), 'a') as f:
f.write('%s\n' % path)

return True

raise Exception('Unknown action: %s' % package[0])

# We always target the OS X deployment target that Python itself was
Expand Down Expand Up @@ -293,7 +314,7 @@ def build(self):
# the virtualenv for paths to be proper.

args = [self.python_path, __file__, 'populate', self.topsrcdir,
self.virtualenv_root]
self.topobjdir, self.virtualenv_root]

result = subprocess.call(args, stdout=self.log_handle,
stderr=subprocess.STDOUT, cwd=self.topsrcdir)
Expand Down Expand Up @@ -329,26 +350,29 @@ def verify_python_version(log_handle):


if __name__ == '__main__':
if len(sys.argv) < 3:
print('Usage: populate_virtualenv.py /path/to/topsrcdir /path/to/virtualenv')
if len(sys.argv) < 4:
print('Usage: populate_virtualenv.py /path/to/topsrcdir /path/to/topobjdir /path/to/virtualenv')
sys.exit(1)

verify_python_version(sys.stdout)

topsrcdir = sys.argv[1]
virtualenv_path = sys.argv[2]
topobjdir = sys.argv[2]
virtualenv_path = sys.argv[3]
populate = False

# This should only be called internally.
if sys.argv[1] == 'populate':
populate = True
topsrcdir = sys.argv[2]
virtualenv_path = sys.argv[3]
topobjdir = sys.argv[3]
virtualenv_path = sys.argv[4]

# path to default packages.txt
manifest_path = os.path.join(topsrcdir, 'build', 'virtualenv', 'packages.txt')

manager = VirtualenvManager(topsrcdir, virtualenv_path, sys.stdout, manifest_path)
manager = VirtualenvManager(topsrcdir, topobjdir, virtualenv_path,
sys.stdout, manifest_path)

if populate:
manager.populate()
Expand Down
2 changes: 1 addition & 1 deletion js/src/build/autoconf/python-virtualenv.m4
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if test -z $DONT_POPULATE_VIRTUALENV; then
dnl virtualenv is present and up to date. It sanitizes the environment
dnl for us, so we don't need to clean anything out.
$PYTHON $_virtualenv_populate_path \
$_virtualenv_topsrcdir $MOZ_BUILD_ROOT/_virtualenv || exit 1
$_virtualenv_topsrcdir $MOZ_BUILD_ROOT $MOZ_BUILD_ROOT/_virtualenv || exit 1
case "$host_os" in
mingw*)
Expand Down
2 changes: 1 addition & 1 deletion layout/tools/reftest/runreftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import re, sys, shutil, os, os.path
SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
sys.path.append(SCRIPT_DIRECTORY)
sys.path.insert(0, SCRIPT_DIRECTORY)

from automation import Automation
from automationutils import *
Expand Down

0 comments on commit 88ff049

Please sign in to comment.