Import recent changess from ruby-build v20140408

This commit is contained in:
Yamashita Yuu 2014-04-09 21:23:46 +09:00
parent 07037d9a5d
commit 986db22da8
7 changed files with 111 additions and 47 deletions

View file

@ -8,6 +8,7 @@
#
# -l/--list List all available versions
# -f/--force Install even if the version appears to be installed already
# -s/--skip-existing Skip if the version appears to be installed already
#
# python-build options:
#
@ -52,6 +53,7 @@ indent() {
}
unset FORCE
unset SKIP_EXISTING
unset KEEP
unset VERBOSE
unset HAS_PATCH
@ -71,6 +73,9 @@ for option in "${OPTIONS[@]}"; do
"f" | "force" )
FORCE=true
;;
"s" | "skip-existing" )
SKIP_EXISTING=true
;;
"k" | "keep" )
[ -n "${PYENV_BUILD_ROOT}" ] || PYENV_BUILD_ROOT="${PYENV_ROOT}/sources"
;;
@ -134,7 +139,8 @@ PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
# If the installation prefix exists, prompt for confirmation unless
# the --force option was specified.
if [ -z "$FORCE" ] && [ -d "${PREFIX}/bin" ]; then
if [ -d "${PREFIX}/bin" ]; then
if [ -z "$FORCE" ] && [ -z "$SKIP_EXISTING" ]; then
echo "pyenv: $PREFIX already exists" >&2
read -p "continue with installation? (y/N) "
@ -142,6 +148,12 @@ if [ -z "$FORCE" ] && [ -d "${PREFIX}/bin" ]; then
y* | Y* ) ;;
* ) exit 1 ;;
esac
elif [ -n "$SKIP_EXISTING" ]; then
# Since we know the python version is already installed, and are opting to
# not force installation of existing versions, we just `exit 0` here to
# leave things happy
exit 0
fi
fi
# If PYENV_BUILD_ROOT is set, always pass keep options to python-build.
@ -158,7 +170,7 @@ fi
# Default PYENV_VERSION to the friendly Python version. (The
# CPython installer requires an existing Python installation to run. An
# unsatisfied local python version can cause the installer to
# unsatisfied local .python-version file can cause the installer to
# fail.)
if [[ "${VERSION_NAME}" == [23]"."* ]]; then
for version in "${VERSION_NAME%-dev}" "${VERSION_NAME%.*}" "${VERSION_NAME%%.*}"; do

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
PYTHON_BUILD_VERSION="20140225"
PYTHON_BUILD_VERSION="20140408"
set -E
exec 3<&2 # preserve original stderr at fd 3
@ -245,7 +245,7 @@ http_head_curl() {
}
http_get_curl() {
curl -C - -o "${2:--}" -qsSLf "$1"
curl -q -o "${2:--}" -sSLf "$1"
}
http_head_wget() {
@ -253,7 +253,7 @@ http_head_wget() {
}
http_get_wget() {
wget -nv -c -O "${2:--}" "$1"
wget -nv -O "${2:--}" "$1"
}
fetch_tarball() {
@ -283,7 +283,7 @@ fetch_tarball() {
tar_args="${tar_args/z/j}"
fi
if ! symlink_tarball_from_cache "$package_filename" "$checksum"; then
if ! reuse_existing_tarball "$package_filename" "$checksum"; then
echo "Downloading ${package_filename}..." >&2
http head "$mirror_url" &&
download_tarball "$mirror_url" "$package_filename" "$checksum" ||
@ -300,13 +300,19 @@ fetch_tarball() {
} >&4 2>&1
}
symlink_tarball_from_cache() {
[ -n "$PYTHON_BUILD_CACHE_PATH" ] || return 1
reuse_existing_tarball() {
local package_filename="$1"
local cached_package_filename="${PYTHON_BUILD_CACHE_PATH}/$package_filename"
local checksum="$2"
# Reuse existing file in build location
if [ -e "$package_filename" ] && verify_checksum "$package_filename" "$checksum"; then
return 0
fi
# Reuse previously downloaded file in cache location
[ -n "$PYTHON_BUILD_CACHE_PATH" ] || return 1
local cached_package_filename="${PYTHON_BUILD_CACHE_PATH}/$package_filename"
[ -e "$cached_package_filename" ] || return 1
verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1
ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1
@ -429,7 +435,7 @@ fetch_jar() {
local package_filename="${package_name}.jar"
if ! symlink_tarball_from_cache "$package_filename" "$checksum"; then
if ! reuse_existing_tarball "$package_filename" "$checksum"; then
echo "Downloading ${package_filename}..." >&2
http head "$mirror_url" &&
download_tarball "$mirror_url" "$package_filename" "$checksum" ||
@ -463,7 +469,7 @@ fetch_zip() {
local package_filename="${package_name}.zip"
if ! symlink_tarball_from_cache "$package_filename" "$checksum"; then
if ! reuse_existing_tarball "$package_filename" "$checksum"; then
echo "Downloading ${package_filename}..." >&2
http head "$mirror_url" &&
download_tarball "$mirror_url" "$package_filename" "$checksum" ||
@ -497,7 +503,7 @@ fetch_script() {
local package_filename="${package_name}.sh" # TODO: extract suffix from ${package_url}
if ! symlink_tarball_from_cache "$package_filename" "$checksum"; then
if ! reuse_existing_tarball "$package_filename" "$checksum"; then
echo "Downloading ${package_filename}..." >&2
http head "$mirror_url" &&
download_tarball "$mirror_url" "$package_filename" "$checksum" ||
@ -860,7 +866,9 @@ fix_rbx_gem_binstubs() {
for file in "$gemdir"/*; do
binstub="${bindir}/${file##*/}"
rm -f "$binstub"
sed -E "s:^#\!.+:#\!${bindir}/ruby:" < "$file" > "$binstub"
{ echo "#!${bindir}/ruby"
cat "$file"
} > "$binstub"
chmod +x "$binstub"
done
rm -rf "$gemdir"

View file

@ -56,7 +56,7 @@ assert_build_log() {
}
@test "yaml is installed for python" {
cached_tarball "yaml-0.1.5"
cached_tarball "yaml-0.1.6"
cached_tarball "Python-3.2.1"
stub brew false
@ -69,7 +69,7 @@ assert_build_log() {
unstub make
assert_build_log <<OUT
yaml-0.1.5: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
yaml-0.1.6: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
make -j 2
make install
Python-3.2.1: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
@ -79,7 +79,7 @@ OUT
}
@test "apply python patch before building" {
cached_tarball "yaml-0.1.5"
cached_tarball "yaml-0.1.6"
cached_tarball "Python-3.2.1"
stub brew false
@ -94,7 +94,7 @@ OUT
unstub patch
assert_build_log <<OUT
yaml-0.1.5: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
yaml-0.1.6: --prefix=$INSTALL_ROOT --libdir=$INSTALL_ROOT/lib
make -j 2
make install
patch -p0 -i -
@ -153,6 +153,7 @@ OUT
@test "readline is not linked from Homebrew when explicitly defined" {
cached_tarball "Python-3.2.1"
# python-build
readline_libdir="$TMP/custom"
mkdir -p "$readline_libdir/include/readline"
touch "$readline_libdir/include/readline/rlconf.h"

View file

@ -11,7 +11,7 @@ setup() {
@test "packages are saved to download cache" {
stub md5 true
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
[ "$status" -eq 0 ]
@ -59,7 +59,7 @@ setup() {
stub md5 true "echo invalid" "echo $checksum"
stub curl "-*I* : true" \
"-C - -o * -*S* http://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4"
"-q -o * -*S* http://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
touch "${PYTHON_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"
@ -76,7 +76,7 @@ setup() {
@test "nonexistent cache directory is ignored" {
stub md5 true
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export PYTHON_BUILD_CACHE_PATH="${TMP}/nonexistent"

View file

@ -7,7 +7,7 @@ export PYTHON_BUILD_CACHE_PATH=
@test "package URL without checksum" {
stub md5 true
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
[ "$status" -eq 0 ]
@ -20,7 +20,7 @@ export PYTHON_BUILD_CACHE_PATH=
@test "package URL with valid checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
[ "$status" -eq 0 ]
@ -33,7 +33,7 @@ export PYTHON_BUILD_CACHE_PATH=
@test "package URL with invalid checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-invalid-checksum
[ "$status" -eq 1 ]
@ -46,7 +46,7 @@ export PYTHON_BUILD_CACHE_PATH=
@test "package URL with checksum but no MD5 support" {
stub md5 false
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
[ "$status" -eq 0 ]
@ -59,7 +59,7 @@ export PYTHON_BUILD_CACHE_PATH=
@test "package with invalid checksum" {
stub md5 true "echo invalid"
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
[ "$status" -eq 1 ]
@ -68,3 +68,46 @@ export PYTHON_BUILD_CACHE_PATH=
unstub curl
unstub md5
}
@test "existing tarball in build location is reused" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub curl false
stub wget false
export -n PYTHON_BUILD_CACHE_PATH
export PYTHON_BUILD_BUILD_PATH="${TMP}/build"
mkdir -p "$PYTHON_BUILD_BUILD_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
DEF
assert_success
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub md5
}
@test "existing tarball in build location is discarded if not matching checksum" {
stub md5 true \
"echo invalid" \
"echo 83e6d7725e20166024a1eb74cde80677"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export -n PYTHON_BUILD_CACHE_PATH
export PYTHON_BUILD_BUILD_PATH="${TMP}/build"
mkdir -p "$PYTHON_BUILD_BUILD_PATH"
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
DEF
assert_success
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub md5
}

View file

@ -1,2 +1,2 @@
install_package "yaml-0.1.5" "http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz" --if needs_yaml
install_package "yaml-0.1.6" "http://pyyaml.org/download/libyaml/yaml-0.1.6.tar.gz" --if needs_yaml
install_package "Python-3.2.1" "http://python.org/ftp/python/3.2.1/Python-3.2.1.tar.gz"

View file

@ -8,7 +8,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
@test "package URL without checksum bypasses mirror" {
stub md5 true
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
echo "$output" >&2
@ -22,7 +22,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
@test "package URL with checksum but no MD5 support bypasses mirror" {
stub md5 false
stub curl "-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
[ "$status" -eq 0 ]
@ -39,7 +39,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
stub md5 true "echo $checksum"
stub curl "-*I* $mirror_url : true" \
"-C - -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4"
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
install_fixture definitions/with-checksum
[ "$status" -eq 0 ]
@ -56,7 +56,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
stub md5 true "echo $checksum"
stub curl "-*I* $mirror_url : false" \
"-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
[ "$status" -eq 0 ]
@ -73,8 +73,8 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
stub md5 true "echo invalid" "echo $checksum"
stub curl "-*I* $mirror_url : true" \
"-C - -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4" \
"-C - -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${6##*/} \$4"
"-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"
install_fixture definitions/with-checksum
echo "$output" >&2
@ -92,7 +92,7 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
stub md5 true "echo $checksum"
stub curl "-*I* : true" \
"-C - -o * -*S* http://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4" \
"-q -o * -*S* http://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
install_fixture definitions/with-checksum
[ "$status" -eq 0 ]