Annotation of pkgsrc/lang/python39/patches/patch-setup.py, revision 1.3
1.3 ! bsiegert 1: $NetBSD: patch-setup.py,v 1.2 2020/11/12 10:58:21 sjmulder Exp $
1.1 adam 2:
1.2 sjmulder 3: - Disable certain modules, so they can be built as separate packages.
4: - Do not look for ncursesw.
5: - Assume panel_library is correct; this is a fix for ncurses' gnupanel
6: which will get transformed to panel in buildlink.
7: - Also look for uuid/uuid.h.
8: - Support for macOS 11 and Apple Silicon (ARM). Backported from:
9: https://github.com/python/cpython/pull/22855
1.1 adam 10:
11: --- setup.py.orig 2020-10-05 15:07:58.000000000 +0000
12: +++ setup.py
13: @@ -29,7 +29,7 @@ except ImportError:
14: SUBPROCESS_BOOTSTRAP = True
15:
16:
17: -from distutils import log
18: +from distutils import log, text_file
19: from distutils.command.build_ext import build_ext
20: from distutils.command.build_scripts import build_scripts
21: from distutils.command.install import install
22: @@ -43,7 +43,7 @@ from distutils.spawn import find_executa
23: TEST_EXTENSIONS = True
24:
25: # This global variable is used to hold the list of modules to be disabled.
26: -DISABLED_MODULE_LIST = []
27: +DISABLED_MODULE_LIST = ["_curses", "_curses_panel", "_elementtree", "_gdbm", "pyexpat", "readline", "_sqlite3", "_tkinter", "xxlimited"]
28:
29:
30: def get_platform():
1.3 ! bsiegert 31: @@ -239,6 +239,16 @@ def is_macosx_sdk_path(path):
1.2 sjmulder 32: or path.startswith('/Library/') )
33:
34:
35: +def grep_headers_for(function, headers):
36: + for header in headers:
1.3 ! bsiegert 37: + try:
! 38: + with open(header, 'r') as f:
! 39: + if function in f.read():
! 40: + return True
! 41: + except UnicodeDecodeError:
! 42: + pass
1.2 sjmulder 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
1.3 ! bsiegert 48: @@ -740,15 +750,15 @@ class PyBuildExt(build_ext):
1.1 adam 49: add_dir_to_list(dir_list, directory)
50:
51: def configure_compiler(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_cross_compiling_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: self.add_ldflags_cppflags()
72:
1.3 ! bsiegert 73: @@ -796,6 +806,9 @@ class PyBuildExt(build_ext):
1.2 sjmulder 74: self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
75:
76: if MACOS:
77: + self.inc_dirs.append(macosx_sdk_root() + '/usr/include')
78: + self.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.
1.3 ! bsiegert 83: @@ -1013,8 +1026,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(self.lib_dirs, 'ncursesw'):
88: - curses_library = 'ncursesw'
89: # Issue 36210: OSS provided ncurses does not link on AIX
90: # Use IBM supplied 'curses' for successful build of _curses
91: elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
1.3 ! bsiegert 92: @@ -1116,8 +1127,7 @@ class PyBuildExt(build_ext):
1.1 adam 93: # If the curses module is enabled, check for the panel module
94: # _curses_panel needs some form of ncurses
95: skip_curses_panel = True if AIX else False
96: - if (curses_enabled and not skip_curses_panel and
97: - self.compiler.find_library_file(self.lib_dirs, panel_library)):
98: + if curses_enabled and not skip_curses_panel:
99: self.add(Extension('_curses_panel', ['_curses_panel.c'],
100: include_dirs=curses_includes,
101: define_macros=curses_defines,
1.3 ! bsiegert 102: @@ -1368,6 +1378,31 @@ class PyBuildExt(build_ext):
1.1 adam 103: dbm_order = ['gdbm']
104: # The standard Unix dbm module:
105: if not CYGWIN:
106: + # Top half based on find_file
107: + def find_ndbm_h(dirs):
108: + ret = None
109: + if MACOS:
110: + sysroot = macosx_sdk_root()
111: + for dir in dirs:
112: + f = os.path.join(dir, 'ndbm.h')
113: + if MACOS and is_macosx_sdk_path(dir):
114: + f = os.path.join(sysroot, dir[1:], 'ndbm.h')
115: + if not os.path.exists(f):
116: + continue
117: +
118: + ret = True
119: + input = text_file.TextFile(f)
120: + while True:
121: + line = input.readline()
122: + if not line:
123: + break
124: + if re.search('This file is part of GDBM', line):
125: + ret = None
126: + break
127: + input.close()
128: + break
129: + return ret
130: +
131: config_args = [arg.strip("'")
132: for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
133: dbm_args = [arg for arg in config_args
1.3 ! bsiegert 134: @@ -1379,7 +1414,7 @@ class PyBuildExt(build_ext):
1.1 adam 135: dbmext = None
136: for cand in dbm_order:
137: if cand == "ndbm":
138: - if find_file("ndbm.h", self.inc_dirs, []) is not None:
139: + if find_ndbm_h(self.inc_dirs) is not None:
140: # Some systems have -lndbm, others have -lgdbm_compat,
141: # others don't have either
142: if self.compiler.find_library_file(self.lib_dirs,
1.3 ! bsiegert 143: @@ -1779,6 +1814,8 @@ class PyBuildExt(build_ext):
1.1 adam 144: def detect_uuid(self):
145: # Build the _uuid module if possible
146: uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
147: + if uuid_incs is None:
148: + uuid_incs = find_file("uuid/uuid.h", self.inc_dirs, [])
149: if uuid_incs is not None:
150: if self.compiler.find_library_file(self.lib_dirs, 'uuid'):
151: uuid_libs = ['uuid']
1.3 ! bsiegert 152: @@ -2101,43 +2138,17 @@ class PyBuildExt(build_ext):
1.2 sjmulder 153: library_dirs=added_lib_dirs))
154: return True
155:
156: - def configure_ctypes_darwin(self, ext):
157: - # Darwin (OS X) uses preconfigured files, in
158: - # the Modules/_ctypes/libffi_osx directory.
159: - ffi_srcdir = os.path.abspath(os.path.join(self.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 MACOS:
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):
191: # Thomas Heller's _ctypes module
192: - self.use_system_libffi = False
193: +
194: + if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS):
195: + self.use_system_libffi = True
196: + else:
197: + self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
198: +
199: include_dirs = []
200: extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
201: extra_link_args = []
1.3 ! bsiegert 202: @@ -2150,11 +2161,9 @@ class PyBuildExt(build_ext):
1.2 sjmulder 203:
204: if MACOS:
205: sources.append('_ctypes/malloc_closure.c')
206: - sources.append('_ctypes/darwin/dlfcn_simple.c')
207: + extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
208: extra_compile_args.append('-DMACOSX')
209: include_dirs.append('_ctypes/darwin')
210: - # XXX Is this still needed?
211: - # extra_link_args.extend(['-read_only_relocs', 'warning'])
212:
213: elif HOST_PLATFORM == 'sunos5':
214: # XXX This shouldn't be necessary; it appears that some
1.3 ! bsiegert 215: @@ -2184,31 +2193,48 @@ class PyBuildExt(build_ext):
1.2 sjmulder 216: sources=['_ctypes/_ctypes_test.c'],
217: libraries=['m']))
218:
219: + ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR")
220: + ffi_lib = None
221: +
222: ffi_inc_dirs = self.inc_dirs.copy()
223: if MACOS:
224: - if '--with-system-ffi' not in sysconfig.get_config_var("CONFIG_ARGS"):
225: - return
226: - # OS X 10.5 comes with libffi.dylib; the include files are
227: - # in /usr/include/ffi
228: - ffi_inc_dirs.append('/usr/include/ffi')
229: -
230: - ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
231: - if not ffi_inc or ffi_inc[0] == '':
232: - ffi_inc = find_file('ffi.h', [], ffi_inc_dirs)
233: - if ffi_inc is not None:
234: - ffi_h = ffi_inc[0] + '/ffi.h'
235: + ffi_in_sdk = os.path.join(macosx_sdk_root(), "usr/include/ffi")
236: +
237: + if not ffi_inc:
238: + if os.path.exists(ffi_in_sdk):
239: + ext.extra_compile_args.append("-DUSING_APPLE_OS_LIBFFI=1")
240: + ffi_inc = ffi_in_sdk
241: + ffi_lib = 'ffi'
242: + else:
243: + # OS X 10.5 comes with libffi.dylib; the include files are
244: + # in /usr/include/ffi
245: + ffi_inc_dirs.append('/usr/include/ffi')
246: +
247: + if not ffi_inc:
248: + found = find_file('ffi.h', [], ffi_inc_dirs)
249: + if found:
250: + ffi_inc = found[0]
251: + if ffi_inc:
252: + ffi_h = ffi_inc + '/ffi.h'
253: if not os.path.exists(ffi_h):
254: ffi_inc = None
255: print('Header file {} does not exist'.format(ffi_h))
256: - ffi_lib = None
257: - if ffi_inc is not None:
258: + if ffi_lib is None and ffi_inc:
259: for lib_name in ('ffi', 'ffi_pic'):
260: if (self.compiler.find_library_file(self.lib_dirs, lib_name)):
261: ffi_lib = lib_name
262: break
263:
264: if ffi_inc and ffi_lib:
265: - ext.include_dirs.extend(ffi_inc)
266: + ffi_headers = glob(os.path.join(ffi_inc, '*.h'))
267: + if grep_headers_for('ffi_prep_cif_var', ffi_headers):
268: + ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
269: + if grep_headers_for('ffi_prep_closure_loc', ffi_headers):
270: + ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
271: + if grep_headers_for('ffi_closure_alloc', ffi_headers):
272: + ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
273: +
274: + ext.include_dirs.append(ffi_inc)
275: ext.libraries.append(ffi_lib)
276: self.use_system_libffi = True
277:
1.3 ! bsiegert 278: @@ -2226,10 +2252,7 @@ class PyBuildExt(build_ext):
1.1 adam 279: sources = ['_decimal/_decimal.c']
280: depends = ['_decimal/docstrings.h']
281: else:
282: - include_dirs = [os.path.abspath(os.path.join(self.srcdir,
283: - 'Modules',
284: - '_decimal',
285: - 'libmpdec'))]
286: + include_dirs = ['Modules/_decimal/libmpdec']
287: libraries = ['m']
288: sources = [
289: '_decimal/_decimal.c',
1.3 ! bsiegert 290: @@ -2609,7 +2632,7 @@ def main():
1.1 adam 291: # If you change the scripts installed here, you also need to
292: # check the PyBuildScripts command above, and change the links
293: # created by the bininstall target in Makefile.pre.in
294: - scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
295: + scripts = ["Tools/scripts/pydoc3",
296: "Tools/scripts/2to3"]
297: )
298:
CVSweb <webmaster@jp.NetBSD.org>