mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Make setup.py work when building in a directory other than the
source directory. Mainly, use 'srcdir' rather than os.getcwd() or '.'.
This commit is contained in:
parent
c03a288181
commit
014bf28ef1
1 changed files with 9 additions and 24 deletions
33
setup.py
33
setup.py
|
@ -112,51 +112,36 @@ class PyBuildExt(build_ext):
|
||||||
self.extensions = extensions
|
self.extensions = extensions
|
||||||
|
|
||||||
# Fix up the autodetected modules, prefixing all the source files
|
# Fix up the autodetected modules, prefixing all the source files
|
||||||
# with Modules/ and adding Python's include directory to the path.
|
# with Modules/.
|
||||||
(srcdir,) = sysconfig.get_config_vars('srcdir')
|
srcdir = sysconfig.get_config_var('srcdir')
|
||||||
if not srcdir:
|
if not srcdir:
|
||||||
# Maybe running on Windows but not using CYGWIN?
|
# Maybe running on Windows but not using CYGWIN?
|
||||||
raise ValueError("No source directory; cannot proceed.")
|
raise ValueError("No source directory; cannot proceed.")
|
||||||
|
|
||||||
# Figure out the location of the source code for extension modules
|
|
||||||
# (This logic is copied in distutils.test.test_sysconfig,
|
|
||||||
# so building in a separate directory does not break test_distutils.)
|
|
||||||
moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
|
|
||||||
moddir = os.path.normpath(moddir)
|
|
||||||
srcdir, tail = os.path.split(moddir)
|
|
||||||
srcdir = os.path.normpath(srcdir)
|
srcdir = os.path.normpath(srcdir)
|
||||||
moddir = os.path.normpath(moddir)
|
moddirlist = [os.path.join(srcdir, 'Modules')]
|
||||||
|
|
||||||
moddirlist = [moddir]
|
|
||||||
incdirlist = ['./Include']
|
|
||||||
|
|
||||||
# Platform-dependent module source and include directories
|
# Platform-dependent module source and include directories
|
||||||
platform = self.get_platform()
|
platform = self.get_platform()
|
||||||
|
|
||||||
alldirlist = moddirlist + incdirlist
|
|
||||||
|
|
||||||
# Fix up the paths for scripts, too
|
# Fix up the paths for scripts, too
|
||||||
self.distribution.scripts = [os.path.join(srcdir, filename)
|
self.distribution.scripts = [os.path.join(srcdir, filename)
|
||||||
for filename in self.distribution.scripts]
|
for filename in self.distribution.scripts]
|
||||||
|
|
||||||
# Python header files
|
# Python header files
|
||||||
headers = glob("Include/*.h") + ["pyconfig.h"]
|
headers = [sysconfig.get_config_h_filename()]
|
||||||
|
headers += glob(os.path.join(sysconfig.get_python_inc(), "*.h"))
|
||||||
|
|
||||||
for ext in self.extensions[:]:
|
for ext in self.extensions[:]:
|
||||||
ext.sources = [ find_module_file(filename, moddirlist)
|
ext.sources = [ find_module_file(filename, moddirlist)
|
||||||
for filename in ext.sources ]
|
for filename in ext.sources ]
|
||||||
if ext.depends is not None:
|
if ext.depends is not None:
|
||||||
ext.depends = [find_module_file(filename, alldirlist)
|
ext.depends = [find_module_file(filename, moddirlist)
|
||||||
for filename in ext.depends]
|
for filename in ext.depends]
|
||||||
else:
|
else:
|
||||||
ext.depends = []
|
ext.depends = []
|
||||||
# re-compile extensions if a header file has been changed
|
# re-compile extensions if a header file has been changed
|
||||||
ext.depends.extend(headers)
|
ext.depends.extend(headers)
|
||||||
|
|
||||||
ext.include_dirs.append( '.' ) # to get config.h
|
|
||||||
for incdir in incdirlist:
|
|
||||||
ext.include_dirs.append( os.path.join(srcdir, incdir) )
|
|
||||||
|
|
||||||
# If a module has already been built statically,
|
# If a module has already been built statically,
|
||||||
# don't build it here
|
# don't build it here
|
||||||
if ext.name in sys.builtin_module_names:
|
if ext.name in sys.builtin_module_names:
|
||||||
|
@ -368,7 +353,7 @@ class PyBuildExt(build_ext):
|
||||||
config_h_vars = sysconfig.parse_config_h(open(config_h))
|
config_h_vars = sysconfig.parse_config_h(open(config_h))
|
||||||
|
|
||||||
platform = self.get_platform()
|
platform = self.get_platform()
|
||||||
(srcdir,) = sysconfig.get_config_vars('srcdir')
|
srcdir = sysconfig.get_config_var('srcdir')
|
||||||
|
|
||||||
# Check for AtheOS which has libraries in non-standard locations
|
# Check for AtheOS which has libraries in non-standard locations
|
||||||
if platform == 'atheos':
|
if platform == 'atheos':
|
||||||
|
@ -1285,7 +1270,7 @@ class PyBuildExt(build_ext):
|
||||||
def configure_ctypes_darwin(self, ext):
|
def configure_ctypes_darwin(self, ext):
|
||||||
# Darwin (OS X) uses preconfigured files, in
|
# Darwin (OS X) uses preconfigured files, in
|
||||||
# the Modules/_ctypes/libffi_osx directory.
|
# the Modules/_ctypes/libffi_osx directory.
|
||||||
(srcdir,) = sysconfig.get_config_vars('srcdir')
|
srcdir = sysconfig.get_config_var('srcdir')
|
||||||
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
|
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
|
||||||
'_ctypes', 'libffi_osx'))
|
'_ctypes', 'libffi_osx'))
|
||||||
sources = [os.path.join(ffi_srcdir, p)
|
sources = [os.path.join(ffi_srcdir, p)
|
||||||
|
@ -1314,7 +1299,7 @@ class PyBuildExt(build_ext):
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
return self.configure_ctypes_darwin(ext)
|
return self.configure_ctypes_darwin(ext)
|
||||||
|
|
||||||
(srcdir,) = sysconfig.get_config_vars('srcdir')
|
srcdir = sysconfig.get_config_var('srcdir')
|
||||||
ffi_builddir = os.path.join(self.build_temp, 'libffi')
|
ffi_builddir = os.path.join(self.build_temp, 'libffi')
|
||||||
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
|
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
|
||||||
'_ctypes', 'libffi'))
|
'_ctypes', 'libffi'))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue