diff options
author | Armin Rigo <arigo@tunes.org> | 2012-09-17 21:11:26 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2012-09-17 21:11:26 +0200 |
commit | d3834ce225fdd1091386f2d3b4105b540f982d32 (patch) | |
tree | 14a86442a608e1243e0d6fcfa8abf91a5333c7da /cffi/ffiplatform.py | |
parent | 8f3c7c408127b229b1d7f0cf2ed81c4087b938f7 (diff) | |
download | cffi-d3834ce225fdd1091386f2d3b4105b540f982d32.tar.gz |
Don't use os.chdir(). Instead, give the tmpdir as options
to distutils, which seems to work.
Diffstat (limited to 'cffi/ffiplatform.py')
-rw-r--r-- | cffi/ffiplatform.py | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/cffi/ffiplatform.py b/cffi/ffiplatform.py index a76a20f..b3eef21 100644 --- a/cffi/ffiplatform.py +++ b/cffi/ffiplatform.py @@ -20,23 +20,11 @@ def get_extension(srcfilename, modname, sources=(), **kwds): def compile(tmpdir, ext): """Compile a C extension module using distutils.""" - # Turn the 'ext.sources' into absolute paths, because we're going to - # do chdir(). In the common case where the path is precisely where - # we're going to chdir(), then replace it with a pathless copy. - for i, src in enumerate(ext.sources): - src = os.path.abspath(src) - if samefile(os.path.dirname(src), tmpdir): - src = os.path.basename(src) - ext.sources[i] = src - saved_environ = os.environ.copy() - saved_path = os.getcwd() try: - os.chdir(tmpdir) - outputfilename = _build(ext) + outputfilename = _build(tmpdir, ext) outputfilename = os.path.abspath(outputfilename) finally: - os.chdir(saved_path) # workaround for a distutils bugs where some env vars can # become longer and longer every time it is used for key, value in saved_environ.items(): @@ -44,7 +32,7 @@ def compile(tmpdir, ext): os.environ[key] = value return outputfilename -def _build(ext): +def _build(tmpdir, ext): # XXX compact but horrible :-( from distutils.core import Distribution import distutils.errors @@ -52,6 +40,8 @@ def _build(ext): dist = Distribution({'ext_modules': [ext]}) options = dist.get_option_dict('build_ext') options['force'] = ('ffiplatform', True) + options['build_lib'] = ('ffiplatform', tmpdir) + options['build_temp'] = ('ffiplatform', tmpdir) # try: dist.run_command('build_ext') |