Import changes from ruby-build v20150112

This commit is contained in:
Yamashita Yuu 2015-01-15 23:13:36 +09:00
parent ba9c01ce77
commit 123b3af1a0
8 changed files with 135 additions and 32 deletions

View file

@ -106,6 +106,8 @@ for option in "${OPTIONS[@]}"; do
esac esac
done done
[ "${#ARGUMENTS[@]}" -le 1 ] || usage 1 >&2
unset VERSION_NAME unset VERSION_NAME
# The first argument contains the definition to install. If the # The first argument contains the definition to install. If the
@ -114,8 +116,7 @@ unset VERSION_NAME
# version is not specified. # version is not specified.
DEFINITION="${ARGUMENTS[0]}" DEFINITION="${ARGUMENTS[0]}"
[ -n "$DEFINITION" ] || DEFINITION="$(pyenv-local 2>/dev/null || true)" [ -n "$DEFINITION" ] || DEFINITION="$(pyenv-local 2>/dev/null || true)"
[ -n "$DEFINITION" ] || usage 1 [ -n "$DEFINITION" ] || usage 1 >&2
# Define `before_install` and `after_install` functions that allow # Define `before_install` and `after_install` functions that allow
# plugin hooks to register a string of code for execution before or # plugin hooks to register a string of code for execution before or

View file

@ -17,24 +17,32 @@ if [ "$1" = "--complete" ]; then
exec pyenv versions --bare exec pyenv versions --bare
fi fi
usage() {
# We can remove the sed fallback once pyenv 0.4.0 is widely available
pyenv-help uninstall 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
[ -z "$1" ] || exit "$1"
}
if [ -z "$PYENV_ROOT" ]; then if [ -z "$PYENV_ROOT" ]; then
PYENV_ROOT="${HOME}/.pyenv" PYENV_ROOT="${HOME}/.pyenv"
fi fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage 0
fi
unset FORCE unset FORCE
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
FORCE=true FORCE=true
shift shift
fi fi
[ "$#" -eq 1 ] || usage 1 >&2
DEFINITION="$1" DEFINITION="$1"
case "$DEFINITION" in case "$DEFINITION" in
"" | -* ) "" | -* )
# We can remove the sed fallback once pyenv 0.4.0 is widely available. usage 1 >&2
{ pyenv-help uninstall 2>/dev/null ||
sed -ne '/^#/!q;s/.\{1,2\}//;1,4d;p' < "$0"
} >&2
exit 1
;; ;;
esac esac

View file

