Prefer tcl-tk@8 from Homebrew due to release of Tcl/Tk 9 with which only 3.12+ are compatible (#3118)

This commit is contained in:
native-api 2024-12-06 02:55:53 +03:00 committed by GitHub
parent 3bc0d858cc
commit a39449bc50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 47 deletions

View File

@ -814,7 +814,7 @@ build_package_standard_build() {
if [ "$package_var_name" = "PYTHON" ]; then
use_homebrew || true
use_tcltk || true
use_custom_tcltk || use_homebrew_tcltk || true
use_homebrew_readline || use_freebsd_pkg || true
use_homebrew_ncurses || true
if is_mac -ge 1014; then
@ -1671,31 +1671,43 @@ use_xcode_sdk_zlib() {
use_homebrew_tcltk() {
can_use_homebrew || return 1
# get the version from the folder that homebrew versions
local tcltk_libdir="$(brew --prefix tcl-tk 2>/dev/null || true)"
if [ -d "$tcltk_libdir" ]; then
echo "python-build: use tcl-tk from homebrew"
if [[ -z "$PYTHON_BUILD_TCLTK_USE_PKGCONFIG" ]]; then
local tcltk_version="$(sh -c '. '"$tcltk_libdir"'/lib/tclConfig.sh; echo $TCL_VERSION')"
package_option python configure --with-tcltk-libs="-L$tcltk_libdir/lib -ltcl$tcltk_version -ltk$tcltk_version"
# In Homebrew Tcl/Tk 8.6.13, headers have been moved to the 'tcl-tk' subdir.
# We're not using tclConfig.sh here 'cuz it produces the version-specific path to <brew prefix>/Cellar
# and we'd rather have rpath set to <brew prefix>/opt/<...> to allow micro release upgrades without rebuilding
# XXX: do use tclConfig.sh and translate the paths if more path shenanigans appear in later releases
if [ -d "$tcltk_libdir/include/tcl-tk" ]; then
package_option python configure --with-tcltk-includes="-I$tcltk_libdir/include/tcl-tk"
else
package_option python configure --with-tcltk-includes="-I$tcltk_libdir/include"
# Since https://github.com/Homebrew/homebrew-core/commit/f10e88617b41555193c22fdcba6109fe82155ee2 (10.11.2024),
# tcl-tk is 9.0 which is not compatible with CPython as of this writing
# but we'll keep it as backup for cases like non-updated Homebrew
local tcltk
for tcltk in "tcl-tk@8" "tcl-tk"; do
local tcltk_libdir="$(brew --prefix "${tcltk}" 2>/dev/null || true)"
if [ -d "$tcltk_libdir" ]; then
echo "python-build: use tcl-tk from homebrew"
if [[ -z "$PYTHON_BUILD_TCLTK_USE_PKGCONFIG" ]]; then
local tcltk_version="$(sh -c '. '"$tcltk_libdir"'/lib/tclConfig.sh; echo $TCL_VERSION')"
package_option python configure --with-tcltk-libs="-L$tcltk_libdir/lib -ltcl$tcltk_version -ltk$tcltk_version"
# In Homebrew Tcl/Tk 8.6.13, headers have been moved to the 'tcl-tk' subdir.
# We're not using tclConfig.sh here 'cuz it produces the version-specific path to <brew prefix>/Cellar
# and we'd rather have rpath set to <brew prefix>/opt/<...> to allow micro release upgrades without rebuilding
# XXX: do use tclConfig.sh and translate the paths if more path shenanigans appear in later releases
if [ -d "$tcltk_libdir/include/tcl-tk" ]; then
package_option python configure --with-tcltk-includes="-I$tcltk_libdir/include/tcl-tk"
else
package_option python configure --with-tcltk-includes="-I$tcltk_libdir/include"
fi
fi
export PKG_CONFIG_PATH="${tcltk_libdir}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
return 0
fi
export PKG_CONFIG_PATH="${tcltk_libdir}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
fi
done
return 1
}
# FIXME: this function is a workaround for #1125
# once fixed, it should be removed.
# if tcltk_ops_flag is in PYTHON_CONFIGURE_OPTS, use user provided tcltk
use_custom_tcltk() {
local tcltk_ops="$1"
local tcltk_ops="$(get_tcltk_flag_from "$PYTHON_CONFIGURE_OPTS")"
if [[ -z "$tcltk_ops" ]]; then
return 1
fi
local tcltk_ops_flag="--with-tcltk-libs="
# get tcltk libs
local tcltk_libs="${tcltk_ops//$tcltk_ops_flag/}"
@ -1738,21 +1750,6 @@ get_tcltk_flag_from() {
IFS="$OLDIFS"
}
use_tcltk() {
if can_use_homebrew; then
local tcltk_libdir="$(brew --prefix tcl-tk 2>/dev/null || true)"
fi
local tcl_tk_libs="$(get_tcltk_flag_from "$PYTHON_CONFIGURE_OPTS")"
# if tcltk_ops_flag is in PYTHON_CONFIGURE_OPTS, use user provided tcltk
# otherwise default to homebrew-installed tcl-tk, if installed
if [[ -n "$tcl_tk_libs" ]]; then
use_custom_tcltk "$tcl_tk_libs"
elif [ -d "$tcltk_libdir" ]; then
use_homebrew_tcltk
fi
}
# Since 3.12, CPython can add DWARF debug information in MacOS
# using Apple's nonstandard way, `dsymutil', that creates a "dSYM bundle"
# that's supposed to be installed alongside executables

View File

@ -182,7 +182,7 @@ OUT
for i in {1..10}; do stub uname '-s : echo Darwin'; done
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
stub brew "--prefix libyaml : echo '$brew_libdir'"
for i in {1..5}; do stub brew false; done
for i in {1..6}; do stub brew false; done
stub_make_install
install_fixture definitions/needs-yaml
@ -208,7 +208,7 @@ OUT
mkdir -p "$readline_libdir"
for i in {1..8}; do stub uname '-s : echo Darwin'; done
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
for i in {1..2}; do stub brew false; done
for i in {1..3}; do stub brew false; done
stub brew "--prefix readline : echo '$readline_libdir'"
for i in {1..2}; do stub brew false; done
stub_make_install
@ -238,7 +238,7 @@ OUT
mkdir -p "$ncurses_libdir"
for i in {1..9}; do stub uname '-s : echo Darwin'; done
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
for i in {1..3}; do stub brew false; done
for i in {1..4}; do stub brew false; done
stub brew "--prefix ncurses : echo '$ncurses_libdir'"
stub brew false
stub_make_install
@ -364,7 +364,7 @@ OUT
for i in {1..4}; do stub uname '-s : echo Linux'; done
stub brew "--prefix : echo '$BREW_PREFIX'"
for i in {1..4}; do stub brew false; done
for i in {1..5}; do stub brew false; done
stub_make_install
export PYTHON_BUILD_USE_HOMEBREW=1
@ -394,7 +394,7 @@ OUT
for i in {1..4}; do stub uname '-s : echo Linux'; done
stub brew "--prefix : echo '$BREW_PREFIX'"
for i in {1..4}; do stub brew false; done
for i in {1..5}; do stub brew false; done
stub_make_install
export PYTHON_BUILD_USE_HOMEBREW=1
@ -453,7 +453,7 @@ OUT
for i in {1..8}; do stub uname '-s : echo Darwin'; done
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
for i in {1..4}; do stub brew false; done
for i in {1..5}; do stub brew false; done
stub_make_install
export PYTHON_CONFIGURE_OPTS="CPPFLAGS=-I$readline_libdir/include LDFLAGS=-L$readline_libdir/lib"
@ -482,11 +482,11 @@ OUT
mkdir -p "$tcl_tk_libdir/lib"
echo "TCL_VERSION='$tcl_tk_version'" >>"$tcl_tk_libdir/lib/tclConfig.sh"
for i in {1..10}; do stub uname '-s : echo Darwin'; done
for i in {1..9}; do stub uname '-s : echo Darwin'; done
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
stub brew false
for i in {1..2}; do stub brew "--prefix tcl-tk : echo '$tcl_tk_libdir'"; done
stub brew "--prefix tcl-tk@8 : echo '$tcl_tk_libdir'"
for i in {1..3}; do stub brew false; done
stub_make_install
@ -516,10 +516,10 @@ OUT
tcl_tk_version_long="8.6.10"
tcl_tk_version="${tcl_tk_version_long%.*}"
for i in {1..9}; do stub uname '-s : echo Darwin'; done
for i in {1..8}; do stub uname '-s : echo Darwin'; done
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
for i in {1..5}; do stub brew false; done
for i in {1..4}; do stub brew false; done
stub_make_install
export PYTHON_CONFIGURE_OPTS="--with-tcltk-libs='-L${TMP}/custom-tcl-tk/lib -ltcl$tcl_tk_version -ltk$tcl_tk_version'"
@ -544,14 +544,14 @@ OUT
@test "tcl-tk is linked from Homebrew via pkgconfig only when envvar is set" {
cached_tarball "Python-3.6.2"
for i in {1..10}; do stub uname '-s : echo Darwin'; done
for i in {1..9}; do stub uname '-s : echo Darwin'; done
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
tcl_tk_libdir="$TMP/homebrew-tcl-tk"
mkdir -p "$tcl_tk_libdir/lib"
stub brew false
for i in {1..2}; do stub brew "--prefix tcl-tk : echo '${tcl_tk_libdir}'"; done
stub brew "--prefix tcl-tk@8 : echo '${tcl_tk_libdir}'"
for i in {1..3}; do stub brew false; done
stub_make_install
@ -739,7 +739,7 @@ OUT
for i in {1..10}; do stub uname '-s : echo Darwin'; done
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
for i in {1..5}; do stub brew false; done
for i in {1..6}; do stub brew false; done
stub_make_install
run_inline_definition <<DEF