mirror of https://github.com/python/cpython
Added command description.
Added 'build_clib' and 'build_temp' options (where to put C libraries and where to put temporary compiler by-products, ie. object files). Moved the call to 'check_library_list()' from 'run()' to 'finalize_options()' -- that way, if we're going to crash we do so earlier, and we guarantee that the library list is valid before we do anything (not just run). Disallow directory separators in library names -- the compiled library always goes right in 'build_clib'. Added 'get_library_names()', so the "build_ext" command knows what libraries to link every extension with.
This commit is contained in:
parent
49ffce173e
commit
833dfd52e5
|
@ -28,12 +28,21 @@ from distutils.ccompiler import new_compiler
|
||||||
|
|
||||||
class build_lib (Command):
|
class build_lib (Command):
|
||||||
|
|
||||||
|
description = "build C/C++ libraries used by Python extensions"
|
||||||
|
|
||||||
user_options = [
|
user_options = [
|
||||||
|
('build-clib', 'b',
|
||||||
|
"directory to build C/C++ libraries to"),
|
||||||
|
('build-temp', 't',
|
||||||
|
"directory to put temporary build by-products"),
|
||||||
('debug', 'g',
|
('debug', 'g',
|
||||||
"compile with debugging information"),
|
"compile with debugging information"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def initialize_options (self):
|
def initialize_options (self):
|
||||||
|
self.build_clib = None
|
||||||
|
self.build_temp = None
|
||||||
|
|
||||||
# List of libraries to build
|
# List of libraries to build
|
||||||
self.libraries = None
|
self.libraries = None
|
||||||
|
|
||||||
|
@ -45,10 +54,23 @@ class build_lib (Command):
|
||||||
|
|
||||||
# initialize_options()
|
# initialize_options()
|
||||||
|
|
||||||
|
|
||||||
def finalize_options (self):
|
def finalize_options (self):
|
||||||
|
|
||||||
|
# This might be confusing: both build-clib and build-temp default
|
||||||
|
# to build-temp as defined by the "build" command. This is because
|
||||||
|
# I think that C libraries are really just temporary build
|
||||||
|
# by-products, at least from the point of view of building Python
|
||||||
|
# extensions -- but I want to keep my options open.
|
||||||
self.set_undefined_options ('build',
|
self.set_undefined_options ('build',
|
||||||
|
('build_temp', 'build_clib'),
|
||||||
|
('build_temp', 'build_temp'),
|
||||||
('debug', 'debug'))
|
('debug', 'debug'))
|
||||||
|
|
||||||
self.libraries = self.distribution.libraries
|
self.libraries = self.distribution.libraries
|
||||||
|
if self.libraries:
|
||||||
|
self.check_library_list (self.libraries)
|
||||||
|
|
||||||
if self.include_dirs is None:
|
if self.include_dirs is None:
|
||||||
self.include_dirs = self.distribution.include_dirs or []
|
self.include_dirs = self.distribution.include_dirs or []
|
||||||
if type (self.include_dirs) is StringType:
|
if type (self.include_dirs) is StringType:
|
||||||
|
@ -65,7 +87,6 @@ class build_lib (Command):
|
||||||
|
|
||||||
if not self.libraries:
|
if not self.libraries:
|
||||||
return
|
return
|
||||||
self.check_library_list (self.libraries)
|
|
||||||
|
|
||||||
# Yech -- this is cut 'n pasted from build_ext.py!
|
# Yech -- this is cut 'n pasted from build_ext.py!
|
||||||
self.compiler = new_compiler (plat=os.environ.get ('PLAT'),
|
self.compiler = new_compiler (plat=os.environ.get ('PLAT'),
|
||||||
|
@ -110,6 +131,12 @@ class build_lib (Command):
|
||||||
raise DistutilsValueError, \
|
raise DistutilsValueError, \
|
||||||
"first element of each tuple in 'libraries' " + \
|
"first element of each tuple in 'libraries' " + \
|
||||||
"must be a string (the library name)"
|
"must be a string (the library name)"
|
||||||
|
if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):
|
||||||
|
raise DistutilsValueError, \
|
||||||
|
("bad library name '%s': " +
|
||||||
|
"may not contain directory separators") % \
|
||||||
|
lib[0]
|
||||||
|
|
||||||
if type (lib[1]) is not DictionaryType:
|
if type (lib[1]) is not DictionaryType:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsValueError, \
|
||||||
"second element of each tuple in 'libraries' " + \
|
"second element of each tuple in 'libraries' " + \
|
||||||
|
@ -119,6 +146,21 @@ class build_lib (Command):
|
||||||
# check_library_list ()
|
# check_library_list ()
|
||||||
|
|
||||||
|
|
||||||
|
def get_library_names (self):
|
||||||
|
# Assume the library list is valid -- 'check_library_list()' is
|
||||||
|
# called from 'finalize_options()', so it should be!
|
||||||
|
|
||||||
|
if not self.libraries:
|
||||||
|
return None
|
||||||
|
|
||||||
|
lib_names = []
|
||||||
|
for (lib_name, build_info) in self.libraries:
|
||||||
|
lib_names.append (lib_name)
|
||||||
|
return lib_names
|
||||||
|
|
||||||
|
# get_library_names ()
|
||||||
|
|
||||||
|
|
||||||
def build_libraries (self, libraries):
|
def build_libraries (self, libraries):
|
||||||
|
|
||||||
compiler = self.compiler
|
compiler = self.compiler
|
||||||
|
@ -134,35 +176,27 @@ class build_lib (Command):
|
||||||
|
|
||||||
self.announce ("building '%s' library" % lib_name)
|
self.announce ("building '%s' library" % lib_name)
|
||||||
|
|
||||||
# Extract the directory the library is intended to go in --
|
|
||||||
# note translation from "universal" slash-separated form to
|
|
||||||
# current platform's pathname convention (so we can use the
|
|
||||||
# string for actual filesystem use).
|
|
||||||
path = tuple (string.split (lib_name, '/')[:-1])
|
|
||||||
if path:
|
|
||||||
lib_dir = apply (os.path.join, path)
|
|
||||||
else:
|
|
||||||
lib_dir = ''
|
|
||||||
|
|
||||||
# First, compile the source code to object files in the library
|
# First, compile the source code to object files in the library
|
||||||
# directory. (This should probably change to putting object
|
# directory. (This should probably change to putting object
|
||||||
# files in a temporary build directory.)
|
# files in a temporary build directory.)
|
||||||
macros = build_info.get ('macros')
|
macros = build_info.get ('macros')
|
||||||
include_dirs = build_info.get ('include_dirs')
|
include_dirs = build_info.get ('include_dirs')
|
||||||
objects = self.compiler.compile (sources,
|
objects = self.compiler.compile (sources,
|
||||||
|
output_dir=self.build_temp,
|
||||||
|
keep_dir=1,
|
||||||
macros=macros,
|
macros=macros,
|
||||||
include_dirs=include_dirs,
|
include_dirs=include_dirs,
|
||||||
output_dir=lib_dir,
|
|
||||||
debug=self.debug)
|
debug=self.debug)
|
||||||
|
|
||||||
# Now "link" the object files together into a static library.
|
# Now "link" the object files together into a static library.
|
||||||
# (On Unix at least, this isn't really linking -- it just
|
# (On Unix at least, this isn't really linking -- it just
|
||||||
# builds an archive. Whatever.)
|
# builds an archive. Whatever.)
|
||||||
self.compiler.link_static_lib (objects, lib_name, debug=self.debug)
|
self.compiler.link_static_lib (objects, lib_name,
|
||||||
|
output_dir=self.build_clib,
|
||||||
|
debug=self.debug)
|
||||||
|
|
||||||
# for libraries
|
# for libraries
|
||||||
|
|
||||||
# build_libraries ()
|
# build_libraries ()
|
||||||
|
|
||||||
|
|
||||||
# class BuildLib
|
# class BuildLib
|
||||||
|
|
|
@ -28,12 +28,21 @@ from distutils.ccompiler import new_compiler
|
||||||
|
|
||||||
class build_lib (Command):
|
class build_lib (Command):
|
||||||
|
|
||||||
|
description = "build C/C++ libraries used by Python extensions"
|
||||||
|
|
||||||
user_options = [
|
user_options = [
|
||||||
|
('build-clib', 'b',
|
||||||
|
"directory to build C/C++ libraries to"),
|
||||||
|
('build-temp', 't',
|
||||||
|
"directory to put temporary build by-products"),
|
||||||
('debug', 'g',
|
('debug', 'g',
|
||||||
"compile with debugging information"),
|
"compile with debugging information"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def initialize_options (self):
|
def initialize_options (self):
|
||||||
|
self.build_clib = None
|
||||||
|
self.build_temp = None
|
||||||
|
|
||||||
# List of libraries to build
|
# List of libraries to build
|
||||||
self.libraries = None
|
self.libraries = None
|
||||||
|
|
||||||
|
@ -45,10 +54,23 @@ class build_lib (Command):
|
||||||
|
|
||||||
# initialize_options()
|
# initialize_options()
|
||||||
|
|
||||||
|
|
||||||
def finalize_options (self):
|
def finalize_options (self):
|
||||||
|
|
||||||
|
# This might be confusing: both build-clib and build-temp default
|
||||||
|
# to build-temp as defined by the "build" command. This is because
|
||||||
|
# I think that C libraries are really just temporary build
|
||||||
|
# by-products, at least from the point of view of building Python
|
||||||
|
# extensions -- but I want to keep my options open.
|
||||||
self.set_undefined_options ('build',
|
self.set_undefined_options ('build',
|
||||||
|
('build_temp', 'build_clib'),
|
||||||
|
('build_temp', 'build_temp'),
|
||||||
('debug', 'debug'))
|
('debug', 'debug'))
|
||||||
|
|
||||||
self.libraries = self.distribution.libraries
|
self.libraries = self.distribution.libraries
|
||||||
|
if self.libraries:
|
||||||
|
self.check_library_list (self.libraries)
|
||||||
|
|
||||||
if self.include_dirs is None:
|
if self.include_dirs is None:
|
||||||
self.include_dirs = self.distribution.include_dirs or []
|
self.include_dirs = self.distribution.include_dirs or []
|
||||||
if type (self.include_dirs) is StringType:
|
if type (self.include_dirs) is StringType:
|
||||||
|
@ -65,7 +87,6 @@ class build_lib (Command):
|
||||||
|
|
||||||
if not self.libraries:
|
if not self.libraries:
|
||||||
return
|
return
|
||||||
self.check_library_list (self.libraries)
|
|
||||||
|
|
||||||
# Yech -- this is cut 'n pasted from build_ext.py!
|
# Yech -- this is cut 'n pasted from build_ext.py!
|
||||||
self.compiler = new_compiler (plat=os.environ.get ('PLAT'),
|
self.compiler = new_compiler (plat=os.environ.get ('PLAT'),
|
||||||
|
@ -110,6 +131,12 @@ class build_lib (Command):
|
||||||
raise DistutilsValueError, \
|
raise DistutilsValueError, \
|
||||||
"first element of each tuple in 'libraries' " + \
|
"first element of each tuple in 'libraries' " + \
|
||||||
"must be a string (the library name)"
|
"must be a string (the library name)"
|
||||||
|
if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):
|
||||||
|
raise DistutilsValueError, \
|
||||||
|
("bad library name '%s': " +
|
||||||
|
"may not contain directory separators") % \
|
||||||
|
lib[0]
|
||||||
|
|
||||||
if type (lib[1]) is not DictionaryType:
|
if type (lib[1]) is not DictionaryType:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsValueError, \
|
||||||
"second element of each tuple in 'libraries' " + \
|
"second element of each tuple in 'libraries' " + \
|
||||||
|
@ -119,6 +146,21 @@ class build_lib (Command):
|
||||||
# check_library_list ()
|
# check_library_list ()
|
||||||
|
|
||||||
|
|
||||||
|
def get_library_names (self):
|
||||||
|
# Assume the library list is valid -- 'check_library_list()' is
|
||||||
|
# called from 'finalize_options()', so it should be!
|
||||||
|
|
||||||
|
if not self.libraries:
|
||||||
|
return None
|
||||||
|
|
||||||
|
lib_names = []
|
||||||
|
for (lib_name, build_info) in self.libraries:
|
||||||
|
lib_names.append (lib_name)
|
||||||
|
return lib_names
|
||||||
|
|
||||||
|
# get_library_names ()
|
||||||
|
|
||||||
|
|
||||||
def build_libraries (self, libraries):
|
def build_libraries (self, libraries):
|
||||||
|
|
||||||
compiler = self.compiler
|
compiler = self.compiler
|
||||||
|
@ -134,35 +176,27 @@ class build_lib (Command):
|
||||||
|
|
||||||
self.announce ("building '%s' library" % lib_name)
|
self.announce ("building '%s' library" % lib_name)
|
||||||
|
|
||||||
# Extract the directory the library is intended to go in --
|
|
||||||
# note translation from "universal" slash-separated form to
|
|
||||||
# current platform's pathname convention (so we can use the
|
|
||||||
# string for actual filesystem use).
|
|
||||||
path = tuple (string.split (lib_name, '/')[:-1])
|
|
||||||
if path:
|
|
||||||
lib_dir = apply (os.path.join, path)
|
|
||||||
else:
|
|
||||||
lib_dir = ''
|
|
||||||
|
|
||||||
# First, compile the source code to object files in the library
|
# First, compile the source code to object files in the library
|
||||||
# directory. (This should probably change to putting object
|
# directory. (This should probably change to putting object
|
||||||
# files in a temporary build directory.)
|
# files in a temporary build directory.)
|
||||||
macros = build_info.get ('macros')
|
macros = build_info.get ('macros')
|
||||||
include_dirs = build_info.get ('include_dirs')
|
include_dirs = build_info.get ('include_dirs')
|
||||||
objects = self.compiler.compile (sources,
|
objects = self.compiler.compile (sources,
|
||||||
|
output_dir=self.build_temp,
|
||||||
|
keep_dir=1,
|
||||||
macros=macros,
|
macros=macros,
|
||||||
include_dirs=include_dirs,
|
include_dirs=include_dirs,
|
||||||
output_dir=lib_dir,
|
|
||||||
debug=self.debug)
|
debug=self.debug)
|
||||||
|
|
||||||
# Now "link" the object files together into a static library.
|
# Now "link" the object files together into a static library.
|
||||||
# (On Unix at least, this isn't really linking -- it just
|
# (On Unix at least, this isn't really linking -- it just
|
||||||
# builds an archive. Whatever.)
|
# builds an archive. Whatever.)
|
||||||
self.compiler.link_static_lib (objects, lib_name, debug=self.debug)
|
self.compiler.link_static_lib (objects, lib_name,
|
||||||
|
output_dir=self.build_clib,
|
||||||
|
debug=self.debug)
|
||||||
|
|
||||||
# for libraries
|
# for libraries
|
||||||
|
|
||||||
# build_libraries ()
|
# build_libraries ()
|
||||||
|
|
||||||
|
|
||||||
# class BuildLib
|
# class BuildLib
|
||||||
|
|
Loading…
Reference in New Issue