Install ncurses from Homebrew, if available

XCode Command Line Tools 15.0 was recently released, and it contains a
broken version of ncurses 6.0. Some uses of Python's `curses` module
will segfault when compiled with it. The solution is to switch to using
the version of ncurses from Homebrew, which is currently 6.4. Support
for ncurses 6 was added to Python 3.7 and was backported to 3.6 and 2.7,
so this change should not break any recently supported Python versions.

I tested this commit with Python 3.12, 3.11, and 2.7, and all tests in
the `test.test_curses` module passed without issue.

See https://github.com/python/cpython/issues/109617 and
https://github.com/python/cpython/issues/69906 for more information.
This commit is contained in:
Alex Hedges 2023-10-04 23:30:38 -04:00
parent 44c8f061af
commit 49c31c7d9d

View File

@ -803,6 +803,7 @@ build_package_standard_build() {
use_homebrew || true
use_tcltk || true
use_homebrew_readline || use_freebsd_pkg || true
use_homebrew_ncurses || true
if is_mac -ge 1014; then
use_xcode_sdk_zlib || use_homebrew_zlib || true
else
@ -1468,6 +1469,18 @@ use_homebrew_readline() {
fi
}
use_homebrew_ncurses() {
can_use_homebrew || return 1
local libdir="$(brew --prefix ncurses 2>/dev/null || true)"
if [ -d "$libdir" ]; then
echo "python-build: use ncurses from homebrew"
export CPPFLAGS="-I$libdir/include${CPPFLAGS:+ $CPPFLAGS}"
export LDFLAGS="-L$libdir/lib${LDFLAGS:+ $LDFLAGS}"
else
return 1
fi
}
prefer_openssl11() {
# Allow overriding the preference of OpenSSL version per definition basis (#1302, #1325, #1326)
PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA="${PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA:-openssl@1.1 openssl}"