Use aria2c as the download if available (#534)

This commit is contained in:
Yamashita, Yuu 2016-02-08 12:27:46 +00:00
parent c8ab429d7b
commit b116f341fe
7 changed files with 67 additions and 50 deletions

View file

@ -323,7 +323,9 @@ http() {
local file="$3" local file="$3"
[ -n "$url" ] || return 1 [ -n "$url" ] || return 1
if type curl &>/dev/null; then if type aria2c &>/dev/null; then
"http_${method}_aria2c" "$url" "$file"
elif type curl &>/dev/null; then
"http_${method}_curl" "$url" "$file" "http_${method}_curl" "$url" "$file"
elif type wget &>/dev/null; then elif type wget &>/dev/null; then
"http_${method}_wget" "$url" "$file" "http_${method}_wget" "$url" "$file"
@ -333,6 +335,20 @@ http() {
fi fi
} }
http_head_aria2c() {
options=""
[ -n "${IPV4}" ] && options="--disable-ipv6=true"
[ -n "${IPV6}" ] && options="--disable-ipv6=false"
aria2c -q --dry-run ${options} "$1" >&4 2>&1
}
http_get_aria2c() {
options=""
[ -n "${IPV4}" ] && options="--disable-ipv6=true"
[ -n "${IPV6}" ] && options="--disable-ipv6=false"
aria2c -q -o "${2:--}" ${options} "$1"
}
http_head_curl() { http_head_curl() {
options="" options=""
[ -n "${IPV4}" ] && options="--ipv4" [ -n "${IPV4}" ] && options="--ipv4"

View file

@ -10,7 +10,7 @@ export -n PYTHON_CONFIGURE_OPTS
setup() { setup() {
mkdir -p "$INSTALL_ROOT" mkdir -p "$INSTALL_ROOT"
stub md5 false stub md5 false
stub curl false stub aria2c false
} }
executable() { executable() {

View file

@ -10,19 +10,19 @@ setup() {
@test "packages are saved to download cache" { @test "packages are saved to download cache" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/without-checksum install_fixture definitions/without-checksum
assert_success assert_success
assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub curl unstub aria2c
} }
@test "cached package without checksum" { @test "cached package without checksum" {
stub curl stub aria2c
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_CACHE_PATH" cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_CACHE_PATH"
@ -31,13 +31,13 @@ setup() {
assert_success assert_success
assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub curl unstub aria2c
} }
@test "cached package with valid checksum" { @test "cached package with valid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl stub aria2c
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_CACHE_PATH" cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_CACHE_PATH"
@ -47,7 +47,7 @@ setup() {
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@ -57,8 +57,8 @@ setup() {
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub shasum true "echo invalid" "echo $checksum" stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* : true" \ stub aria2c "-q --dry-run * : true" \
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" "-q -o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
touch "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" touch "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"
@ -69,13 +69,13 @@ setup() {
assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ] assert [ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
assert diff -q "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz" assert diff -q "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz"
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@test "nonexistent cache directory is ignored" { @test "nonexistent cache directory is ignored" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
export PYTHON_BUILD_CACHE_PATH="${TMP}/nonexistent" export PYTHON_BUILD_CACHE_PATH="${TMP}/nonexistent"
@ -85,5 +85,5 @@ setup() {
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
refute [ -d "$PYTHON_BUILD_CACHE_PATH" ] refute [ -d "$PYTHON_BUILD_CACHE_PATH" ]
unstub curl unstub aria2c
} }

View file

@ -6,102 +6,103 @@ export PYTHON_BUILD_CACHE_PATH=
@test "package URL without checksum" { @test "package URL without checksum" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/without-checksum install_fixture definitions/without-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
} }
@test "package URL with valid checksum" { @test "package URL with valid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@test "package URL with invalid checksum" { @test "package URL with invalid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-invalid-checksum install_fixture definitions/with-invalid-checksum
assert_failure assert_failure
refute [ -f "${INSTALL_ROOT}/bin/package" ] refute [ -f "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@test "package URL with checksum but no shasum support" { @test "package URL with checksum but no shasum support" {
stub shasum false stub shasum false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@test "package URL with valid md5 checksum" { @test "package URL with valid md5 checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677" stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-md5-checksum install_fixture definitions/with-md5-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub md5 unstub md5
} }
@test "package URL with md5 checksum but no md5 support" { @test "package URL with md5 checksum but no md5 support" {
stub md5 false stub md5 false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-md5-checksum install_fixture definitions/with-md5-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub md5 unstub md5
} }
@test "package with invalid checksum" { @test "package with invalid checksum" {
stub shasum true "echo invalid" stub shasum true "echo invalid"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
assert_failure assert_failure
refute [ -f "${INSTALL_ROOT}/bin/package" ] refute [ -f "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@test "existing tarball in build location is reused" { @test "existing tarball in build location is reused" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub aria2c false
stub curl false stub curl false
stub wget false stub wget false
@ -125,7 +126,7 @@ DEF
stub shasum true \ stub shasum true \
"echo invalid" \ "echo invalid" \
"echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
export -n PYTHON_BUILD_CACHE_PATH export -n PYTHON_BUILD_CACHE_PATH
export PYTHON_BUILD_BUILD_PATH="${TMP}/build" export PYTHON_BUILD_BUILD_PATH="${TMP}/build"
@ -144,7 +145,7 @@ DEF
} }
@test "package URL with checksum of unexpected length" { @test "package URL with checksum of unexpected length" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
run_inline_definition <<DEF run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#checksum_of_unexpected_length" copy install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#checksum_of_unexpected_length" copy

View file

@ -10,7 +10,7 @@ setup() {
} }
@test "failed download displays error message" { @test "failed download displays error message" {
stub curl false stub aria2c false
install_fixture definitions/without-checksum install_fixture definitions/without-checksum
assert_failure assert_failure

View file

@ -8,7 +8,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
@test "package URL without checksum bypasses mirror" { @test "package URL without checksum bypasses mirror" {
stub shasum true stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/without-checksum install_fixture definitions/without-checksum
echo "$output" >&2 echo "$output" >&2
@ -16,21 +16,21 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@test "package URL with checksum but no shasum support bypasses mirror" { @test "package URL with checksum but no shasum support bypasses mirror" {
stub shasum false stub shasum false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@ -40,15 +40,15 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum" local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum"
stub shasum true "echo $checksum" stub shasum true "echo $checksum"
stub curl "-*I* $mirror_url : true" \ stub aria2c "-q --dry-run $mirror_url : true" \
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" "-q -o * $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@ -58,15 +58,15 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum" local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum"
stub shasum true "echo $checksum" stub shasum true "echo $checksum"
stub curl "-*I* $mirror_url : false" \ stub aria2c "-q --dry-run $mirror_url : false" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@ -76,9 +76,9 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum" local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum"
stub shasum true "echo invalid" "echo $checksum" stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* $mirror_url : true" \ stub aria2c "-q --dry-run $mirror_url : true" \
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \ "-q -o * $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" "-q -o * http://example.com/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
echo "$output" >&2 echo "$output" >&2
@ -86,7 +86,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@ -96,15 +96,15 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub shasum true "echo $checksum" stub shasum true "echo $checksum"
stub curl "-*I* : true" \ stub aria2c "-q --dry-run : true" \
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \ "-q -o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }
@ -114,7 +114,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub shasum true "echo $checksum" stub shasum true "echo $checksum"
stub curl "-q -o * -*S* https://www.python.org/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub aria2c "-q -o * https://www.python.org/* : cp $FIXTURE_ROOT/\${4##*/} \$3"
run_inline_definition <<DEF run_inline_definition <<DEF
install_package "package-1.0.0" "https://www.python.org/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy install_package "package-1.0.0" "https://www.python.org/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
@ -123,6 +123,6 @@ DEF
assert_success assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ] assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl unstub aria2c
unstub shasum unstub shasum
} }

View file

@ -11,7 +11,7 @@ export TMP_FIXTURES="$TMP/fixtures"
setup() { setup() {
mkdir -p "$INSTALL_ROOT" mkdir -p "$INSTALL_ROOT"
stub md5 false stub md5 false
stub curl false stub aria2c false
} }
executable() { executable() {