mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
Some option changes:
- rename 'dir' to 'build_dir' - take 'package' from distribution option 'ext_package' - take 'extensions' from distribution option 'ext_modules' - take 'include_dirs' from distribution Name keyword args explictly when calling CCompiler methods. Overhauled how we generate extension filenames (in 'extension_filename() and 'build_extension()') to take 'package' option into account.
This commit is contained in:
parent
17dc6e7ed8
commit
dbb96253ea
1 changed files with 30 additions and 17 deletions
|
@ -16,9 +16,10 @@ from distutils.sysconfig import INCLUDEPY, SO, exec_prefix
|
||||||
from distutils.errors import *
|
from distutils.errors import *
|
||||||
|
|
||||||
|
|
||||||
# This is the same as a Python NAME, since we must accept any
|
# An extension name is just a dot-separated list of Python NAMEs (ie.
|
||||||
# valid module name for the extension name.
|
# the same as a fully-qualified module name).
|
||||||
extension_name_re = re.compile (r'^[a-zA-Z_][a-zA-Z_0-9]*$')
|
extension_name_re = re.compile \
|
||||||
|
(r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
|
||||||
|
|
||||||
|
|
||||||
class BuildExt (Command):
|
class BuildExt (Command):
|
||||||
|
@ -41,7 +42,7 @@ class BuildExt (Command):
|
||||||
# takes care of both command-line and client options
|
# takes care of both command-line and client options
|
||||||
# in between set_default_options() and set_final_options())
|
# in between set_default_options() and set_final_options())
|
||||||
|
|
||||||
options = [('dir=', 'd',
|
options = [('build-dir=', 'd',
|
||||||
"directory for compiled extension modules"),
|
"directory for compiled extension modules"),
|
||||||
('include-dirs=', 'I',
|
('include-dirs=', 'I',
|
||||||
"list of directories to search for header files"),
|
"list of directories to search for header files"),
|
||||||
|
@ -57,12 +58,14 @@ class BuildExt (Command):
|
||||||
"directories to search for shared C libraries at runtime"),
|
"directories to search for shared C libraries at runtime"),
|
||||||
('link-objects=', 'O',
|
('link-objects=', 'O',
|
||||||
"extra explicit link objects to include in the link"),
|
"extra explicit link objects to include in the link"),
|
||||||
|
('package=', 'p',
|
||||||
|
"Python package to put extension modules into"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def set_default_options (self):
|
def set_default_options (self):
|
||||||
self.extensions = None
|
self.extensions = None
|
||||||
self.dir = None
|
self.build_dir = None
|
||||||
self.package = None
|
self.package = None
|
||||||
|
|
||||||
self.include_dirs = None
|
self.include_dirs = None
|
||||||
|
@ -74,10 +77,13 @@ class BuildExt (Command):
|
||||||
self.link_objects = None
|
self.link_objects = None
|
||||||
|
|
||||||
def set_final_options (self):
|
def set_final_options (self):
|
||||||
self.set_undefined_options ('build', ('platdir', 'dir'))
|
self.set_undefined_options ('build', ('platdir', 'build_dir'))
|
||||||
|
|
||||||
if self.package is None:
|
if self.package is None:
|
||||||
self.package = ''
|
self.package = self.distribution.ext_package
|
||||||
|
|
||||||
|
self.extensions = self.distribution.ext_modules
|
||||||
|
|
||||||
|
|
||||||
# Make sure Python's include directories (for Python.h, config.h,
|
# Make sure Python's include directories (for Python.h, config.h,
|
||||||
# etc.) are in the include search path. We have to roll our own
|
# etc.) are in the include search path. We have to roll our own
|
||||||
|
@ -87,7 +93,7 @@ class BuildExt (Command):
|
||||||
exec_py_include = os.path.join (exec_prefix, 'include',
|
exec_py_include = os.path.join (exec_prefix, 'include',
|
||||||
'python' + sys.version[0:3])
|
'python' + sys.version[0:3])
|
||||||
if self.include_dirs is None:
|
if self.include_dirs is None:
|
||||||
self.include_dirs = []
|
self.include_dirs = self.distribution.include_dirs or []
|
||||||
self.include_dirs.insert (0, py_include)
|
self.include_dirs.insert (0, py_include)
|
||||||
if exec_py_include != py_include:
|
if exec_py_include != py_include:
|
||||||
self.include_dirs.insert (0, exec_py_include)
|
self.include_dirs.insert (0, exec_py_include)
|
||||||
|
@ -177,7 +183,9 @@ class BuildExt (Command):
|
||||||
|
|
||||||
macros = build_info.get ('macros')
|
macros = build_info.get ('macros')
|
||||||
include_dirs = build_info.get ('include_dirs')
|
include_dirs = build_info.get ('include_dirs')
|
||||||
self.compiler.compile (sources, macros, include_dirs)
|
self.compiler.compile (sources,
|
||||||
|
macros=macros,
|
||||||
|
includes=include_dirs)
|
||||||
|
|
||||||
objects = self.compiler.object_filenames (sources)
|
objects = self.compiler.object_filenames (sources)
|
||||||
extra_objects = build_info.get ('extra_objects')
|
extra_objects = build_info.get ('extra_objects')
|
||||||
|
@ -185,18 +193,23 @@ class BuildExt (Command):
|
||||||
objects.extend (extra_objects)
|
objects.extend (extra_objects)
|
||||||
libraries = build_info.get ('libraries')
|
libraries = build_info.get ('libraries')
|
||||||
library_dirs = build_info.get ('library_dirs')
|
library_dirs = build_info.get ('library_dirs')
|
||||||
ext_filename = self.extension_filename (extension_name)
|
ext_filename = self.extension_filename \
|
||||||
dest = os.path.dirname (
|
(extension_name, self.package)
|
||||||
os.path.join (self.dir, self.package, ext_filename))
|
ext_filename = os.path.join (self.build_dir, ext_filename)
|
||||||
self.mkpath (dest)
|
dest_dir = os.path.dirname (ext_filename)
|
||||||
self.compiler.link_shared_object (objects, ext_filename, dest,
|
self.mkpath (dest_dir)
|
||||||
libraries, library_dirs,
|
self.compiler.link_shared_object (objects, ext_filename,
|
||||||
|
libraries=libraries,
|
||||||
|
library_dirs=library_dirs,
|
||||||
build_info=build_info) # XXX hack!
|
build_info=build_info) # XXX hack!
|
||||||
|
|
||||||
# build_extensions ()
|
# build_extensions ()
|
||||||
|
|
||||||
|
|
||||||
def extension_filename (self, ext_name):
|
def extension_filename (self, ext_name, package=None):
|
||||||
return ext_name + SO
|
if package:
|
||||||
|
ext_name = package + '.' + ext_name
|
||||||
|
ext_path = string.split (ext_name, '.')
|
||||||
|
return apply (os.path.join, ext_path) + SO
|
||||||
|
|
||||||
# class BuildExt
|
# class BuildExt
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue