From 2a5bbf6cb58383b5dd79b8cd82e080800fc905e6 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Fri, 13 Jan 2023 15:46:38 +0300 Subject: [PATCH 1/2] Fix searching readline and sqlite3 in FreeBSD Surprisingly, CPython doesn't search these with pkg-config This is fixed upstream in 3.12.0a1 --- plugins/python-build/bin/python-build | 15 ++++++++--- plugins/python-build/test/build.bats | 37 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index c5815da4..e2913dac 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -1422,9 +1422,18 @@ use_freebsd_pkg() { # check if 11-R or later release="$(uname -r)" if [ "${release%%.*}" -ge 11 ]; then - if pkg info -e readline > /dev/null && ! command -v pkg-config > /dev/null ; then - # use readline from Ports Collection - # unlike Linux, BSD's cc does not look in /usr/local by default + # Use packages from Ports Collection. + # + # Unlike Linux, BSD's cc does not look in /usr/local by default + # where Ports-installed packages are, but they are available via pkg-config. + # Surprisingly, CPython's Configure only uses pkg-config + # to locate some of the dependencies and not others. + # Here we detect those that are (as of this writing) known + # to not be searched via pkg-config. + # + # XXX: As a side effect, this would pick up any other libs from Ports + # that are searched via compiler + if pkg info -e readline || pkg info -e sqlite3; then export CPPFLAGS="${CPPFLAGS:+${CPPFLAGS% } }-I/usr/local/include" export LDFLAGS="${LDFLAGS:+${LDFLAGS% } }-L/usr/local/lib -Wl,-rpath,/usr/local/lib" fi diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index f9c9a0a9..41bbaa33 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -259,6 +259,42 @@ make install OUT } +@test "readline and sqlite3 are linked from Ports in FreeBSD" { + cached_tarball "Python-3.6.2" + + for lib in readline sqlite3; do + + for i in {1..8}; do stub uname '-s : echo FreeBSD'; done + stub uname '-r : echo 11.0-RELEASE' + for i in {1..2}; do stub uname '-s : echo FreeBSD'; done + stub sysctl '-n hw.ncpu : echo 1' + + stub pkg "$([[ $lib == readline ]] && echo "info -e $lib : true" || echo false)" + if [[ $lib == sqlite3 ]]; then stub pkg echo "info -e $lib : true"; fi + + stub_make_install + + export -n MAKE_OPTS + run_inline_definition < Date: Fri, 13 Jan 2023 20:58:51 +0300 Subject: [PATCH 2/2] Avoid adding dangling spaces to *FLAGS --- plugins/python-build/bin/python-build | 42 ++++++++++---------- plugins/python-build/test/build.bats | 50 ++++++++++++------------ plugins/python-build/test/pyenv_ext.bats | 8 ++-- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index e2913dac..af1bbf94 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -1385,8 +1385,8 @@ use_homebrew() { local brew_prefix="$(brew --prefix 2>/dev/null || true)" # /usr/local/lib:/usr/lib is the default library search path if [[ -n $brew_prefix && $brew_prefix != "/usr" && $brew_prefix != "/usr/local" ]]; then - export CPPFLAGS="${CPPFLAGS:+${CPPFLAGS% } }-I${brew_prefix}/include" - export LDFLAGS="${LDFLAGS:+${LDFLAGS% } }-L${brew_prefix}/lib -Wl,-rpath,${brew_prefix}/lib" + export CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }-I${brew_prefix}/include" + export LDFLAGS="${LDFLAGS:+$LDFLAGS }-L${brew_prefix}/lib -Wl,-rpath,${brew_prefix}/lib" # `python-config` ignores LDFLAGS envvar. Adding to LIBS is the only way to add extra stuff # to `python-config --ldflags` output export LIBS="${LIBS:+${LIBS% } }-L${brew_prefix}/lib -Wl,-rpath,${brew_prefix}/lib" @@ -1404,8 +1404,8 @@ use_homebrew_yaml() { local libdir="$(brew --prefix libyaml 2>/dev/null || true)" if [ -d "$libdir" ]; then echo "python-build: use libyaml from homebrew" - export CPPFLAGS="-I$libdir/include ${CPPFLAGS}" - export LDFLAGS="-L$libdir/lib ${LDFLAGS}" + export CPPFLAGS="-I$libdir/include${CPPFLAGS:+ $CPPFLAGS}" + export LDFLAGS="-L$libdir/lib${LDFLAGS:+ ${LDFLAGS% }}" else return 1 fi @@ -1434,8 +1434,8 @@ use_freebsd_pkg() { # XXX: As a side effect, this would pick up any other libs from Ports # that are searched via compiler if pkg info -e readline || pkg info -e sqlite3; then - export CPPFLAGS="${CPPFLAGS:+${CPPFLAGS% } }-I/usr/local/include" - export LDFLAGS="${LDFLAGS:+${LDFLAGS% } }-L/usr/local/lib -Wl,-rpath,/usr/local/lib" + export CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }-I/usr/local/include" + export LDFLAGS="${LDFLAGS:+$LDFLAGS }-L/usr/local/lib -Wl,-rpath,/usr/local/lib" fi fi fi @@ -1455,8 +1455,8 @@ use_homebrew_readline() { local libdir="$(brew --prefix readline 2>/dev/null || true)" if [ -d "$libdir" ]; then echo "python-build: use readline from homebrew" - export CPPFLAGS="-I$libdir/include ${CPPFLAGS}" - export LDFLAGS="-L$libdir/lib ${LDFLAGS}" + export CPPFLAGS="-I$libdir/include${CPPFLAGS:+ $CPPFLAGS}" + export LDFLAGS="-L$libdir/lib${LDFLAGS:+ $LDFLAGS}" else return 1 fi @@ -1474,8 +1474,8 @@ build_package_mac_readline() { READLINE_PREFIX_PATH="${PREFIX_PATH}/readline" # Tell Python to use this readline for its extension. - export CPPFLAGS="-I${READLINE_PREFIX_PATH}/include ${CPPFLAGS}" - export LDFLAGS="-L${READLINE_PREFIX_PATH}/lib ${LDFLAGS}" + export CPPFLAGS="-I${READLINE_PREFIX_PATH}/include${CPPFLAGS:+ $CPPFLAGS}" + export LDFLAGS="-L${READLINE_PREFIX_PATH}/lib${LDFLAGS:+ $LDFLAGS}" # Make sure pkg-config finds our build first. export PKG_CONFIG_PATH="${READLINE_PREFIX_PATH}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" @@ -1502,8 +1502,8 @@ use_homebrew_openssl() { # https://bugs.python.org/issue21541 package_option python configure --with-openssl="${ssldir}" else - export CPPFLAGS="-I$ssldir/include ${CPPFLAGS}" - export LDFLAGS="-L$ssldir/lib ${LDFLAGS}" + export CPPFLAGS="-I$ssldir/include ${CPPFLAGS:+ $CPPFLAGS}" + export LDFLAGS="-L$ssldir/lib${LDFLAGS:+ $LDFLAGS}" fi export PKG_CONFIG_PATH="$ssldir/lib/pkgconfig/:${PKG_CONFIG_PATH}" return @@ -1525,8 +1525,8 @@ build_package_mac_openssl() { # https://bugs.python.org/issue21541 package_option python configure --with-openssl="${OPENSSL_PREFIX_PATH}" else - export CPPFLAGS="-I${OPENSSL_PREFIX_PATH}/include ${CPPFLAGS}" - export LDFLAGS="-L${OPENSSL_PREFIX_PATH}/lib ${LDFLAGS}" + export CPPFLAGS="-I${OPENSSL_PREFIX_PATH}/include ${CPPFLAGS:+ $CPPFLAGS}" + export LDFLAGS="-L${OPENSSL_PREFIX_PATH}/lib${LDFLAGS:+ $LDFLAGS}" fi # Make sure pkg-config finds our build first. @@ -1605,9 +1605,9 @@ use_xcode_sdk_zlib() { local xc_sdk_path="$(xcrun --show-sdk-path 2>/dev/null || true)" if [ -d "$xc_sdk_path" ]; then echo "python-build: use zlib from xcode sdk" - export CFLAGS="-I${xc_sdk_path}/usr/include ${CFLAGS}" + export CFLAGS="${CFLAGS:+$CFLAGS }-I${xc_sdk_path}/usr/include" if is_mac -ge 1100; then - export LDFLAGS="${LDFLAGS} -L${xc_sdk_path}/usr/lib" + export LDFLAGS="${LDFLAGS:+$LDFLAGS }-L${xc_sdk_path}/usr/lib" fi fi } @@ -1706,7 +1706,7 @@ build_package_auto_tcltk() { if is_mac && [ ! -d /usr/include/X11 ]; then if [ -d /opt/X11/include ]; then if [[ "$CPPFLAGS" != *-I/opt/X11/include* ]]; then - export CPPFLAGS="-I/opt/X11/include $CPPFLAGS" + export CPPFLAGS="-I/opt/X11/include${CPPFLAGS:+ $CPPFLAGS}" fi else package_option python configure --without-tk @@ -2209,13 +2209,13 @@ package_option python configure --libdir="${PREFIX_PATH}/lib" if [[ "$CONFIGURE_OPTS $PYTHON_CONFIGURE_OPTS ${PYTHON_CONFIGURE_OPTS_ARRAY[@]}" == *"--enable-shared"* ]]; then # The ld on Darwin embeds the full paths to each dylib by default if [[ "$LDFLAGS" != *"-rpath="* ]] && ! is_mac; then - export LDFLAGS="-Wl,-rpath=${PREFIX_PATH}/lib ${LDFLAGS}" + export LDFLAGS="-Wl,-rpath=${PREFIX_PATH}/lib${LDFLAGS:+ $LDFLAGS}" fi fi # python-build: Set `RPATH` if --shared` was given for PyPy (#244) if [[ "$PYPY_OPTS" == *"--shared"* ]]; then - export LDFLAGS="-Wl,-rpath=${PREFIX_PATH}/lib ${LDFLAGS}" + export LDFLAGS="-Wl,-rpath=${PREFIX_PATH}/lib${LDFLAGS:+ $LDFLAGS}" fi # Add support for framework installation (`--enable-framework`) of CPython (#55, #99) @@ -2381,8 +2381,8 @@ if [ -n "$VERBOSE" ]; then trap "kill $TAIL_PID" SIGINT SIGTERM EXIT fi -export LDFLAGS="-L${PREFIX_PATH}/lib ${LDFLAGS}" -export CPPFLAGS="-I${PREFIX_PATH}/include ${CPPFLAGS}" +export LDFLAGS="-L${PREFIX_PATH}/lib${LDFLAGS:+ $LDFLAGS}" +export CPPFLAGS="-I${PREFIX_PATH}/include${CPPFLAGS:+ $CPPFLAGS}" unset PYTHONHOME unset PYTHONPATH diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index 41bbaa33..41e13d6b 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -74,11 +74,11 @@ assert_build_log() { unstub make assert_build_log <