Kaydet (Commit) 49c99423 authored tarafından Marc-André Lemburg's avatar Marc-André Lemburg

Added an execution layer to be able to customize per-extension

building.
üst d30e587e
...@@ -356,104 +356,105 @@ class build_ext (Command): ...@@ -356,104 +356,105 @@ class build_ext (Command):
# get_outputs () # get_outputs ()
def build_extensions(self):
def build_extensions (self):
# First, sanity-check the 'extensions' list # First, sanity-check the 'extensions' list
self.check_extensions_list(self.extensions) self.check_extensions_list(self.extensions)
for ext in self.extensions: for ext in self.extensions:
sources = ext.sources self.build_extension(ext)
if sources is None or type(sources) not in (ListType, TupleType):
raise DistutilsSetupError, \
("in 'ext_modules' option (extension '%s'), " +
"'sources' must be present and must be " +
"a list of source filenames") % ext.name
sources = list(sources)
fullname = self.get_ext_fullname(ext.name) def build_extension(self, ext):
if self.inplace:
# ignore build-lib -- put the compiled extension into
# the source tree along with pure Python modules
modpath = string.split(fullname, '.')
package = string.join(modpath[0:-1], '.')
base = modpath[-1]
build_py = self.get_finalized_command('build_py')
package_dir = build_py.get_package_dir(package)
ext_filename = os.path.join(package_dir,
self.get_ext_filename(base))
else:
ext_filename = os.path.join(self.build_lib,
self.get_ext_filename(fullname))
if not (self.force or newer_group(sources, ext_filename, 'newer')): sources = ext.sources
self.announce("skipping '%s' extension (up-to-date)" % if sources is None or type(sources) not in (ListType, TupleType):
ext.name) raise DistutilsSetupError, \
continue # 'for' loop over all extensions ("in 'ext_modules' option (extension '%s'), " +
else: "'sources' must be present and must be " +
self.announce("building '%s' extension" % ext.name) "a list of source filenames") % ext.name
sources = list(sources)
# First, scan the sources for SWIG definition files (.i), run
# SWIG on 'em to create .c files, and modify the sources list fullname = self.get_ext_fullname(ext.name)
# accordingly. if self.inplace:
sources = self.swig_sources(sources) # ignore build-lib -- put the compiled extension into
# the source tree along with pure Python modules
# Next, compile the source code to object files.
modpath = string.split(fullname, '.')
# XXX not honouring 'define_macros' or 'undef_macros' -- the package = string.join(modpath[0:-1], '.')
# CCompiler API needs to change to accommodate this, and I base = modpath[-1]
# want to do one thing at a time!
build_py = self.get_finalized_command('build_py')
# Two possible sources for extra compiler arguments: package_dir = build_py.get_package_dir(package)
# - 'extra_compile_args' in Extension object ext_filename = os.path.join(package_dir,
# - CFLAGS environment variable (not particularly self.get_ext_filename(base))
# elegant, but people seem to expect it and I else:
# guess it's useful) ext_filename = os.path.join(self.build_lib,
# The environment variable should take precedence, and self.get_ext_filename(fullname))
# any sensible compiler will give precedence to later
# command line args. Hence we combine them in order: if not (self.force or newer_group(sources, ext_filename, 'newer')):
extra_args = ext.extra_compile_args or [] self.announce("skipping '%s' extension (up-to-date)" %
ext.name)
macros = ext.define_macros[:] return
for undef in ext.undef_macros: else:
macros.append((undef,)) self.announce("building '%s' extension" % ext.name)
# XXX and if we support CFLAGS, why not CC (compiler # First, scan the sources for SWIG definition files (.i), run
# executable), CPPFLAGS (pre-processor options), and LDFLAGS # SWIG on 'em to create .c files, and modify the sources list
# (linker options) too? # accordingly.
# XXX should we use shlex to properly parse CFLAGS? sources = self.swig_sources(sources)
if os.environ.has_key('CFLAGS'): # Next, compile the source code to object files.
extra_args.extend(string.split(os.environ['CFLAGS']))
# XXX not honouring 'define_macros' or 'undef_macros' -- the
objects = self.compiler.compile(sources, # CCompiler API needs to change to accommodate this, and I
output_dir=self.build_temp, # want to do one thing at a time!
macros=macros,
include_dirs=ext.include_dirs, # Two possible sources for extra compiler arguments:
debug=self.debug, # - 'extra_compile_args' in Extension object
extra_postargs=extra_args) # - CFLAGS environment variable (not particularly
# elegant, but people seem to expect it and I
# Now link the object files together into a "shared object" -- # guess it's useful)
# of course, first we have to figure out all the other things # The environment variable should take precedence, and
# that go into the mix. # any sensible compiler will give precedence to later
if ext.extra_objects: # command line args. Hence we combine them in order:
objects.extend(ext.extra_objects) extra_args = ext.extra_compile_args or []
extra_args = ext.extra_link_args or []
macros = ext.define_macros[:]
for undef in ext.undef_macros:
self.compiler.link_shared_object( macros.append((undef,))
objects, ext_filename,
libraries=self.get_libraries(ext), # XXX and if we support CFLAGS, why not CC (compiler
library_dirs=ext.library_dirs, # executable), CPPFLAGS (pre-processor options), and LDFLAGS
runtime_library_dirs=ext.runtime_library_dirs, # (linker options) too?
extra_postargs=extra_args, # XXX should we use shlex to properly parse CFLAGS?
export_symbols=self.get_export_symbols(ext),
debug=self.debug, if os.environ.has_key('CFLAGS'):
build_temp=self.build_temp) extra_args.extend(string.split(os.environ['CFLAGS']))
# build_extensions () objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=extra_args)
# Now link the object files together into a "shared object" --
# of course, first we have to figure out all the other things
# that go into the mix.
if ext.extra_objects:
objects.extend(ext.extra_objects)
extra_args = ext.extra_link_args or []
self.compiler.link_shared_object(
objects, ext_filename,
libraries=self.get_libraries(ext),
library_dirs=ext.library_dirs,
runtime_library_dirs=ext.runtime_library_dirs,
extra_postargs=extra_args,
export_symbols=self.get_export_symbols(ext),
debug=self.debug,
build_temp=self.build_temp)
def swig_sources (self, sources): def swig_sources (self, sources):
......
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