Bug 785871 - Make importing config.status easier. r=ted,r=gps

This commit is contained in:
Mike Hommey 2012-09-20 09:52:12 +02:00
Родитель c07488a294
Коммит d210fb66e2
3 изменённых файлов: 44 добавлений и 1 удалений

27
build/buildconfig.py Normal file
Просмотреть файл

@ -0,0 +1,27 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import imp
import os
import sys
path = os.path.dirname(__file__)
while not os.path.exists(os.path.join(path, 'config.status')):
parent = os.path.normpath(os.path.join(path, os.pardir))
if parent == path:
raise Exception("Can't find config.status")
path = parent
path = os.path.join(path, 'config.status')
config = imp.load_module('_buildconfig', open(path), path, ('', 'r', imp.PY_SOURCE))
for var in os.environ:
if var in config.substs:
config.substs[var] = os.environ[var]
for var in config.__all__:
value = getattr(config, var)
if isinstance(value, list) and isinstance(value[0], tuple):
value = dict(value)
setattr(sys.modules[__name__], var, value)

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

@ -12,3 +12,4 @@ optional:setup.py:python/psutil:build_ext:--inplace
optional:psutil.pth:python/psutil
mozilla.pth:build
mozilla.pth:config
copy:build/buildconfig.py

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

@ -7,6 +7,7 @@
from __future__ import with_statement
import os
import shutil
import subprocess
import sys
import distutils.sysconfig
@ -23,11 +24,16 @@ def populate_virtualenv(top_source_directory, manifest_filename, log_handle):
2. argument(s) to setup.py. e.g. "develop". Each program argument is
delimited by a colon. Arguments with colons are not yet supported.
filename.pth -- Adds the path given as argument to filename.pth under
the virtualenv site packages directory.
optional -- This denotes the action as optional. The requested action
is attempted. If it fails, we issue a warning and go on. The initial
"optional" field is stripped then the remaining line is processed
like normal. e.g. "optional:setup.py:python/foo:built_ext:-i"
copy -- Copies the given file in the virtualenv site packages directory.
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 into the wrong place.
@ -40,6 +46,7 @@ def populate_virtualenv(top_source_directory, manifest_filename, log_handle):
fh.close()
def handle_package(package):
python_lib = distutils.sysconfig.get_python_lib()
if package[0] == 'setup.py':
assert len(package) >= 2
@ -48,10 +55,18 @@ def populate_virtualenv(top_source_directory, manifest_filename, log_handle):
return True
if package[0] == 'copy':
assert len(package) == 2
shutil.copy(os.path.join(top_source_directory, package[1]),
os.path.join(python_lib, os.path.basename(package[1])))
return True
if package[0].endswith('.pth'):
assert len(package) == 2
with open(os.path.join(distutils.sysconfig.get_python_lib(), package[0]), 'a') as f:
with open(os.path.join(python_lib, package[0]), 'a') as f:
f.write("%s\n" % os.path.join(top_source_directory, package[1]))
return True