Commit 40c0f5e6 authored by PJ Eby's avatar PJ Eby

Write stub files correctly for build_ext --inplace

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4042036
parent 181ffb61
......@@ -10,6 +10,7 @@ from distutils.file_util import copy_file
from setuptools.extension import Library
from distutils.ccompiler import new_compiler
from distutils.sysconfig import customize_compiler
from distutils import log
have_rtld = False
libtype = 'shared'
......@@ -38,7 +39,6 @@ if os.name != 'nt':
class build_ext(_build_ext):
def run(self):
"""Build extensions in build directory, then copy if --inplace"""
......@@ -50,7 +50,7 @@ class build_ext(_build_ext):
def copy_extensions_to_source(self):
build_py = self.get_finalized_command('build_py')
for ext in self.extensions or ():
for ext in self.extensions:
fullname = self.get_ext_fullname(ext.name)
filename = self.get_ext_filename(fullname)
modpath = fullname.split('.')
......@@ -66,6 +66,9 @@ class build_ext(_build_ext):
src_filename, dest_filename, verbose=self.verbose,
dry_run=self.dry_run
)
if ext._needs_stub:
self.write_stub(package_dir, ext, False)
if _build_ext is not _du_build_ext:
# Workaround for problems using some Pyrex versions w/SWIG and/or 2.4
......@@ -77,16 +80,13 @@ class build_ext(_build_ext):
def get_ext_filename(self, fullname):
filename = _build_ext.get_ext_filename(self,fullname)
ext = self.ext_map[fullname]
if isinstance(ext,Library):
fn, ext = os.path.splitext(filename)
return self.shlib_compiler.library_filename(fn,libtype)
elif have_rtld and ext.links_to_dynamic:
elif have_rtld and ext._links_to_dynamic:
d,fn = os.path.split(filename)
return os.path.join(d,'dl-'+fn)
else:
......@@ -100,18 +100,19 @@ class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
self.check_extensions_list(self.extensions)
self.shlibs = [ext for ext in self.extensions or ()
self.extensions = self.extensions or []
self.check_extensions_list()
self.shlibs = [ext for ext in self.extensions
if isinstance(ext,Library)]
if self.shlibs:
self.setup_shlib_compiler()
for ext in self.extensions:
fullname = ext._full_name = self.get_ext_fullname(ext.name)
self.ext_map[fullname] = ext
filename = ext._file_name = self.get_ext_filename(fullname)
ltd = ext._links_to_dynamic = \
self.shlibs and self.links_to_dynamic(ext) or False
ext._needs_stub = ltd and have_rtld and not isinstance(ext,Library)
filename = ext._file_name = self.get_ext_filename(fullname)
libdir = os.path.dirname(os.path.join(self.build_lib,filename))
if ltd and libdir not in ext.library_dirs:
ext.library_dirs.append(libdir)
......@@ -120,7 +121,6 @@ class build_ext(_build_ext):
def setup_shlib_compiler(self):
compiler = self.shlib_compiler = new_compiler(
compiler=self.compiler, dry_run=self.dry_run, force=self.force
......@@ -169,14 +169,13 @@ class build_ext(_build_ext):
self.compiler = self.shlib_compiler
_build_ext.build_extension(self,ext)
if ext._needs_stub:
self.write_stub(ext)
self.write_stub(self.build_lib, ext)
finally:
self.compiler = _compiler
def write_stub(self, ext):
def write_stub(self, output_dir, ext, compile=True):
log.info("writing stub loader for %s",ext._full_name)
stub_file = os.path.join(self.build_lib, *ext._full_name.split('.'))
stub_file += '.py'
stub_file = os.path.join(output_dir, *ext._full_name.split('.'))+'.py'
if not self.dry_run:
f = open(stub_file,'w')
f.write('\n'.join([
......@@ -201,6 +200,7 @@ class build_ext(_build_ext):
"" # terminal \n
]))
f.close()
if compile:
self.get_finalized_command('build_py').byte_compile(stub_file)
def links_to_dynamic(self, ext):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment