From 1f76effbfb19977eb856090201b9e766709c334c Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 27 Dec 2013 18:44:54 +0900 Subject: [PATCH 1/3] Import changes from ruby-build v20131225.1 --- plugins/python-build/bin/pyenv-install | 18 +++++++--- plugins/python-build/bin/python-build | 49 +++++++++++++++++++------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/plugins/python-build/bin/pyenv-install b/plugins/python-build/bin/pyenv-install index 718a02f4..9dbe9094 100755 --- a/plugins/python-build/bin/pyenv-install +++ b/plugins/python-build/bin/pyenv-install @@ -1,17 +1,21 @@ #!/usr/bin/env bash # -# Summary: Install a Python version using the python-build plugin +# Summary: Install a Python version using python-build # -# Usage: pyenv install [-f|--force] [-g|--debug] [-k|--keep] [-v|--verbose] -# pyenv install [-f|--force] [-g|--debug] [-k|--keep] [-v|--verbose] +# Usage: pyenv install [-f] [-kvp] +# pyenv install [-f] [-kvp] # pyenv install -l|--list # # -l/--list List all available versions # -f/--force Install even if the version appears to be installed already +# +# python-build options: +# # -k/--keep Keep source tree in $PYENV_BUILD_ROOT after installation # (defaults to $PYENV_ROOT/sources) -# -g/--debug Build a debug version # -v/--verbose Verbose mode: print compilation status to stdout +# -p/--patch Apply a patch from stdin before building +# -g/--debug Build a debug version # # For detailed information on installing Python versions with # python-build, including a list of environment variables for adjusting @@ -50,6 +54,7 @@ indent() { unset FORCE unset KEEP unset VERBOSE +unset HAS_PATCH unset DEBUG parse_options "$@" @@ -72,6 +77,9 @@ for option in "${OPTIONS[@]}"; do "v" | "verbose" ) VERBOSE="-v" ;; + "p" | "patch" ) + HAS_PATCH="-p" + ;; "g" | "debug" ) DEBUG="-g" ;; @@ -167,7 +175,7 @@ trap cleanup SIGINT # Invoke `python-build` and record the exit status in $STATUS. STATUS=0 -python-build $KEEP $VERBOSE $DEBUG "$DEFINITION" "$PREFIX" || STATUS="$?" +python-build $KEEP $VERBOSE $HAS_PATCH $DEBUG "$DEFINITION" "$PREFIX" || STATUS="$?" # Display a more helpful message if the definition wasn't found. if [ "$STATUS" == "2" ]; then diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index 7a8783aa..bda04de2 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -1,6 +1,6 @@ #!/usr/bin/env bash -PYTHON_BUILD_VERSION="20131211" +PYTHON_BUILD_VERSION="20131225.1" set -E exec 3<&2 # preserve original stderr at fd 3 @@ -307,16 +307,14 @@ fetch_tarball() { local tar_args="xzvf" local package_filename="${package_name}.tar.gz" - local package_suffix extract_option - case "${package_url}" in - *".tgz" ) - package_filename="${package_name}.tgz" - ;; - *".tar.bz2" ) - package_filename="${package_name}.tar.bz2" + if [ "$package_url" != "${package_url%tgz}" ]; then + package_filename="${package_filename%tar.gz}tgz" + fi + + if [ "$package_url" != "${package_url%bz2}" ]; then + package_filename="${package_filename%.gz}.bz2" tar_args="${tar_args/z/j}" - ;; - esac + fi if ! symlink_tarball_from_cache "$package_filename" "$checksum"; then echo "Downloading ${package_filename}..." >&2 @@ -527,6 +525,8 @@ build_package() { echo "Installing ${package_name}..." >&2 + [ -n "$HAS_PATCH" ] && apply_python_patch "$package_name" + for command in $commands; do "build_package_${command}" "$package_name" done @@ -677,6 +677,7 @@ build_package_jruby() { ln -fs jruby ruby install_jruby_launcher remove_windows_files + fix_jruby_shebangs } install_jruby_launcher() { @@ -685,6 +686,15 @@ install_jruby_launcher() { } >&4 2>&1 } +fix_jruby_shebangs() { + for file in "${PREFIX_PATH}/bin"/*; do + if [ "$(head -c 20 "$file")" = "#!/usr/bin/env jruby" ]; then + sed -i.bak -E "1s:.+:#\!${PREFIX_PATH}/bin/jruby:" "$file" + rm "$file".bak + fi + done +} + remove_windows_files() { cd "$PREFIX_PATH" rm -f bin/*.exe bin/*.dll bin/*.bat bin/jruby.sh @@ -1078,6 +1088,14 @@ isolated_gem_install() { gem install "$@" } +apply_python_patch() { + case "$1" in + Python-* | jython-* | pypy-* ) + patch -p0 -i "${2:--}" + ;; + esac +} + has_broken_mac_llvm_gcc() { [ "$(uname -s)" = "Darwin" ] && [[ "$(gcc --version 2>/dev/null || true)" == *"llvm-gcc-4.2"* ]] @@ -1208,7 +1226,7 @@ version() { usage() { { version - echo "usage: python-build [-g|--debug] [-k|--keep] [-v|--verbose] definition prefix" + echo "usage: python-build [-k|--keep] [-v|--verbose] [-p|--patch] [-g|--debug] definition prefix" echo " python-build --definitions" } >&2 @@ -1228,8 +1246,9 @@ list_definitions() { unset VERBOSE unset KEEP_BUILD_PATH -PYTHON_BUILD_ROOT="$(abs_dirname "$0")/.." +unset HAS_PATCH unset DEBUG +PYTHON_BUILD_ROOT="$(abs_dirname "$0")/.." parse_options "$@" @@ -1239,8 +1258,9 @@ for option in "${OPTIONS[@]}"; do usage without_exiting { echo echo " -k/--keep Do not remove source tree after installation" - echo " -g/--debug Build a debug version" 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 @@ -1256,6 +1276,9 @@ for option in "${OPTIONS[@]}"; do "v" | "verbose" ) VERBOSE=true ;; + "p" | "patch" ) + HAS_PATCH=true + ;; "g" | "debug" ) DEBUG=true ;; From 4953fa403435303fbb0d474cdadc21068b2bf768 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Mon, 30 Dec 2013 17:18:03 +0900 Subject: [PATCH 2/3] Apply built-in patches only if patch is not given via STDIN --- plugins/python-build/README.md | 4 -- plugins/python-build/bin/python-build | 96 ++++++++++----------------- 2 files changed, 36 insertions(+), 64 deletions(-) diff --git a/plugins/python-build/README.md b/plugins/python-build/README.md index 1044db64..c9dcf425 100644 --- a/plugins/python-build/README.md +++ b/plugins/python-build/README.md @@ -104,10 +104,6 @@ process. * `PYTHON_CONFIGURE_OPTS` and `PYTHON_MAKE_OPTS` allow you to specify configure and make options for buildling CPython. These variables will be passed to Python only, not any dependent packages (e.g. libyaml). -* `PYTHON_PATCH_PATH` allows you to specify a directory that contains - the patches for building CPython. All patches should be created - as same strip number (default `-p0`). `PYTHON_PATCH_OPTS` allows - you to override the options for `patch`. ### Checksum verification diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index bda04de2..085f3102 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -160,57 +160,12 @@ install_package_using() { } >&2 } -apply_patches() { - local package_name="$1" - - # Support PYTHON_PATCH, PYTHON_PATCH_OPTS, etc. - local package_var_name="$(capitalize "${package_name%%-*}")" - local PACKAGE_PATCH="${package_var_name}_PATCH" - local PACKAGE_PATCH_OPTS="${package_var_name}_PATCH_OPTS" - - if [ -z "${PATCH_OPTS+defined}" ] && [ -z "${!PACKAGE_PATCH_OPTS+defined}" ]; then - local PATCH_OPTS="-p0" - fi - - local patch - for patch in $(list_patches "${package_name}"); do - echo "Applying ${patch##*/} to ${package_name}..." >&2 - { ${!PACKAGE_PATCH:-patch} $PATCH_OPTS ${!PACKAGE_PATCH_OPTS} < "$patch" - } >&4 2>&1 - done -} - -list_patches() { - local package_name="$1" - - # Support PYTHON_PATCH_PATH, etc. - local package_var_name="$(capitalize "${package_name%%-*}")" - local PACKAGE_PATCH_PATH="${package_var_name}_PATCH_PATH" - - if [ "${!PACKAGE_PATCH_PATH+defined}" ]; then - # patch path may be given in relative from working directory - if [[ "${!PACKAGE_PATCH_PATH}" != /* ]]; then - local patch_path="${CWD}/${!PACKAGE_PATCH_PATH}" - else - local patch_path="${!PACKAGE_PATCH_PATH}" - fi - else - local patch_path="${PYTHON_BUILD_PATCH_PATH}/${package_name}" - fi - - { for patch in "${patch_path}"/*; do - [ -f "${patch}" ] && echo "${patch}" - done - } | sort -} - make_package() { local package_name="$1" shift pushd "$package_name" >&4 before_install_package "$package_name" - apply_patches "$package_name" build_package "$package_name" $* after_install_package "$package_name" fix_directory_permissions @@ -744,10 +699,28 @@ build_package_copy() { before_install_package() { local stub=1 + before_install_package_patch "$@" +} + +before_install_package_patch() { +# Apply built-in patches if patch was not given from stdin + if [ -z "$HAS_PATCH" ]; then + ( cat "${PYTHON_BUILD_ROOT}/share/python-build/patches/${DEFINITION_PATH##*/}/$1"/* || true ) 2>/dev/null 1>"$1.patch" + exec <&- + exec <"$1.patch" + fi + ORIG_HAS_PATCH="$HAS_PATCH" + HAS_PATCH=true } after_install_package() { local stub=1 + after_install_package_patch "$@" +} + +after_install_package_patch() { + rm -f "$1.patch" + HAS_PATCH="$ORIG_HAS_PATCH" } fix_directory_permissions() { @@ -973,13 +946,13 @@ has_broken_mac_readline() { } use_homebrew_readline() { - local libdir="$(brew --prefix readline 2>/dev/null || true)" - if [ -d "$libdir" ]; then - CPPFLAGS="-I$libdir/include $CPPFLAGS" - LDFLAGS="-L$libdir/lib $LDFLAGS" - else - return 1 - fi + local libdir="$(brew --prefix readline 2>/dev/null || true)" + if [ -d "$libdir" ]; then + CPPFLAGS="-I$libdir/include $CPPFLAGS" + LDFLAGS="-L$libdir/lib $LDFLAGS" + else + return 1 + fi } has_broken_mac_openssl() { @@ -1089,9 +1062,19 @@ isolated_gem_install() { } apply_python_patch() { + local package_name="$1" + + # Support PYTHON_PATCH_OPTS, etc. + local package_var_name="$(capitalize "${package_name%%-*}")" + local PACKAGE_PATCH_OPTS="${package_var_name}_PATCH_OPTS" + + if [ -z "${PATCH_OPTS+defined}" ] && [ -z "${!PACKAGE_PATCH_OPTS+defined}" ]; then + local PATCH_OPTS="-p0" + fi + case "$1" in Python-* | jython-* | pypy-* ) - patch -p0 -i "${2:--}" + ${PATCH:-patch} $PATCH_OPTS ${!PACKAGE_PATCH_OPTS} -i "${2:--}" ;; esac } @@ -1302,13 +1285,6 @@ elif [ ! -e "$DEFINITION_PATH" ]; then fi fi -if [ -z "$PYTHON_BUILD_PATCH_PATH" ]; then - # Find patches from "./patches" relatively from the definition path - PYTHON_BUILD_PATCH_PATH="$(abs_dirname "${DEFINITION_PATH}" 2>/dev/null)/patches/${DEFINITION_PATH##*/}" -else - PYTHON_BUILD_PATCH_PATH="$(abs_dirname "${PYTHON_BUILD_PATCH_PATH}/.." 2>/dev/null)" -fi - PREFIX_PATH="${ARGUMENTS[1]}" if [ -z "$PREFIX_PATH" ]; then usage From 8892f3735d7ad43cf0e3f21592b3af8dc5a9c71e Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Wed, 1 Jan 2014 12:21:29 +0900 Subject: [PATCH 3/3] Use `-p0` for all patches to keep things simple (sstephenson/ruby-build#484) There is filterdiff(1) available to transform strip level of a patch if optional level is required. ``` git diff HEAD^ | filterdiff --strip=1 | pyenv install -p 3.3.3 ``` --- plugins/python-build/bin/python-build | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index 085f3102..a7f1bfc3 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -1062,19 +1062,9 @@ isolated_gem_install() { } apply_python_patch() { - local package_name="$1" - - # Support PYTHON_PATCH_OPTS, etc. - local package_var_name="$(capitalize "${package_name%%-*}")" - local PACKAGE_PATCH_OPTS="${package_var_name}_PATCH_OPTS" - - if [ -z "${PATCH_OPTS+defined}" ] && [ -z "${!PACKAGE_PATCH_OPTS+defined}" ]; then - local PATCH_OPTS="-p0" - fi - case "$1" in Python-* | jython-* | pypy-* ) - ${PATCH:-patch} $PATCH_OPTS ${!PACKAGE_PATCH_OPTS} -i "${2:--}" + patch -p0 -i "${2:--}" ;; esac }