Преглед изворни кода

allow tcl-tk as argument or try with homebrew by default Replacement for #1409 (#1646)

* feat(python-build): allow tcl-tk as argument or default to homebrew
* refactor(python-build): detect tcl-tk-libs from confugre_opts_arr
pull/2071/head
tillhainbach пре 3 година
committed by GitHub
родитељ
комит
e56962b357
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 измењених фајлова са 135 додато и 16 уклоњено
  1. +70
    -13
      plugins/python-build/bin/python-build
  2. +65
    -3
      plugins/python-build/test/build.bats

+ 70
- 13
plugins/python-build/bin/python-build Прегледај датотеку

@ -773,6 +773,7 @@ build_package_standard_build() {
local PACKAGE_CFLAGS="${package_var_name}_CFLAGS"
if [ "$package_var_name" = "PYTHON" ]; then
use_tcltk || true
use_homebrew_readline || use_freebsd_pkg || true
if is_mac -ge 1014; then
use_xcode_sdk_zlib || use_homebrew_zlib || true
@ -1523,6 +1524,75 @@ use_xcode_sdk_zlib() {
fi
}
use_homebrew_tcltk() {
# get the version from the folder that homebrew versions
local tcltk_version_long="$(ls "$(brew --cellar tcl-tk)")"
local tcltk_version="${tcltk_version_long%.*}"
local tcltk_flags="--with-tcltk-includes=-I$tcltk_libdir/include --with-tcltk-libs=-L$tcltk_libdir/lib -ltcl$tcltk_version -ltk$tcltk_version"
echo "python-build: use tcl-tk from homebrew"
package_option python configure --with-tcltk-libs="-L$tcltk_libdir/lib -ltcl$tcltk_version -ltk$tcltk_version"
package_option python configure --with-tcltk-includes="-I$tcltk_libdir/include"
}
# FIXME: this function is a workaround for #1125
# once fixed, it should be removed.
use_custom_tcltk() {
local tcltk_ops="$1"
local tcltk_ops_flag="--with-tcltk-libs="
# get tcltk libs
local tcltk_libs="${tcltk_ops//$tcltk_ops_flag/}"
# remove tcltk-flag from configure_opts
# this allows for weird input such as
# --with-tcltk-libs=' -L/custom-tcl-tk/lib -ltcl8.6 -ltk8.4 '
PYTHON_CONFIGURE_OPTS="${PYTHON_CONFIGURE_OPTS//"$tcltk_ops_flag"/}"
PYTHON_CONFIGURE_OPTS="${PYTHON_CONFIGURE_OPTS//$tcltk_libs/}"
# remove quotes, because there mess up compilations
PYTHON_CONFIGURE_OPTS="${PYTHON_CONFIGURE_OPTS//"''"/}"
PYTHON_CONFIGURE_OPTS="${PYTHON_CONFIGURE_OPTS//'""'/}"
echo "python-build: use tcl-tk from \$PYTHON_CONFIGURE_OPTS"
# echo "PYTHON_CONFIGURE_OPTS=${PYTHON_CONFIGURE_OPTS}"
package_option python configure --with-tcltk-libs="${tcltk_libs}"
# IFS="$OLDIFS"
}
# FIXME: this function is a workaround for #1125
# once fixed, it should be removed.
# Get tcltk-flag and options from `$1`
# expects one argument containing a string of configure opts, eg. `PYTHON_CONFIGURE_OPTS`
# returns tcl_tk flag or an empty string if nothing was found.
get_tcltk_flag_from() {
IFS=$'\n'
# parse input string into array
local opts_arr=( $(xargs -n1 <<<"$1") )
# iterate through `opts_arr`, break if `--with-tcltk-libs=` was found.
for opts in ${opts_arr[@]}; do
# `--with-tcltk-libs=` must be the prefix.
if [[ "$opts" == "--with-tcltk-libs="* ]]; then
# return
echo "$opts"
break
fi
done
IFS="$OLDIFS"
}
use_tcltk() {
local tcltk_libdir="$(brew --prefix tcl-tk 2>/dev/null || true)"
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
}
# CPython 3.9.1+ and 3.8.10+ have old config.sub that doesn't support "arm64" arch
# which is what Gnu uname (but not Apple uname) produces on Apple M1
# (https://github.com/pyenv/pyenv/pull/2020#issuecomment-891911842)
@ -2083,19 +2153,6 @@ if [[ "$PYTHON_CONFIGURE_OPTS" != *"--enable-unicode="* ]]; then
fi
fi
# regex_to_match="(--with-tcltk-libs='([^']+)')"
if [[ "$PYTHON_CONFIGURE_OPTS" =~ (--with-tcltk-libs=\'([^\']+)\') ]]; then
tcltk_match="${BASH_REMATCH[1]}"
tcltk_match_quoted="${tcltk_match//--with-tcltk-libs=/}"
# remove it from PYTHON_CONFIGURE_OPTS since it will mess up compile
PYTHON_CONFIGURE_OPTS="${PYTHON_CONFIGURE_OPTS//$tcltk_match/}"
# having issues passing the single quoted part, couldnt pass as single var and still work
package_option python configure "--with-tcltk-libs='${tcltk_match_quoted}'"
unset tcltk_match
unset tcltk_match_quoted
fi
# Unset `PIP_REQUIRE_VENV` during build (#216)
unset PIP_REQUIRE_VENV
unset PIP_REQUIRE_VIRTUALENV

+ 65
- 3
plugins/python-build/test/build.bats Прегледај датотеку

@ -165,7 +165,7 @@ OUT
stub uname '-s : echo Linux'
stub uname '-s : echo Darwin'
stub brew "--prefix libyaml : echo '$brew_libdir'" false
stub brew "--prefix libyaml : echo '$brew_libdir'" false false
stub_make_install
install_fixture definitions/needs-yaml
@ -192,7 +192,7 @@ OUT
# pyenv/pyenv#1026
stub uname false false
stub brew "--prefix readline : echo '$readline_libdir'"
stub brew false "--prefix readline : echo '$readline_libdir'"
stub_make_install
run_inline_definition <<DEF
@ -222,7 +222,7 @@ OUT
# pyenv/pyenv#1026
stub uname false false
stub brew
stub brew false
stub_make_install
export PYTHON_CONFIGURE_OPTS="CPPFLAGS=-I$readline_libdir/include LDFLAGS=-L$readline_libdir/lib"
@ -242,6 +242,68 @@ make install
OUT
}
@test "tcl-tk is linked from Homebrew" {
cached_tarball "Python-3.6.2"
# python build
tcl_tk_libdir="$TMP/homebrew-tcl-tk"
tcl_tk_version_long="8.6.10"
tcl_tk_version="${tcl_tk_version_long%.*}"
mkdir -p "$tcl_tk_libdir"
mkdir -p "$tcl_tk_libdir/$tcl_tk_version_long"
# pyenv/pyenv#1026
stub uname false false
stub brew "--prefix tcl-tk : echo '$tcl_tk_libdir'" "--cellar tcl-tk : echo '$TMP/homebrew-tcl-tk'" false
stub_make_install
run_inline_definition <<DEF
install_package "Python-3.6.2" "http://python.org/ftp/python/3.6.2/Python-3.6.2.tar.gz"
DEF
assert_success
unstub brew
unstub make
assert_build_log <<OUT
Python-3.6.2: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
Python-3.6.2: --prefix=${TMP}/install --libdir=${TMP}/install/lib --with-tcltk-libs=-L${TMP}/homebrew-tcl-tk/lib -ltcl$tcl_tk_version -ltk$tcl_tk_version --with-tcltk-includes=-I${TMP}/homebrew-tcl-tk/include
make -j 2
make install
OUT
}
@test "tcl-tk is not linked from Homebrew when explicitly defined" {
cached_tarball "Python-3.6.2"
# python build
tcl_tk_version_long="8.6.10"
tcl_tk_version="${tcl_tk_version_long%.*}"
# pyenv/pyenv#1026
stub uname false false
stub brew false false
stub_make_install
export PYTHON_CONFIGURE_OPTS="--with-tcltk-libs='-L${TMP}/custom-tcl-tk/lib -ltcl$tcl_tk_version -ltk$tcl_tk_version'"
run_inline_definition <<DEF
install_package "Python-3.6.2" "http://python.org/ftp/python/3.6.2/Python-3.6.2.tar.gz"
DEF
assert_success
unstub brew
unstub make
assert_build_log <<OUT
Python-3.6.2: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
Python-3.6.2: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib --with-tcltk-libs=-L${TMP}/custom-tcl-tk/lib -ltcl8.6 -ltk8.6
make -j 2
make install
OUT
}
@test "number of CPU cores defaults to 2" {
cached_tarball "Python-3.6.2"

Loading…
Откажи
Сачувај