@ -1,4 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# Usage: python-build [-kvp] <definition> <prefix>
# python-build --definitions
#
# -k/--keep Do not remove source tree after installation
# -v/--verbose Verbose mode: print compilation status to stdout
# -p/--patch Apply a patch from stdin before building
# --definitions List all built-in definitions
# -g/--debug Build a debug version
#
PYTHON_BUILD_VERSION="20141028" PYTHON_BUILD_VERSION="20141028"
@ -495,7 +505,7 @@ fetch_svn() {
if type svn &>/dev/null; then if type svn &>/dev/null; then
svn co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1 svn co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1
else else
echo "error: please install \`svn\` and try again" >&2 echo "error: please install Subversion and try again" >&2
exit 1 exit 1
fi fi
} }
@ -644,7 +654,6 @@ build_package_standard() {
local PACKAGE_MAKE_OPTS_ARRAY="${package_var_name}_MAKE_OPTS_ARRAY[@]" local PACKAGE_MAKE_OPTS_ARRAY="${package_var_name}_MAKE_OPTS_ARRAY[@]"
local PACKAGE_MAKE_INSTALL_OPTS="${package_var_name}_MAKE_INSTALL_OPTS" local PACKAGE_MAKE_INSTALL_OPTS="${package_var_name}_MAKE_INSTALL_OPTS"
local PACKAGE_MAKE_INSTALL_OPTS_ARRAY="${package_var_name}_MAKE_INSTALL_OPTS_ARRAY[@]" local PACKAGE_MAKE_INSTALL_OPTS_ARRAY="${package_var_name}_MAKE_INSTALL_OPTS_ARRAY[@]"
local PACKAGE_MAKE_INSTALL_TARGET="${package_var_name}_MAKE_INSTALL_TARGET"
local PACKAGE_CFLAGS="${package_var_name}_CFLAGS" local PACKAGE_CFLAGS="${package_var_name}_CFLAGS"
[ "$package_var_name" = "PYTHON" ] && use_homebrew_readline || true [ "$package_var_name" = "PYTHON" ] && use_homebrew_readline || true
@ -661,7 +670,7 @@ build_package_standard() {
) >&4 2>&1 ) >&4 2>&1
{ "$MAKE" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS} "${!PACKAGE_MAKE_OPTS_ARRAY}" { "$MAKE" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS} "${!PACKAGE_MAKE_OPTS_ARRAY}"
"$MAKE" "${!PACKAGE_MAKE_INSTALL_TARGET:-install}" $MAKE_INSTALL_OPTS ${!PACKAGE_MAKE_INSTALL_OPTS} "${!PACKAGE_MAKE_INSTALL_OPTS_ARRAY}" "$MAKE" install $MAKE_INSTALL_OPTS ${!PACKAGE_MAKE_INSTALL_OPTS} "${!PACKAGE_MAKE_INSTALL_OPTS_ARRAY}"
} >&4 2>&1 } >&4 2>&1
} }
@ -1098,7 +1107,15 @@ require_llvm() {
local llvm_version="$1" local llvm_version="$1"
if [ "$(uname -s)" = "Darwin" ] && [ "$(osx_version)" -ge 1010 ]; then if [ "$(uname -s)" = "Darwin" ] && [ "$(osx_version)" -ge 1010 ]; then
if [[ "$PYTHON_CONFIGURE_OPTS" != *--llvm-* ]]; then if [[ "$PYTHON_CONFIGURE_OPTS" != *--llvm-* ]]; then
package_option python configure --prebuilt-name="llvm-3.2-x86_64-apple-darwin13.tar.bz2" if [ "$llvm_version" = "3.2" ]; then
package_option python configure --prebuilt-name="llvm-3.2-x86_64-apple-darwin13.tar.bz2"
else
local llvm_prefix="$(brew --prefix llvm 2>/dev/null || true)"
local llvm_config="${llvm_prefix}/bin/llvm-config"
if [ -x "$llvm_config" ]; then
package_option python configure --llvm-config="$llvm_config"
fi
fi
fi fi
fi fi
} }
@ -1519,14 +1536,8 @@ version() {
} }
usage() { usage() {
{ version sed -ne '/^#/!q;s/.\{1,2\}//;1,2d;p' < "$0"
echo "usage: python-build [-k|--keep] [-v|--verbose] [-p|--patch] [-g|--debug] definition prefix" [ -z "$1" ] || exit "$1"
echo " python-build --definitions"
} >&2
if [ -z "$1" ]; then
exit 1
fi
} }
list_definitions() { list_definitions() {
@ -1558,16 +1569,9 @@ parse_options "$@"
for option in "${OPTIONS[@]}"; do for option in "${OPTIONS[@]}"; do
case "$option" in case "$option" in
"h" | "help" ) "h" | "help" )
usage without_exiting version
{ echo echo
echo " -k/--keep Do not remove source tree after installation" usage 0
echo " -v/--verbose Verbose mode: print compilation status to stdout"
echo " -p/--patch Apply a patch from stdin before building"
echo " -g/--debug Build a debug version"
echo " --definitions List all built-in definitions"
echo
} >&2
exit 0
;; ;;
"definitions" ) "definitions" )
list_definitions list_definitions
@ -1592,9 +1596,11 @@ for option in "${OPTIONS[@]}"; do
esac esac
done done
[ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1 >&2
DEFINITION_PATH="${ARGUMENTS[0]}" DEFINITION_PATH="${ARGUMENTS[0]}"
if [ -z "$DEFINITION_PATH" ]; then if [ -z "$DEFINITION_PATH" ]; then
usage usage 1 >&2
elif [ ! -f "$DEFINITION_PATH" ]; then elif [ ! -f "$DEFINITION_PATH" ]; then
for DEFINITION_DIR in "${PYTHON_BUILD_DEFINITIONS[@]}"; do for DEFINITION_DIR in "${PYTHON_BUILD_DEFINITIONS[@]}"; do
if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then
@ -1611,7 +1617,7 @@ fi
PREFIX_PATH="${ARGUMENTS[1]}" PREFIX_PATH="${ARGUMENTS[1]}"
if [ -z "$PREFIX_PATH" ]; then if [ -z "$PREFIX_PATH" ]; then
usage usage 1 >&2
elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
PREFIX_PATH="${PWD}/${PREFIX_PATH}" PREFIX_PATH="${PWD}/${PREFIX_PATH}"
fi fi

View file

@ -0,0 +1,23 @@
#!/usr/bin/env bats
load test_helper
@test "not enought arguments for python-build" {
# use empty inline definition so nothing gets built anyway
local definition="${TMP}/build-definition"
echo '' > "$definition"
run python-build "$definition"
assert_failure
assert_output_contains 'Usage: python-build'
}
@test "extra arguments for python-build" {
# use empty inline definition so nothing gets built anyway
local definition="${TMP}/build-definition"
echo '' > "$definition"
run python-build "$definition" "${TMP}/install" ""
assert_failure
assert_output_contains 'Usage: python-build'
}

View file

@ -5,6 +5,7 @@ export PYTHON_BUILD_CACHE_PATH="$TMP/cache"
export MAKE=make export MAKE=make
export MAKE_OPTS="-j 2" export MAKE_OPTS="-j 2"
export CC=cc export CC=cc
export -n PYTHON_CONFIGURE_OPTS
setup() { setup() {
mkdir -p "$INSTALL_ROOT" mkdir -p "$INSTALL_ROOT"
@ -449,6 +450,18 @@ OUT
# nop # nop
} }
@test "JRuby Java 7 missing" {
# nop
}
@test "JRuby Java is outdated" {
# nop
}
@test "JRuby Java 7 up-to-date" {
# nop
}
@test "non-writable TMPDIR aborts build" { @test "non-writable TMPDIR aborts build" {
export TMPDIR="${TMP}/build" export TMPDIR="${TMP}/build"
mkdir -p "$TMPDIR" mkdir -p "$TMPDIR"

View file

@ -5,8 +5,13 @@ export MAKE=make
export MAKE_OPTS='-j 2' export MAKE_OPTS='-j 2'
export -n CFLAGS export -n CFLAGS
export -n CC export -n CC
export -n PYTHON_CONFIGURE_OPTS
@test "require_gcc on OS X 10.9" { @test "require_gcc on OS X 10.9" {
# yyuu/pyenv#222
stub uname '-s : echo Darwin'
stub sw_vers '-productVersion : echo 10.9.5'
stub uname '-s : echo Darwin' stub uname '-s : echo Darwin'
stub sw_vers '-productVersion : echo 10.9.5' stub sw_vers '-productVersion : echo 10.9.5'
stub gcc '--version : echo 4.2.1' stub gcc '--version : echo 4.2.1'
@ -24,6 +29,10 @@ OUT
} }
@test "require_gcc on OS X 10.10" { @test "require_gcc on OS X 10.10" {
# yyuu/pyenv#222
stub uname '-s : echo Darwin'
stub sw_vers '-productVersion : echo 10.10'
stub uname '-s : echo Darwin' stub uname '-s : echo Darwin'
stub sw_vers '-productVersion : echo 10.10' stub sw_vers '-productVersion : echo 10.10'
stub gcc '--version : echo 4.2.1' stub gcc '--version : echo 4.2.1'
@ -36,7 +45,7 @@ DEF
assert_success assert_success
assert_output <<OUT assert_output <<OUT
CC=${TMP}/bin/gcc CC=${TMP}/bin/gcc
MACOSX_DEPLOYMENT_TARGET=10.10 MACOSX_DEPLOYMENT_TARGET=10.9
OUT OUT
} }

View file

@ -146,3 +146,42 @@ ${PYENV_ROOT}/plugins/bar/share/python-build
${PYENV_ROOT}/plugins/foo/share/python-build ${PYENV_ROOT}/plugins/foo/share/python-build
OUT OUT
} }
@test "not enough arguments for pyenv-install" {
stub_python_build
run pyenv-install
assert_failure
assert_output_contains 'Usage: pyenv install'
}
@test "too many arguments for pyenv-install" {
stub_python_build
run pyenv-install 3.4.1 3.4.2
assert_failure
assert_output_contains 'Usage: pyenv install'
}
@test "show help for pyenv-install" {
stub_python_build
run pyenv-install -h
assert_success
assert_output_contains 'Usage: pyenv install'
}
@test "not enough arguments pyenv-uninstall" {
run pyenv-uninstall
assert_failure
assert_output_contains 'Usage: pyenv uninstall'
}
@test "too many arguments for pyenv-uninstall" {
run pyenv-uninstall 3.4.1 3.4.2
assert_failure
assert_output_contains 'Usage: pyenv uninstall'
}
@test "show help for pyenv-uninstall" {
run pyenv-uninstall -h
assert_success
assert_output_contains 'Usage: pyenv uninstall'
}

View file

@ -115,6 +115,10 @@ assert_output() {
assert_output_contains() { assert_output_contains() {
local expected="$1" local expected="$1"
if [ -z "$expected" ]; then
echo "assert_output_contains needs an argument" >&2
return 1
fi
echo "$output" | $(type -p ggrep grep | head -1) -F "$expected" >/dev/null || { echo "$output" | $(type -p ggrep grep | head -1) -F "$expected" >/dev/null || {
{ echo "expected output to contain $expected" { echo "expected output to contain $expected"
echo "actual: $output" echo "actual: $output"