Annotation of pkgsrc/lang/python37/patches/patch-setup.py, revision 1.3

1.3     ! bsiegert    1: $NetBSD: patch-setup.py,v 1.2 2020/11/17 19:33:26 sjmulder Exp $
1.1       adam        2: 
                      3: Disable certain modules, so they can be built as separate packages.
1.2       sjmulder    4: 
1.1       adam        5: Do not look for ncursesw.
1.2       sjmulder    6: 
1.1       adam        7: Assume panel_library is correct; this is a fix for ncurses' gnupanel
1.2       sjmulder    8: which will get transformed to panel in buildlink.
                      9: 
1.1       adam       10: Also look for uuid/uuid.h.
                     11: 
1.2       sjmulder   12: Support for macOS 11 and Apple Silicon (ARM). Mostly backported from:
                     13: https://github.com/python/cpython/pull/22855
                     14: 
                     15: --- setup.py.orig      2020-08-15 05:20:16.000000000 +0000
1.1       adam       16: +++ setup.py
                     17: @@ -8,6 +8,7 @@ import importlib.util
                     18:  import sysconfig
                     19:  
                     20:  from distutils import log
                     21: +from distutils import text_file
                     22:  from distutils.errors import *
                     23:  from distutils.core import Extension, setup
                     24:  from distutils.command.build_ext import build_ext
1.2       sjmulder   25: @@ -48,7 +49,7 @@ host_platform = get_platform()
1.1       adam       26:  COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
                     27:  
                     28:  # This global variable is used to hold the list of modules to be disabled.
                     29: -disabled_module_list = []
                     30: +disabled_module_list = ["_curses", "_curses_panel", "_elementtree", "_gdbm", "pyexpat", "readline", "_sqlite3", "_tkinter", "xxlimited"]
                     31:  
                     32:  def add_dir_to_list(dirlist, dir):
                     33:      """Add the directory 'dir' to the list 'dirlist' (after any relative
1.3     ! bsiegert   34: @@ -150,6 +151,16 @@ def is_macosx_sdk_path(path):
1.2       sjmulder   35:                  or path.startswith('/System/')
                     36:                  or path.startswith('/Library/') )
                     37:  
                     38: +def grep_headers_for(function, headers):
                     39: +    for header in headers:
1.3     ! bsiegert   40: +        try:
        !            41: +            with open(header, 'r') as f:
        !            42: +                if function in f.read():
        !            43: +                    return True
        !            44: +        except UnicodeDecodeError:
        !            45: +            pass
1.2       sjmulder   46: +    return False
                     47: +
                     48:  def find_file(filename, std_dirs, paths):
                     49:      """Searches for the directory where a given file is located,
                     50:      and returns a possibly-empty list of additional directories, or None
1.3     ! bsiegert   51: @@ -581,15 +592,15 @@ class PyBuildExt(build_ext):
1.1       adam       52:              os.unlink(tmpfile)
                     53:  
                     54:      def detect_modules(self):
                     55: -        # Ensure that /usr/local is always used, but the local build
                     56: -        # directories (i.e. '.' and 'Include') must be first.  See issue
                     57: -        # 10520.
                     58: -        if not cross_compiling:
                     59: -            add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
                     60: -            add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
                     61: -        # only change this for cross builds for 3.3, issues on Mageia
                     62: -        if cross_compiling:
                     63: -            self.add_gcc_paths()
                     64: +        # Add the buildlink directories for pkgsrc
                     65: +        if os.environ.get('BUILDLINK_DIR'):
                     66: +            dir = os.environ['BUILDLINK_DIR']
                     67: +            libdir = dir + '/lib'
                     68: +            incdir = dir + '/include'
                     69: +            if libdir not in self.compiler.library_dirs:
                     70: +                self.compiler.library_dirs.insert(0, libdir)
                     71: +            if incdir not in self.compiler.include_dirs:
                     72: +                self.compiler.include_dirs.insert(0, incdir)
                     73:          self.add_multiarch_paths()
                     74:  
                     75:          # Add paths specified in the environment variables LDFLAGS and
