From e6446555f3ca582eb1210d34c90809de42ff0ff7 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Tue, 13 Sep 2022 16:25:15 +0300 Subject: [PATCH] Add envvar to skip Homebrew --- plugins/python-build/README.md | 5 +++-- plugins/python-build/bin/python-build | 23 ++++++++++++++--------- plugins/python-build/test/build.bats | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/plugins/python-build/README.md b/plugins/python-build/README.md index 6d6effd9..0665c047 100644 --- a/plugins/python-build/README.md +++ b/plugins/python-build/README.md @@ -113,6 +113,7 @@ You can set certain environment variables to control the build process. checksum of the file to the mirror URL. * `PYTHON_BUILD_SKIP_MIRROR`, if set, forces python-build to download packages from their original source URLs instead of using a mirror. +* `PYTHON_BUILD_SKIP_HOMEBREW`, if set, will not search for libraries installed by Homebrew on macOS. * `PYTHON_BUILD_ROOT` overrides the default location from where build definitions in `share/python-build/` are looked up. * `PYTHON_BUILD_DEFINITIONS` can be a list of colon-separated paths that get @@ -231,7 +232,7 @@ the full build log for build failures. ### Testing new python versions -If you are contributing a new python version for python-build, +If you are contributing a new python version for python-build, you can test the build in a [docker](https://www.docker.com/) container based on Ubuntu 18.04. With docker installed: @@ -249,7 +250,7 @@ docker run -it my_container ``` The container will need to be rebuilt whenever you change the repo, -but after the first build, this will be very fast, +but after the first build, this will be very fast, as the layer including the build dependencies will be cached. Changes made inside the container will not be persisted. diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index 52e8a846..1b5c30aa 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -112,6 +112,11 @@ is_mac() { [ $# -eq 0 ] || [ "$(osx_version)" "$@" ] } +can_use_homebrew() { + [ -z "$PYTHON_BUILD_SKIP_HOMEBREW" ] || return 1 + is_mac || return 1 +} + # 9.1 -> 901 # 10.9 -> 1009 # 10.10 -> 1010 @@ -1322,7 +1327,7 @@ configured_with_package_dir() { } use_homebrew() { - is_mac || return 1 + can_use_homebrew || return 1 # unless Homebrew is at the default /usr/local, need to add its paths to # compiler search to be able to use non-keg-only deps from there if is_mac && command -v brew &>/dev/null; then @@ -1344,7 +1349,7 @@ needs_yaml() { } use_homebrew_yaml() { - is_mac || return 1 + can_use_homebrew || return 1 local libdir="$(brew --prefix libyaml 2>/dev/null || true)" if [ -d "$libdir" ]; then echo "python-build: use libyaml from homebrew" @@ -1388,7 +1393,7 @@ has_broken_mac_readline() { } use_homebrew_readline() { - is_mac || return 1 + can_use_homebrew || return 1 if ! configured_with_package_dir "python" "readline/rlconf.h"; then local libdir="$(brew --prefix readline 2>/dev/null || true)" if [ -d "$libdir" ]; then @@ -1429,7 +1434,7 @@ has_broken_mac_openssl() { } use_homebrew_openssl() { - is_mac || return 1 + can_use_homebrew || return 1 command -v brew >/dev/null || return 1 for openssl in ${PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA:-openssl}; do local ssldir="$(brew --prefix "${openssl}" || true)" @@ -1529,7 +1534,7 @@ build_package_verify_openssl() { } use_homebrew_zlib() { - is_mac || return 1 + can_use_homebrew || return 1 local brew_zlib="$(brew --prefix zlib 2>/dev/null || true)" if [ -d "$brew_zlib" ]; then echo "python-build: use zlib from homebrew" @@ -1549,7 +1554,7 @@ use_xcode_sdk_zlib() { } use_homebrew_tcltk() { - is_mac || return 1 + 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 @@ -1591,13 +1596,13 @@ use_custom_tcltk() { get_tcltk_flag_from() { IFS=$'\n' # parse input string into array - local opts_arr=( $(xargs -n1 <<<"$1") ) + 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 + # return echo "$opts" break fi @@ -1607,7 +1612,7 @@ get_tcltk_flag_from() { } use_tcltk() { - if is_mac; then + 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")" diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index 1034f0ba..5e757161 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -283,6 +283,32 @@ make install OUT } +@test "no library searches performed during normal operation touch homebrew if envvar is set" { + cached_tarball "Python-3.6.2" + + for i in {1..4}; do stub uname '-s : echo Darwin'; done + for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done + stub brew true; brew + stub_make_install + export PYTHON_BUILD_SKIP_HOMEBREW=1 + + run_inline_definition <