diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-12-27 12:46:59 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-12-27 12:46:59 -0500 |
commit | a78f0158a28734f965218b834ea8c0b166b7353f (patch) | |
tree | dca70268e2a41d49658e7eed783c6fc243d119cd /setup.py | |
parent | ec8e6895a3ce9cd69b6ceb75a15fcc74d4a522dc (diff) | |
parent | bf64d9064ab641b1ef9a0c4bda097ebf1204faf4 (diff) | |
download | cpython-git-revert-23107-revert-13893-fix-issue-37193.tar.gz |
Merge branch 'master' into revert-23107-revert-13893-fix-issue-37193revert-23107-revert-13893-fix-issue-37193
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 152 |
1 files changed, 63 insertions, 89 deletions
@@ -9,6 +9,7 @@ import re import sys import sysconfig from glob import glob, escape +import _osx_support try: @@ -178,32 +179,9 @@ def macosx_sdk_root(): MACOS_SDK_ROOT = m.group(1) MACOS_SDK_SPECIFIED = MACOS_SDK_ROOT != '/' else: - MACOS_SDK_ROOT = '/' + MACOS_SDK_ROOT = _osx_support._default_sysroot( + sysconfig.get_config_var('CC')) MACOS_SDK_SPECIFIED = False - cc = sysconfig.get_config_var('CC') - tmpfile = '/tmp/setup_sdk_root.%d' % os.getpid() - try: - os.unlink(tmpfile) - except: - pass - ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile)) - in_incdirs = False - try: - if ret == 0: - with open(tmpfile) as fp: - for line in fp.readlines(): - if line.startswith("#include <...>"): - in_incdirs = True - elif line.startswith("End of search list"): - in_incdirs = False - elif in_incdirs: - line = line.strip() - if line == '/usr/include': - MACOS_SDK_ROOT = '/' - elif line.endswith(".sdk/usr/include"): - MACOS_SDK_ROOT = line[:-12] - finally: - os.unlink(tmpfile) return MACOS_SDK_ROOT @@ -239,6 +217,13 @@ def is_macosx_sdk_path(path): or path.startswith('/Library/') ) +def grep_headers_for(function, headers): + for header in headers: + with open(header, 'r', errors='surrogateescape') as f: + if function in f.read(): + return True + return False + def find_file(filename, std_dirs, paths): """Searches for the directory where a given file is located, and returns a possibly-empty list of additional directories, or None @@ -869,8 +854,6 @@ class PyBuildExt(build_ext): # C-optimized pickle replacement self.add(Extension("_pickle", ["_pickle.c"], extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) - # atexit - self.add(Extension("atexit", ["atexitmodule.c"])) # _json speedups self.add(Extension("_json", ["_json.c"], extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) @@ -1030,7 +1013,7 @@ class PyBuildExt(build_ext): os_release = int(os.uname()[2].split('.')[0]) dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') if (dep_target and - (tuple(int(n) for n in dep_target.split('.')[0:2]) + (tuple(int(n) for n in str(dep_target).split('.')[0:2]) < (10, 5) ) ): os_release = 8 if os_release < 9: @@ -1147,18 +1130,12 @@ class PyBuildExt(build_ext): def detect_socket(self): # socket(2) - if not VXWORKS: - kwargs = {'depends': ['socketmodule.h']} - if MACOS: - # Issue #35569: Expose RFC 3542 socket options. - kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542'] - - self.add(Extension('_socket', ['socketmodule.c'], **kwargs)) - elif self.compiler.find_library_file(self.lib_dirs, 'net'): - libs = ['net'] - self.add(Extension('_socket', ['socketmodule.c'], - depends=['socketmodule.h'], - libraries=libs)) + kwargs = {'depends': ['socketmodule.h']} + if MACOS: + # Issue #35569: Expose RFC 3542 socket options. + kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542'] + + self.add(Extension('_socket', ['socketmodule.c'], **kwargs)) def detect_dbm_gdbm(self): # Modules that provide persistent dictionary-like semantics. You will @@ -1824,8 +1801,16 @@ class PyBuildExt(build_ext): ## self.add(Extension('xx', ['xxmodule.c'])) if 'd' not in sysconfig.get_config_var('ABIFLAGS'): + # Non-debug mode: Build xxlimited with limited API self.add(Extension('xxlimited', ['xxlimited.c'], + define_macros=[('Py_LIMITED_API', '0x03100000')])) + self.add(Extension('xxlimited_35', ['xxlimited_35.c'], define_macros=[('Py_LIMITED_API', '0x03050000')])) + else: + # Debug mode: Build xxlimited with the full API + # (which is compatible with the limited one) + self.add(Extension('xxlimited', ['xxlimited.c'])) + self.add(Extension('xxlimited_35', ['xxlimited_35.c'])) def detect_tkinter_explicitly(self): # Build _tkinter using explicit locations for Tcl/Tk. @@ -2105,43 +2090,17 @@ class PyBuildExt(build_ext): library_dirs=added_lib_dirs)) return True - def configure_ctypes_darwin(self, ext): - # Darwin (OS X) uses preconfigured files, in - # the Modules/_ctypes/libffi_osx directory. - ffi_srcdir = os.path.abspath(os.path.join(self.srcdir, 'Modules', - '_ctypes', 'libffi_osx')) - sources = [os.path.join(ffi_srcdir, p) - for p in ['ffi.c', - 'x86/darwin64.S', - 'x86/x86-darwin.S', - 'x86/x86-ffi_darwin.c', - 'x86/x86-ffi64.c', - 'powerpc/ppc-darwin.S', - 'powerpc/ppc-darwin_closure.S', - 'powerpc/ppc-ffi_darwin.c', - 'powerpc/ppc64-darwin_closure.S', - ]] - - # Add .S (preprocessed assembly) to C compiler source extensions. - self.compiler.src_extensions.append('.S') - - include_dirs = [os.path.join(ffi_srcdir, 'include'), - os.path.join(ffi_srcdir, 'powerpc')] - ext.include_dirs.extend(include_dirs) - ext.sources.extend(sources) - return True - def configure_ctypes(self, ext): - if not self.use_system_libffi: - if MACOS: - return self.configure_ctypes_darwin(ext) - print('INFO: Could not locate ffi libs and/or headers') - return False return True def detect_ctypes(self): # Thomas Heller's _ctypes module - self.use_system_libffi = False + + if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS): + self.use_system_libffi = True + else: + self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS") + include_dirs = [] extra_compile_args = ['-DPy_BUILD_CORE_MODULE'] extra_link_args = [] @@ -2154,11 +2113,9 @@ class PyBuildExt(build_ext): if MACOS: sources.append('_ctypes/malloc_closure.c') - sources.append('_ctypes/darwin/dlfcn_simple.c') + extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1') extra_compile_args.append('-DMACOSX') include_dirs.append('_ctypes/darwin') - # XXX Is this still needed? - # extra_link_args.extend(['-read_only_relocs', 'warning']) elif HOST_PLATFORM == 'sunos5': # XXX This shouldn't be necessary; it appears that some @@ -2188,31 +2145,48 @@ class PyBuildExt(build_ext): sources=['_ctypes/_ctypes_test.c'], libraries=['m'])) + ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR") + ffi_lib = None + ffi_inc_dirs = self.inc_dirs.copy() if MACOS: - if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"): - return - # OS X 10.5 comes with libffi.dylib; the include files are - # in /usr/include/ffi - ffi_inc_dirs.append('/usr/include/ffi') - - ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")] - if not ffi_inc or ffi_inc[0] == '': - ffi_inc = find_file('ffi.h', [], ffi_inc_dirs) - if ffi_inc is not None: - ffi_h = ffi_inc[0] + '/ffi.h' + ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi") + + if not ffi_inc: + if os.path.exists(ffi_in_sdk): + ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1") + ffi_inc = ffi_in_sdk + ffi_lib = 'ffi' + else: + # OS X 10.5 comes with libffi.dylib; the include files are + # in /usr/include/ffi + ffi_inc_dirs.append('/usr/include/ffi') + + if not ffi_inc: + found = find_file('ffi.h', [], ffi_inc_dirs) + if found: + ffi_inc = found[0] + if ffi_inc: + ffi_h = ffi_inc + '/ffi.h' if not os.path.exists(ffi_h): ffi_inc = None print('Header file {} does not exist'.format(ffi_h)) - ffi_lib = None - if ffi_inc is not None: + if ffi_lib is None and ffi_inc: for lib_name in ('ffi', 'ffi_pic'): if (self.compiler.find_library_file(self.lib_dirs, lib_name)): ffi_lib = lib_name break if ffi_inc and ffi_lib: - ext.include_dirs.extend(ffi_inc) + ffi_headers = glob(os.path.join(ffi_inc, '*.h')) + if grep_headers_for('ffi_prep_cif_var', ffi_headers): + ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1") + if grep_headers_for('ffi_prep_closure_loc', ffi_headers): + ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1") + if grep_headers_for('ffi_closure_alloc', ffi_headers): + ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1") + + ext.include_dirs.append(ffi_inc) ext.libraries.append(ffi_lib) self.use_system_libffi = True |