Browse Source

Merge branch 'ruby-build-style-patching'

Yamashita Yuu 10 years ago
parent
commit
e1a5b326e4
3 changed files with 74 additions and 81 deletions
  1. +0
    -4
      plugins/python-build/README.md
  2. +13
    -5
      plugins/python-build/bin/pyenv-install
  3. +61
    -72
      plugins/python-build/bin/python-build

+ 0
- 4
plugins/python-build/README.md View File

@ -104,10 +104,6 @@ process.
* `PYTHON_CONFIGURE_OPTS` and `PYTHON_MAKE_OPTS` allow you to specify * `PYTHON_CONFIGURE_OPTS` and `PYTHON_MAKE_OPTS` allow you to specify
configure and make options for buildling CPython. These variables will configure and make options for buildling CPython. These variables will
be passed to Python only, not any dependent packages (e.g. libyaml). 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 ### Checksum verification

+ 13
- 5
plugins/python-build/bin/pyenv-install View File

@ -1,17 +1,21 @@
#!/usr/bin/env bash #!/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] <version>
# pyenv install [-f|--force] [-g|--debug] [-k|--keep] [-v|--verbose] <definition-file>
# Usage: pyenv install [-f] [-kvp] <version>
# pyenv install [-f] [-kvp] <definition-file>
# pyenv install -l|--list # pyenv install -l|--list
# #
# -l/--list List all available versions # -l/--list List all available versions
# -f/--force Install even if the version appears to be installed already # -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 # -k/--keep Keep source tree in $PYENV_BUILD_ROOT after installation
# (defaults to $PYENV_ROOT/sources) # (defaults to $PYENV_ROOT/sources)
# -g/--debug Build a debug version
# -v/--verbose Verbose mode: print compilation status to stdout # -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 # For detailed information on installing Python versions with
# python-build, including a list of environment variables for adjusting # python-build, including a list of environment variables for adjusting
@ -50,6 +54,7 @@ indent() {
unset FORCE unset FORCE
unset KEEP unset KEEP
unset VERBOSE unset VERBOSE
unset HAS_PATCH
unset DEBUG unset DEBUG
parse_options "$@" parse_options "$@"
@ -72,6 +77,9 @@ for option in "${OPTIONS[@]}"; do
"v" | "verbose" ) "v" | "verbose" )
VERBOSE="-v" VERBOSE="-v"
;; ;;
"p" | "patch" )
HAS_PATCH="-p"
;;
"g" | "debug" ) "g" | "debug" )
DEBUG="-g" DEBUG="-g"
;; ;;
@ -167,7 +175,7 @@ trap cleanup SIGINT
# Invoke `python-build` and record the exit status in $STATUS. # Invoke `python-build` and record the exit status in $STATUS.
STATUS=0 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. # Display a more helpful message if the definition wasn't found.
if [ "$STATUS" == "2" ]; then if [ "$STATUS" == "2" ]; then

