From 4bd8a975f4f625a0f68f669fca04d5d003117914 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Fri, 13 Jan 2023 20:58:51 +0300 Subject: [PATCH] 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 <