Import changes from ruby-build v20140524

This commit is contained in:
Yamashita Yuu 2014-06-03 11:41:47 +09:00
parent 3290973990
commit 9dac275567
7 changed files with 158 additions and 66 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
PYTHON_BUILD_VERSION="20140420"
PYTHON_BUILD_VERSION="20140524"
set -E
exec 3<&2 # preserve original stderr at fd 3
@ -184,14 +184,31 @@ make_package() {
popd >&4
}
compute_sha2() {
local output
if type shasum &>/dev/null; then
output="$(shasum -a 256 -b)" || return 1
echo "${output% *}"
elif type openssl &>/dev/null; then
output="$(openssl dgst -sha256)" || return 1
echo "${output##* }"
elif type sha256sum &>/dev/null; then
output="$(sha256sum --quiet)" || return 1
echo "${output% *}"
else
return 1
fi
}
compute_md5() {
local output
if type md5 &>/dev/null; then
md5 -q
elif type openssl &>/dev/null; then
local output="$(openssl md5)"
output="$(openssl md5)" || return 1
echo "${output##* }"
elif type md5sum &>/dev/null; then
local output="$(md5sum -b)"
output="$(md5sum -b)" || return 1
echo "${output% *}"
else
return 1
@ -199,8 +216,9 @@ compute_md5() {
}
verify_checksum() {
# If there's no MD5 support, return success
[ -n "$HAS_MD5_SUPPORT" ] || return 0
# If there's no SHA2 support, return success
[ -n "$HAS_SHA2_SUPPORT" ] || return 0
local checksum_command="compute_sha2"
# If the specified filename doesn't exist, return success
local filename="$1"
@ -210,8 +228,14 @@ verify_checksum() {
local expected_checksum=`echo "$2" | tr [A-Z] [a-z]`
[ -n "$expected_checksum" ] || return 0
# If the checksum length is 32 chars, assume MD5, otherwise SHA2
if [ "${#expected_checksum}" -eq 32 ]; then
[ -n "$HAS_MD5_SUPPORT" ] || return 0
checksum_command="compute_md5"
fi
# If the computed checksum is empty, return failure
local computed_checksum=`echo "$(compute_md5 < "$filename")" | tr [A-Z] [a-z]`
local computed_checksum=`echo "$($checksum_command < "$filename")" | tr [A-Z] [a-z]`
[ -n "$computed_checksum" ] || return 1
if [ "$expected_checksum" != "$computed_checksum" ]; then
@ -1201,9 +1225,15 @@ isolated_gem_install() {
}
apply_python_patch() {
local patchfile
case "$1" in
Python-* | jython-* | pypy-* )
patch -p0 -i "${2:--}"
patchfile="$(mktemp "${TMP}/python-patch.XXXXXX")"
cat "${2:--}" >"$patchfile"
local striplevel=0
grep -q '^diff --git a/' "$patchfile" && striplevel=1
patch -p$striplevel --force -i "$patchfile"
;;
esac
}
@ -1453,6 +1483,13 @@ if [ -n "$PYTHON_BUILD_SKIP_MIRROR" ]; then
unset PYTHON_BUILD_MIRROR_URL
fi
if echo test | compute_sha2 >/dev/null; then
HAS_SHA2_SUPPORT=1
else
unset HAS_SHA2_SUPPORT
unset PYTHON_BUILD_MIRROR_URL
fi
if echo test | compute_md5 >/dev/null; then
HAS_MD5_SUPPORT=1
else

View file

@ -88,9 +88,9 @@ OUT
stub brew false
stub_make_install
stub_make_install
stub patch ' : echo patch "$@" >> build.log'
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
install_fixture --patch definitions/needs-yaml
TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml <<<""
assert_success
unstub make
@ -101,7 +101,35 @@ yaml-0.1.6: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
yaml-0.1.6: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
make -j 2
make install
patch -p0 -i -
patch -p0 --force -i $TMP/python-patch.XXX
Python-3.2.1: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
Python-3.2.1: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
make -j 2
make install
OUT
}
@test "apply python patch from git diff before building" {
cached_tarball "yaml-0.1.6"
cached_tarball "Python-3.2.1"
stub brew false
stub_make_install
stub_make_install
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml <<<"diff --git a/script.py"
assert_success
unstub make
unstub patch
assert_build_log <<OUT
yaml-0.1.6: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
yaml-0.1.6: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
make -j 2
make install
patch -p1 --force -i $TMP/python-patch.XXX
Python-3.2.1: CPPFLAGS="-I${TMP}/install/include " LDFLAGS="-L${TMP}/install/lib "
Python-3.2.1: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
make -j 2

View file

@ -10,7 +10,7 @@ setup() {
@test "packages are saved to download cache" {
stub md5 true
stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
@ -18,12 +18,12 @@ setup() {
[ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub curl
unstub md5
unstub shasum
}
@test "cached package without checksum" {
stub md5 true
stub shasum true
stub curl
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_CACHE_PATH"
@ -33,12 +33,12 @@ setup() {
[ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub curl
unstub md5
unstub shasum
}
@test "cached package with valid checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_CACHE_PATH"
@ -49,15 +49,15 @@ setup() {
[ -e "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub curl
unstub md5
unstub shasum
}
@test "cached package with invalid checksum falls back to mirror and updates cache" {
export PYTHON_BUILD_SKIP_MIRROR=
local checksum="83e6d7725e20166024a1eb74cde80677"
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub md5 true "echo invalid" "echo $checksum"
stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* : true" \
"-q -o * -*S* http://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
@ -70,12 +70,12 @@ setup() {
diff -q "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz"
unstub curl
unstub md5
unstub shasum
}
@test "nonexistent cache directory is ignored" {
stub md5 true
stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export PYTHON_BUILD_CACHE_PATH="${TMP}/nonexistent"
@ -86,5 +86,5 @@ setup() {
[ ! -d "$PYTHON_BUILD_CACHE_PATH" ]
unstub curl
unstub md5
unstub shasum
}

View file

@ -6,7 +6,7 @@ export PYTHON_BUILD_CACHE_PATH=
@test "package URL without checksum" {
stub md5 true
stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
@ -14,41 +14,67 @@ export PYTHON_BUILD_CACHE_PATH=
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
unstub shasum
}
@test "package URL with valid checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
[ "$status" -eq 0 ]
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub shasum
}
@test "package URL with invalid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-invalid-checksum
[ "$status" -eq 1 ]
[ ! -f "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub shasum
}
@test "package URL with checksum but no shasum support" {
stub shasum false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
[ "$status" -eq 0 ]
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub shasum
}
@test "package URL with valid md5 checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-md5-checksum
[ "$status" -eq 0 ]
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
}
@test "package URL with invalid checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-invalid-checksum
[ "$status" -eq 1 ]
[ ! -f "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
}
@test "package URL with checksum but no MD5 support" {
@test "package URL with md5 checksum but no md5 support" {
stub md5 false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
install_fixture definitions/with-md5-checksum
[ "$status" -eq 0 ]
[ -x "${INSTALL_ROOT}/bin/package" ]
@ -58,7 +84,7 @@ export PYTHON_BUILD_CACHE_PATH=
@test "package with invalid checksum" {
stub md5 true "echo invalid"
stub shasum true "echo invalid"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
@ -66,11 +92,11 @@ export PYTHON_BUILD_CACHE_PATH=
[ ! -f "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
unstub shasum
}
@test "existing tarball in build location is reused" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl false
stub wget false
@ -81,19 +107,19 @@ export PYTHON_BUILD_CACHE_PATH=
ln -s "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$PYTHON_BUILD_BUILD_PATH"
run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#83e6d7725e20166024a1eb74cde80677" copy
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
DEF
assert_success
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub md5
unstub shasum
}
@test "existing tarball in build location is discarded if not matching checksum" {
stub md5 true \
stub shasum true \
"echo invalid" \
"echo 83e6d7725e20166024a1eb74cde80677"
"echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export -n PYTHON_BUILD_CACHE_PATH
@ -103,11 +129,11 @@ DEF
touch "${PYTHON_BUILD_BUILD_PATH}/package-1.0.0.tar.gz"
run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#83e6d7725e20166024a1eb74cde80677" copy
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
DEF
assert_success
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub md5
unstub shasum
}

View file

@ -1 +1 @@
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#83e6d7725e20166024a1eb74cde80677" copy
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy

View file

@ -0,0 +1 @@
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#83e6d7725e20166024a1eb74cde80677" copy

View file

@ -7,7 +7,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
@test "package URL without checksum bypasses mirror" {
stub md5 true
stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
@ -16,12 +16,12 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
unstub shasum
}
@test "package URL with checksum but no MD5 support bypasses mirror" {
stub md5 false
@test "package URL with checksum but no shasum support bypasses mirror" {
stub shasum false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
@ -29,15 +29,15 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
unstub shasum
}
@test "package URL with checksum hits mirror first" {
local checksum="83e6d7725e20166024a1eb74cde80677"
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum"
stub md5 true "echo $checksum"
stub shasum true "echo $checksum"
stub curl "-*I* $mirror_url : true" \
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
@ -46,15 +46,15 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
unstub shasum
}
@test "package is fetched from original URL if mirror download fails" {
local checksum="83e6d7725e20166024a1eb74cde80677"
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum"
stub md5 true "echo $checksum"
stub shasum true "echo $checksum"
stub curl "-*I* $mirror_url : false" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
@ -63,15 +63,15 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
unstub shasum
}
@test "package is fetched from original URL if mirror download checksum is invalid" {
local checksum="83e6d7725e20166024a1eb74cde80677"
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
local mirror_url="${PYTHON_BUILD_MIRROR_URL}/$checksum"
stub md5 true "echo invalid" "echo $checksum"
stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* $mirror_url : true" \
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
@ -82,15 +82,15 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
unstub shasum
}
@test "default mirror URL" {
export PYTHON_BUILD_MIRROR_URL=
local checksum="83e6d7725e20166024a1eb74cde80677"
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub md5 true "echo $checksum"
stub shasum true "echo $checksum"
stub curl "-*I* : true" \
"-q -o * -*S* http://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
@ -99,5 +99,5 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
unstub shasum
}