+ 61
- 72
plugins/python-build/bin/python-build View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
PYTHON_BUILD_VERSION="20131211"
PYTHON_BUILD_VERSION="20131225.1"
set -E set -E
exec 3<&2 # preserve original stderr at fd 3 exec 3<&2 # preserve original stderr at fd 3
@ -160,57 +160,12 @@ install_package_using() {
} >&2 } >&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() { make_package() {
local package_name="$1" local package_name="$1"
shift shift
pushd "$package_name" >&4 pushd "$package_name" >&4
before_install_package "$package_name" before_install_package "$package_name"
apply_patches "$package_name"
build_package "$package_name" $* build_package "$package_name" $*
after_install_package "$package_name" after_install_package "$package_name"
fix_directory_permissions fix_directory_permissions
@ -307,16 +262,14 @@ fetch_tarball() {
local tar_args="xzvf" local tar_args="xzvf"
local package_filename="${package_name}.tar.gz" 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}" tar_args="${tar_args/z/j}"
;;
esac
fi
if ! symlink_tarball_from_cache "$package_filename" "$checksum"; then if ! symlink_tarball_from_cache "$package_filename" "$checksum"; then
echo "Downloading ${package_filename}..." >&2 echo "Downloading ${package_filename}..." >&2
@ -527,6 +480,8 @@ build_package() {
echo "Installing ${package_name}..." >&2 echo "Installing ${package_name}..." >&2
[ -n "$HAS_PATCH" ] && apply_python_patch "$package_name"
for command in $commands; do for command in $commands; do
"build_package_${command}" "$package_name" "build_package_${command}" "$package_name"
done done
@ -677,6 +632,7 @@ build_package_jruby() {
ln -fs jruby ruby ln -fs jruby ruby
install_jruby_launcher install_jruby_launcher
remove_windows_files remove_windows_files
fix_jruby_shebangs
} }
install_jruby_launcher() { install_jruby_launcher() {
@ -685,6 +641,15 @@ install_jruby_launcher() {
} >&4 2>&1 } >&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() { remove_windows_files() {
cd "$PREFIX_PATH" cd "$PREFIX_PATH"
rm -f bin/*.exe bin/*.dll bin/*.bat bin/jruby.sh rm -f bin/*.exe bin/*.dll bin/*.bat bin/jruby.sh
@ -734,10 +699,28 @@ build_package_copy() {
before_install_package() { before_install_package() {
local stub=1 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() { after_install_package() {
local stub=1 local stub=1
after_install_package_patch "$@"
}
after_install_package_patch() {
rm -f "$1.patch"
HAS_PATCH="$ORIG_HAS_PATCH"
} }
fix_directory_permissions() { fix_directory_permissions() {
@ -963,13 +946,13 @@ has_broken_mac_readline() {
} }
use_homebrew_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() { has_broken_mac_openssl() {
@ -1078,6 +1061,14 @@ isolated_gem_install() {
gem install "$@" gem install "$@"
} }
apply_python_patch() {
case "$1" in
Python-* | jython-* | pypy-* )
patch -p0 -i "${2:--}"
;;
esac
}
has_broken_mac_llvm_gcc() { has_broken_mac_llvm_gcc() {
[ "$(uname -s)" = "Darwin" ] && [ "$(uname -s)" = "Darwin" ] &&
[[ "$(gcc --version 2>/dev/null || true)" == *"llvm-gcc-4.2"* ]] [[ "$(gcc --version 2>/dev/null || true)" == *"llvm-gcc-4.2"* ]]
@ -1208,7 +1199,7 @@ version() {
usage() { usage() {
{ version { 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" echo " python-build --definitions"
} >&2 } >&2
@ -1228,8 +1219,9 @@ list_definitions() {
unset VERBOSE unset VERBOSE
unset KEEP_BUILD_PATH unset KEEP_BUILD_PATH
PYTHON_BUILD_ROOT="$(abs_dirname "$0")/.."
unset HAS_PATCH
unset DEBUG unset DEBUG
PYTHON_BUILD_ROOT="$(abs_dirname "$0")/.."
parse_options "$@" parse_options "$@"
@ -1239,8 +1231,9 @@ for option in "${OPTIONS[@]}"; do
usage without_exiting usage without_exiting
{ echo { echo
echo " -k/--keep Do not remove source tree after installation" 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 " -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 " --definitions List all built-in definitions"
echo echo
} >&2 } >&2
@ -1256,6 +1249,9 @@ for option in "${OPTIONS[@]}"; do
"v" | "verbose" ) "v" | "verbose" )
VERBOSE=true VERBOSE=true
;; ;;
"p" | "patch" )
HAS_PATCH=true
;;
"g" | "debug" ) "g" | "debug" )
DEBUG=true DEBUG=true
;; ;;
@ -1279,13 +1275,6 @@ elif [ ! -e "$DEFINITION_PATH" ]; then
fi fi
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]}" PREFIX_PATH="${ARGUMENTS[1]}"
if [ -z "$PREFIX_PATH" ]; then if [ -z "$PREFIX_PATH" ]; then
usage usage

Loading…
Cancel
Save