1.3     ! bsiegert   76: @@ -673,6 +684,9 @@ class PyBuildExt(build_ext):
1.2       sjmulder   77:              lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
                     78:  
                     79:          if host_platform == 'darwin':
                     80: +            inc_dirs.append(macosx_sdk_root() + '/usr/include')
                     81: +            lib_dirs.append(macosx_sdk_root() + '/usr/lib')
                     82: +
                     83:              # This should work on any unixy platform ;-)
                     84:              # If the user has bothered specifying additional -I and -L flags
                     85:              # in OPT and LDFLAGS we might as well use them here.
1.3     ! bsiegert   86: @@ -854,8 +868,6 @@ class PyBuildExt(build_ext):
1.1       adam       87:          # use the same library for the readline and curses modules.
                     88:          if 'curses' in readline_termcap_library:
                     89:              curses_library = readline_termcap_library
                     90: -        elif self.compiler.find_library_file(lib_dirs, 'ncursesw'):
                     91: -            curses_library = 'ncursesw'
                     92:          elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
                     93:              curses_library = 'ncurses'
                     94:          elif self.compiler.find_library_file(lib_dirs, 'curses'):
1.3     ! bsiegert   95: @@ -1285,6 +1297,30 @@ class PyBuildExt(build_ext):
1.1       adam       96:          dbm_order = ['gdbm']
                     97:          # The standard Unix dbm module:
                     98:          if host_platform not in ['cygwin']:
                     99: +
                    100: +            ## Top half based on find_file
                    101: +            def find_ndbm_h(dirs):
                    102: +                ret = None
                    103: +                if sys.platform == 'darwin':
                    104: +                    sysroot = macosx_sdk_root()
                    105: +                for dir in dirs:
                    106: +                    f = os.path.join(dir, 'ndbm.h')
                    107: +                    if sys.platform == 'darwin' and is_macosx_sdk_path(dir):
                    108: +                        f = os.path.join(sysroot, dir[1:], 'ndbm.h')
                    109: +                    if not os.path.exists(f): continue
                    110: +
                    111: +                    ret = 'True'
                    112: +                    input = text_file.TextFile(f)
                    113: +                    while 1:
                    114: +                        line = input.readline()
                    115: +                        if not line: break
                    116: +                        if re.search('This file is part of GDBM', line):
                    117: +                            ret = None
                    118: +                            break
                    119: +                    input.close()
                    120: +                    break
                    121: +                return ret
                    122: +
                    123:              config_args = [arg.strip("'")
                    124:                             for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
                    125:              dbm_args = [arg for arg in config_args
1.3     ! bsiegert  126: @@ -1296,7 +1332,7 @@ class PyBuildExt(build_ext):
1.1       adam      127:              dbmext = None
                    128:              for cand in dbm_order:
                    129:                  if cand == "ndbm":
                    130: -                    if find_file("ndbm.h", inc_dirs, []) is not None:
                    131: +                    if find_ndbm_h(inc_dirs) is not None:
                    132:                          # Some systems have -lndbm, others have -lgdbm_compat,
                    133:                          # others don't have either
                    134:                          if self.compiler.find_library_file(lib_dirs,
1.3     ! bsiegert  135: @@ -1428,8 +1464,7 @@ class PyBuildExt(build_ext):
1.1       adam      136:              missing.append('_curses')
                    137:  
                    138:          # If the curses module is enabled, check for the panel module
                    139: -        if (module_enabled(exts, '_curses') and
                    140: -            self.compiler.find_library_file(lib_dirs, panel_library)):
                    141: +        if (module_enabled(exts, '_curses')):
                    142:              exts.append( Extension('_curses_panel', ['_curses_panel.c'],
                    143:                                     include_dirs=curses_includes,
                    144:                                     define_macros=curses_defines,
1.3     ! bsiegert  145: @@ -1670,6 +1705,8 @@ class PyBuildExt(build_ext):
1.1       adam      146:  
                    147:          # Build the _uuid module if possible
                    148:          uuid_incs = find_file("uuid.h", inc_dirs, ["/usr/include/uuid"])
                    149: +        if uuid_incs is None:
                    150: +            uuid_incs = find_file("uuid/uuid.h", inc_dirs, [])
                    151:          if uuid_incs is not None:
                    152:              if self.compiler.find_library_file(lib_dirs, 'uuid'):
                    153:                  uuid_libs = ['uuid']
1.3     ! bsiegert  154: @@ -1936,43 +1973,15 @@ class PyBuildExt(build_ext):
1.2       sjmulder  155:          # *** Uncomment these for TOGL extension only:
                    156:          #       -lGL -lGLU -lXext -lXmu \
                    157:  
                    158: -    def configure_ctypes_darwin(self, ext):
                    159: -        # Darwin (OS X) uses preconfigured files, in
                    160: -        # the Modules/_ctypes/libffi_osx directory.
                    161: -        srcdir = sysconfig.get_config_var('srcdir')
                    162: -        ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
                    163: -                                                  '_ctypes', 'libffi_osx'))
                    164: -        sources = [os.path.join(ffi_srcdir, p)
                    165: -                   for p in ['ffi.c',
                    166: -                             'x86/darwin64.S',
                    167: -                             'x86/x86-darwin.S',
                    168: -                             'x86/x86-ffi_darwin.c',
                    169: -                             'x86/x86-ffi64.c',
                    170: -                             'powerpc/ppc-darwin.S',
                    171: -                             'powerpc/ppc-darwin_closure.S',
                    172: -                             'powerpc/ppc-ffi_darwin.c',
                    173: -                             'powerpc/ppc64-darwin_closure.S',
                    174: -                             ]]
                    175: -
                    176: -        # Add .S (preprocessed assembly) to C compiler source extensions.
                    177: -        self.compiler.src_extensions.append('.S')
                    178: -
                    179: -        include_dirs = [os.path.join(ffi_srcdir, 'include'),
                    180: -                        os.path.join(ffi_srcdir, 'powerpc')]
                    181: -        ext.include_dirs.extend(include_dirs)
                    182: -        ext.sources.extend(sources)
                    183: -        return True
                    184: -
                    185:      def configure_ctypes(self, ext):
                    186: -        if not self.use_system_libffi:
                    187: -            if host_platform == 'darwin':
                    188: -                return self.configure_ctypes_darwin(ext)
                    189: -            print('INFO: Could not locate ffi libs and/or headers')
                    190: -            return False
                    191:          return True
                    192:  
                    193:      def detect_ctypes(self, inc_dirs, lib_dirs):
                    194: -        self.use_system_libffi = False
                    195: +        if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and host_platform == 'darwin'):
                    196: +            self.use_system_libffi = True
                    197: +        else:
                    198: +            self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
                    199: +
                    200:          include_dirs = []
                    201:          extra_compile_args = []
                    202:          extra_link_args = []
1.3     ! bsiegert  203: @@ -1985,11 +1994,9 @@ class PyBuildExt(build_ext):
1.2       sjmulder  204:  
                    205:          if host_platform == 'darwin':
                    206:              sources.append('_ctypes/malloc_closure.c')
                    207: -            sources.append('_ctypes/darwin/dlfcn_simple.c')
                    208: +            extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
                    209:              extra_compile_args.append('-DMACOSX')
                    210:              include_dirs.append('_ctypes/darwin')
                    211: -# XXX Is this still needed?
                    212: -##            extra_link_args.extend(['-read_only_relocs', 'warning'])
                    213:  
                    214:          elif host_platform == 'sunos5':
                    215:              # XXX This shouldn't be necessary; it appears that some
1.3     ! bsiegert  216: @@ -2018,30 +2025,48 @@ class PyBuildExt(build_ext):
1.2       sjmulder  217:                       libraries=['m'])
                    218:          self.extensions.extend([ext, ext_test])
                    219:  
                    220: +        ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
                    221: +        ffi_lib = None
                    222: +
                    223: +        ffi_inc_dirs = inc_dirs.copy()
                    224:          if host_platform == 'darwin':
                    225: -            if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
                    226: -                return
                    227: -            # OS X 10.5 comes with libffi.dylib; the include files are
                    228: -            # in /usr/include/ffi
                    229: -            inc_dirs.append('/usr/include/ffi')
                    230: -
                    231: -        ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
                    232: -        if not ffi_inc or ffi_inc[0] == '':
                    233: -            ffi_inc = find_file('ffi.h', [], inc_dirs)
                    234: -        if ffi_inc is not None:
                    235: -            ffi_h = ffi_inc[0] + '/ffi.h'
                    236: +            ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi")
                    237: +
                    238: +            if not ffi_inc:
                    239: +                if os.path.exists(ffi_in_sdk):
                    240: +                    ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1")
                    241: +                    ffi_inc = ffi_in_sdk
                    242: +                    ffi_lib = 'ffi'
                    243: +                else:
                    244: +                    # OS X 10.5 comes with libffi.dylib; the include files are
                    245: +                    # in /usr/include/ffi
                    246: +                    ffi_inc_dirs.append('/usr/include/ffi')
                    247: +
                    248: +        if not ffi_inc:
                    249: +            found = find_file('ffi.h', [], ffi_inc_dirs)
                    250: +            if found:
                    251: +                ffi_inc = found[0]
                    252: +        if ffi_inc:
                    253: +            ffi_h = ffi_inc + '/ffi.h'
                    254:              if not os.path.exists(ffi_h):
                    255:                  ffi_inc = None
                    256:                  print('Header file {} does not exist'.format(ffi_h))
                    257: -        ffi_lib = None
                    258: -        if ffi_inc is not None:
                    259: +        if ffi_lib is None and ffi_inc:
                    260:              for lib_name in ('ffi', 'ffi_pic'):
                    261:                  if (self.compiler.find_library_file(lib_dirs, lib_name)):
                    262:                      ffi_lib = lib_name
                    263:                      break
                    264:  
                    265:          if ffi_inc and ffi_lib:
                    266: -            ext.include_dirs.extend(ffi_inc)
                    267: +            ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
                    268: +            if grep_headers_for('ffi_prep_cif_var', ffi_headers):
                    269: +                ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
                    270: +            if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
                    271: +                ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
                    272: +            if grep_headers_for('ffi_closure_alloc', ffi_headers):
                    273: +                ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
                    274: +
                    275: +            ext.include_dirs.append(ffi_inc)
                    276:              ext.libraries.append(ffi_lib)
                    277:              self.use_system_libffi = True
                    278:  
1.3     ! bsiegert  279: @@ -2059,10 +2084,7 @@ class PyBuildExt(build_ext):
1.1       adam      280:              depends = ['_decimal/docstrings.h']
                    281:          else:
                    282:              srcdir = sysconfig.get_config_var('srcdir')
                    283: -            include_dirs = [os.path.abspath(os.path.join(srcdir,
                    284: -                                                         'Modules',
                    285: -                                                         '_decimal',
                    286: -                                                         'libmpdec'))]
                    287: +            include_dirs = ['Modules/_decimal/libmpdec']
                    288:              libraries = ['m']
                    289:              sources = [
                    290:                '_decimal/_decimal.c',
1.3     ! bsiegert  291: @@ -2398,7 +2420,7 @@ def main():
1.1       adam      292:            # If you change the scripts installed here, you also need to
                    293:            # check the PyBuildScripts command above, and change the links
                    294:            # created by the bininstall target in Makefile.pre.in
                    295: -          scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
                    296: +          scripts = ["Tools/scripts/pydoc3",
                    297:                       "Tools/scripts/2to3", "Tools/scripts/pyvenv"]
                    298:          )
                    299:  

CVSweb <webmaster@jp.NetBSD.org>