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

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

CVSweb <webmaster@jp.NetBSD.org>