From fc90785f75461b8eb67b0a9c3d74f1e4932c9c6f Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Tue, 24 Apr 2018 02:23:08 +0000 Subject: [PATCH 1/3] Allow overriding HTTP client type based on environment variable `PYTHON_BUILD_HTTP_CLIENT` (#1126) --- plugins/python-build/bin/python-build | 35 +++++++++++++++++---------- test/test_helper.bash | 1 + 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index eccfec18..50dc8e44 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -328,21 +328,22 @@ http() { local file="$3" [ -n "$url" ] || return 1 - if type aria2c &>/dev/null; then - "http_${method}_aria2c" "$url" "$file" - elif type curl &>/dev/null; then - "http_${method}_curl" "$url" "$file" - elif type wget &>/dev/null; then - # SSL Certificate error with older wget that does not support Server Name Indication (#60) - if [[ "$(wget --version 2>/dev/null || true)" = "GNU Wget 1.1"[0-3]* ]]; then - echo "python-build: wget (< 1.14) doesn't support Server Name Indication. Please install curl (>= 7.18.1) and try again" >&2 - return 1 - fi - "http_${method}_wget" "$url" "$file" + local http_client + if [ -n "${PYTHON_BUILD_HTTP_CLIENT}" ]; then + http_client="http_${method}_${PYTHON_BUILD_HTTP_CLIENT}" else - echo "error: please install \`aria2c\`, \`curl\` or \`wget\` and try again" >&2 - exit 1 + if type aria2c &>/dev/null; then + http_client="http_${method}_aria2c" + elif type curl &>/dev/null; then + http_client="http_${method}_curl" + elif type wget &>/dev/null; then + http_client="http_${method}_wget" + else + echo "error: please install \`aria2c\`, \`curl\` or \`wget\` and try again" >&2 + exit 1 + fi fi + "${http_client}" "$url" "$file" } http_head_aria2c() { @@ -2031,6 +2032,14 @@ ARIA2_OPTS="${PYTHON_BUILD_ARIA2_OPTS} ${IPV4+--disable-ipv6=true} ${IPV6+--disa CURL_OPTS="${PYTHON_BUILD_CURL_OPTS} ${IPV4+--ipv4} ${IPV6+--ipv6}" WGET_OPTS="${PYTHON_BUILD_WGET_OPTS} ${IPV4+--inet4-only} ${IPV6+--inet6-only}" +if [ -z "${PYTHON_BUILD_HTTP_CLIENT}" ] && ! type aria2c &>/dev/null && ! type curl &>/dev/null; then + # SSL Certificate error with older wget that does not support Server Name Indication (#60) + if [[ "$(wget --version 2>/dev/null || true)" = "GNU Wget 1.1"[0-3]* ]]; then + echo "python-build: wget (< 1.14) doesn't support Server Name Indication. Please install curl (>= 7.18.1) and try again" >&2 + return 1 + fi +fi + # Add an option to build a debug version of Python (#11) if [ -n "$DEBUG" ]; then package_option python configure --with-pydebug diff --git a/test/test_helper.bash b/test/test_helper.bash index e11cd8f1..ed9bbb2c 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,5 +1,6 @@ unset PYENV_VERSION unset PYENV_DIR +unset PYTHON_BUILD_HTTP_CLIENT # guard against executing this block twice due to bats internals if [ -z "$PYENV_TEST_DIR" ]; then From 098fb9f07acfca10c131825e0844527e6fde0a31 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Tue, 24 Apr 2018 05:22:32 +0000 Subject: [PATCH 2/3] Rewrite python-build tests with using `PYTHON_BUILD_HTTP_CLIENT` --- plugins/python-build/test/build.bats | 2 +- plugins/python-build/test/cache.bats | 2 +- plugins/python-build/test/checksum.bats | 5 +--- plugins/python-build/test/fetch.bats | 3 ++- plugins/python-build/test/mirror.bats | 5 +--- plugins/python-build/test/pyenv_ext.bats | 2 +- plugins/python-build/test/test_helper.bash | 29 ---------------------- 7 files changed, 7 insertions(+), 41 deletions(-) diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index 69afb6f4..472c9209 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -6,9 +6,9 @@ export MAKE=make export MAKE_OPTS="-j 2" export CC=cc export -n PYTHON_CONFIGURE_OPTS +export PYTHON_BUILD_HTTP_CLIENT="curl" setup() { - ensure_not_found_in_path aria2c mkdir -p "$INSTALL_ROOT" stub md5 false stub curl false diff --git a/plugins/python-build/test/cache.bats b/plugins/python-build/test/cache.bats index 88b3f89d..3eea3386 100644 --- a/plugins/python-build/test/cache.bats +++ b/plugins/python-build/test/cache.bats @@ -4,9 +4,9 @@ load test_helper export PYTHON_BUILD_SKIP_MIRROR=1 export PYTHON_BUILD_CACHE_PATH="$TMP/cache" export PYTHON_BUILD_CURL_OPTS= +export PYTHON_BUILD_HTTP_CLIENT="curl" setup() { - ensure_not_found_in_path aria2c mkdir "$PYTHON_BUILD_CACHE_PATH" } diff --git a/plugins/python-build/test/checksum.bats b/plugins/python-build/test/checksum.bats index 04973a97..dc4f958a 100644 --- a/plugins/python-build/test/checksum.bats +++ b/plugins/python-build/test/checksum.bats @@ -4,10 +4,7 @@ load test_helper export PYTHON_BUILD_SKIP_MIRROR=1 export PYTHON_BUILD_CACHE_PATH= export PYTHON_BUILD_CURL_OPTS= - -setup() { - ensure_not_found_in_path aria2c -} +export PYTHON_BUILD_HTTP_CLIENT="curl" @test "package URL without checksum" { diff --git a/plugins/python-build/test/fetch.bats b/plugins/python-build/test/fetch.bats index c131e688..48b058ce 100644 --- a/plugins/python-build/test/fetch.bats +++ b/plugins/python-build/test/fetch.bats @@ -4,9 +4,9 @@ load test_helper export PYTHON_BUILD_SKIP_MIRROR=1 export PYTHON_BUILD_CACHE_PATH= export PYTHON_BUILD_ARIA2_OPTS= +export PYTHON_BUILD_HTTP_CLIENT="curl" setup() { - ensure_not_found_in_path aria2c export PYTHON_BUILD_BUILD_PATH="${TMP}/source" mkdir -p "${PYTHON_BUILD_BUILD_PATH}" } @@ -21,6 +21,7 @@ setup() { } @test "using aria2c if available" { + export PYTHON_BUILD_HTTP_CLIENT="aria2c" stub aria2c "--allow-overwrite=true --no-conf=true -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4" install_fixture definitions/without-checksum diff --git a/plugins/python-build/test/mirror.bats b/plugins/python-build/test/mirror.bats index 038a920a..0ee26b4f 100644 --- a/plugins/python-build/test/mirror.bats +++ b/plugins/python-build/test/mirror.bats @@ -5,10 +5,7 @@ export PYTHON_BUILD_SKIP_MIRROR= export PYTHON_BUILD_CACHE_PATH= export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com export PYTHON_BUILD_CURL_OPTS= - -setup() { - ensure_not_found_in_path aria2c -} +export PYTHON_BUILD_HTTP_CLIENT="curl" @test "package URL without checksum bypasses mirror" { diff --git a/plugins/python-build/test/pyenv_ext.bats b/plugins/python-build/test/pyenv_ext.bats index ae9f72ab..5f6d5037 100644 --- a/plugins/python-build/test/pyenv_ext.bats +++ b/plugins/python-build/test/pyenv_ext.bats @@ -5,11 +5,11 @@ export PYTHON_BUILD_CACHE_PATH="$TMP/cache" export MAKE=make export MAKE_OPTS="-j 2" export CC=cc +export PYTHON_BUILD_HTTP_CLIENT="curl" export TMP_FIXTURES="$TMP/fixtures" setup() { - ensure_not_found_in_path aria2c mkdir -p "$INSTALL_ROOT" stub md5 false stub curl false diff --git a/plugins/python-build/test/test_helper.bash b/plugins/python-build/test/test_helper.bash index 1ad42d58..74607ddd 100644 --- a/plugins/python-build/test/test_helper.bash +++ b/plugins/python-build/test/test_helper.bash @@ -9,35 +9,6 @@ if [ "$FIXTURE_ROOT" != "$BATS_TEST_DIRNAME/fixtures" ]; then export PATH fi -remove_command_from_path() { - OLDIFS="${IFS}" - local cmd="$1" - local path - local paths=() - IFS=: - for path in ${PATH}; do - if [ -e "${path}/${cmd}" ]; then - local tmp_path="$(mktemp -d "${TMP}/path.XXXXX")" - ln -fs "${path}"/* "${tmp_path}" - rm -f "${tmp_path}/${cmd}" - paths["${#paths[@]}"]="${tmp_path}" - else - paths["${#paths[@]}"]="${path}" - fi - done - export PATH="${paths[*]}" - IFS="${OLDIFS}" -} - -ensure_not_found_in_path() { - local cmd - for cmd; do - if command -v "${cmd}" 1>/dev/null 2>&1; then - remove_command_from_path "${cmd}" - fi - done -} - teardown() { rm -fr "${TMP:?}"/* } From b3ba0fd7e377cd4953c1782fa2e159cebb27c60c Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Thu, 26 Apr 2018 02:06:57 +0000 Subject: [PATCH 3/3] Refactor test code of python-build. Use curl during tests by default --- plugins/python-build/test/build.bats | 1 - plugins/python-build/test/cache.bats | 2 -- plugins/python-build/test/checksum.bats | 2 -- plugins/python-build/test/fetch.bats | 3 +-- plugins/python-build/test/mirror.bats | 2 -- plugins/python-build/test/test_helper.bash | 2 ++ test/test_helper.bash | 1 - 7 files changed, 3 insertions(+), 10 deletions(-) diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index 472c9209..7674628e 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -6,7 +6,6 @@ export MAKE=make export MAKE_OPTS="-j 2" export CC=cc export -n PYTHON_CONFIGURE_OPTS -export PYTHON_BUILD_HTTP_CLIENT="curl" setup() { mkdir -p "$INSTALL_ROOT" diff --git a/plugins/python-build/test/cache.bats b/plugins/python-build/test/cache.bats index 3eea3386..2baef589 100644 --- a/plugins/python-build/test/cache.bats +++ b/plugins/python-build/test/cache.bats @@ -3,8 +3,6 @@ load test_helper export PYTHON_BUILD_SKIP_MIRROR=1 export PYTHON_BUILD_CACHE_PATH="$TMP/cache" -export PYTHON_BUILD_CURL_OPTS= -export PYTHON_BUILD_HTTP_CLIENT="curl" setup() { mkdir "$PYTHON_BUILD_CACHE_PATH" diff --git a/plugins/python-build/test/checksum.bats b/plugins/python-build/test/checksum.bats index dc4f958a..f80d5ae2 100644 --- a/plugins/python-build/test/checksum.bats +++ b/plugins/python-build/test/checksum.bats @@ -3,8 +3,6 @@ load test_helper export PYTHON_BUILD_SKIP_MIRROR=1 export PYTHON_BUILD_CACHE_PATH= -export PYTHON_BUILD_CURL_OPTS= -export PYTHON_BUILD_HTTP_CLIENT="curl" @test "package URL without checksum" { diff --git a/plugins/python-build/test/fetch.bats b/plugins/python-build/test/fetch.bats index 48b058ce..a2a41759 100644 --- a/plugins/python-build/test/fetch.bats +++ b/plugins/python-build/test/fetch.bats @@ -3,8 +3,6 @@ load test_helper export PYTHON_BUILD_SKIP_MIRROR=1 export PYTHON_BUILD_CACHE_PATH= -export PYTHON_BUILD_ARIA2_OPTS= -export PYTHON_BUILD_HTTP_CLIENT="curl" setup() { export PYTHON_BUILD_BUILD_PATH="${TMP}/source" @@ -21,6 +19,7 @@ setup() { } @test "using aria2c if available" { + export PYTHON_BUILD_ARIA2_OPTS= export PYTHON_BUILD_HTTP_CLIENT="aria2c" stub aria2c "--allow-overwrite=true --no-conf=true -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4" diff --git a/plugins/python-build/test/mirror.bats b/plugins/python-build/test/mirror.bats index 0ee26b4f..62ed38c0 100644 --- a/plugins/python-build/test/mirror.bats +++ b/plugins/python-build/test/mirror.bats @@ -4,8 +4,6 @@ load test_helper export PYTHON_BUILD_SKIP_MIRROR= export PYTHON_BUILD_CACHE_PATH= export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com -export PYTHON_BUILD_CURL_OPTS= -export PYTHON_BUILD_HTTP_CLIENT="curl" @test "package URL without checksum bypasses mirror" { diff --git a/plugins/python-build/test/test_helper.bash b/plugins/python-build/test/test_helper.bash index 74607ddd..f959dd19 100644 --- a/plugins/python-build/test/test_helper.bash +++ b/plugins/python-build/test/test_helper.bash @@ -1,4 +1,6 @@ export TMP="$BATS_TEST_DIRNAME/tmp" +export RUBY_BUILD_CURL_OPTS= +export RUBY_BUILD_HTTP_CLIENT="curl" if [ "$FIXTURE_ROOT" != "$BATS_TEST_DIRNAME/fixtures" ]; then export FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures" diff --git a/test/test_helper.bash b/test/test_helper.bash index ed9bbb2c..e11cd8f1 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,6 +1,5 @@ unset PYENV_VERSION unset PYENV_DIR -unset PYTHON_BUILD_HTTP_CLIENT # guard against executing this block twice due to bats internals if [ -z "$PYENV_TEST_DIR" ]; then