mirror of
https://github.com/python/cpython.git
synced 2025-10-25 18:54:53 +00:00
gh-90005: Port readline and curses to PY_STDLIB_MOD (GH-94452)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
parent
50b9a7762f
commit
e925241d95
6 changed files with 1943 additions and 458 deletions
146
setup.py
146
setup.py
|
|
@ -1015,149 +1015,9 @@ def detect_test_extensions(self):
|
|||
))
|
||||
|
||||
def detect_readline_curses(self):
|
||||
# readline
|
||||
readline_termcap_library = ""
|
||||
curses_library = ""
|
||||
# Cannot use os.popen here in py3k.
|
||||
tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
|
||||
if not os.path.exists(self.build_temp):
|
||||
os.makedirs(self.build_temp)
|
||||
# Determine if readline is already linked against curses or tinfo.
|
||||
if sysconfig.get_config_var('HAVE_LIBREADLINE'):
|
||||
if sysconfig.get_config_var('WITH_EDITLINE'):
|
||||
readline_lib = 'edit'
|
||||
else:
|
||||
readline_lib = 'readline'
|
||||
do_readline = self.compiler.find_library_file(self.lib_dirs,
|
||||
readline_lib)
|
||||
if CROSS_COMPILING:
|
||||
ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
|
||||
% (sysconfig.get_config_var('READELF'),
|
||||
do_readline, tmpfile))
|
||||
elif find_executable('ldd'):
|
||||
ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
|
||||
else:
|
||||
ret = 1
|
||||
if ret == 0:
|
||||
with open(tmpfile) as fp:
|
||||
for ln in fp:
|
||||
if 'curses' in ln:
|
||||
readline_termcap_library = re.sub(
|
||||
r'.*lib(n?cursesw?)\.so.*', r'\1', ln
|
||||
).rstrip()
|
||||
break
|
||||
# termcap interface split out from ncurses
|
||||
if 'tinfo' in ln:
|
||||
readline_termcap_library = 'tinfo'
|
||||
break
|
||||
if os.path.exists(tmpfile):
|
||||
os.unlink(tmpfile)
|
||||
else:
|
||||
do_readline = False
|
||||
# Issue 7384: If readline is already linked against curses,
|
||||
# use the same library for the readline and curses modules.
|
||||
if 'curses' in readline_termcap_library:
|
||||
curses_library = readline_termcap_library
|
||||
elif self.compiler.find_library_file(self.lib_dirs, 'ncursesw'):
|
||||
curses_library = 'ncursesw'
|
||||
# Issue 36210: OSS provided ncurses does not link on AIX
|
||||
# Use IBM supplied 'curses' for successful build of _curses
|
||||
elif AIX and self.compiler.find_library_file(self.lib_dirs, 'curses'):
|
||||
curses_library = 'curses'
|
||||
elif self.compiler.find_library_file(self.lib_dirs, 'ncurses'):
|
||||
curses_library = 'ncurses'
|
||||
elif self.compiler.find_library_file(self.lib_dirs, 'curses'):
|
||||
curses_library = 'curses'
|
||||
|
||||
if MACOS:
|
||||
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])
|
||||
< (10, 5) ) ):
|
||||
os_release = 8
|
||||
if os_release < 9:
|
||||
# MacOSX 10.4 has a broken readline. Don't try to build
|
||||
# the readline module unless the user has installed a fixed
|
||||
# readline package
|
||||
if find_file('readline/rlconf.h', self.inc_dirs, []) is None:
|
||||
do_readline = False
|
||||
if do_readline:
|
||||
readline_libs = [readline_lib]
|
||||
if readline_termcap_library:
|
||||
pass # Issue 7384: Already linked against curses or tinfo.
|
||||
elif curses_library:
|
||||
readline_libs.append(curses_library)
|
||||
elif self.compiler.find_library_file(self.lib_dirs +
|
||||
['/usr/lib/termcap'],
|
||||
'termcap'):
|
||||
readline_libs.append('termcap')
|
||||
self.add(Extension('readline', ['readline.c'],
|
||||
library_dirs=['/usr/lib/termcap'],
|
||||
libraries=readline_libs))
|
||||
else:
|
||||
self.missing.append('readline')
|
||||
|
||||
# Curses support, requiring the System V version of curses, often
|
||||
# provided by the ncurses library.
|
||||
curses_defines = []
|
||||
curses_includes = []
|
||||
panel_library = 'panel'
|
||||
if curses_library == 'ncursesw':
|
||||
curses_defines.append(('HAVE_NCURSESW', '1'))
|
||||
if not CROSS_COMPILING:
|
||||
curses_includes.append('/usr/include/ncursesw')
|
||||
# Bug 1464056: If _curses.so links with ncursesw,
|
||||
# _curses_panel.so must link with panelw.
|
||||
panel_library = 'panelw'
|
||||
if MACOS:
|
||||
# On OS X, there is no separate /usr/lib/libncursesw nor
|
||||
# libpanelw. If we are here, we found a locally-supplied
|
||||
# version of libncursesw. There should also be a
|
||||
# libpanelw. _XOPEN_SOURCE defines are usually excluded
|
||||
# for OS X but we need _XOPEN_SOURCE_EXTENDED here for
|
||||
# ncurses wide char support
|
||||
curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
|
||||
elif MACOS and curses_library == 'ncurses':
|
||||
# Building with the system-suppied combined libncurses/libpanel
|
||||
curses_defines.append(('HAVE_NCURSESW', '1'))
|
||||
curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
|
||||
|
||||
curses_enabled = True
|
||||
if curses_library.startswith('ncurses'):
|
||||
curses_libs = [curses_library]
|
||||
self.add(Extension('_curses', ['_cursesmodule.c'],
|
||||
include_dirs=curses_includes,
|
||||
define_macros=curses_defines,
|
||||
libraries=curses_libs))
|
||||
elif curses_library == 'curses' and not MACOS:
|
||||
# OSX has an old Berkeley curses, not good enough for
|
||||
# the _curses module.
|
||||
if (self.compiler.find_library_file(self.lib_dirs, 'terminfo')):
|
||||
curses_libs = ['curses', 'terminfo']
|
||||
elif (self.compiler.find_library_file(self.lib_dirs, 'termcap')):
|
||||
curses_libs = ['curses', 'termcap']
|
||||
else:
|
||||
curses_libs = ['curses']
|
||||
|
||||
self.add(Extension('_curses', ['_cursesmodule.c'],
|
||||
define_macros=curses_defines,
|
||||
libraries=curses_libs))
|
||||
else:
|
||||
curses_enabled = False
|
||||
self.missing.append('_curses')
|
||||
|
||||
# If the curses module is enabled, check for the panel module
|
||||
# _curses_panel needs some form of ncurses
|
||||
skip_curses_panel = True if AIX else False
|
||||
if (curses_enabled and not skip_curses_panel and
|
||||
self.compiler.find_library_file(self.lib_dirs, panel_library)):
|
||||
self.add(Extension('_curses_panel', ['_curses_panel.c'],
|
||||
include_dirs=curses_includes,
|
||||
define_macros=curses_defines,
|
||||
libraries=[panel_library, *curses_libs]))
|
||||
elif not skip_curses_panel:
|
||||
self.missing.append('_curses_panel')
|
||||
self.addext(Extension('readline', ['readline.c']))
|
||||
self.addext(Extension('_curses', ['_cursesmodule.c']))
|
||||
self.addext(Extension('_curses_panel', ['_curses_panel.c']))
|
||||
|
||||
def detect_crypt(self):
|
||||
self.addext(Extension('_crypt', ['_cryptmodule.c']))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue