Commit 4351c469 by Mislav Marohnić

Add `--patch` flag to apply a Ruby patch from stdin

If `-p|--patch` flag was set while invoking `ruby-build` or
`rbenv install`, ruby-build will use `patch -p0 -i -` to apply a patch
from stdin to Ruby, Rubinius, or JRuby source code before running the
rest of `build_package_*` commands.

References #443
parent 6f9647d7
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
# #
# Summary: Install a Ruby version using the ruby-build plugin # Summary: Install a Ruby version using the ruby-build plugin
# #
# Usage: rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <version> # Usage: rbenv install [-f|--force] [-k|--keep] [-v|--verbose] [-p|--patch] <version>
# rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <definition-file> # rbenv install [-f|--force] [-k|--keep] [-v|--verbose] [-p|--patch] <definition-file>
# rbenv install -l|--list # rbenv install -l|--list
# #
# -l/--list List all available versions # -l/--list List all available versions
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
# -k/--keep Keep source tree in $RBENV_BUILD_ROOT after installation # -k/--keep Keep source tree in $RBENV_BUILD_ROOT after installation
# (defaults to $RBENV_ROOT/sources) # (defaults to $RBENV_ROOT/sources)
# -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
# #
# For detailed information on installing Ruby versions with # For detailed information on installing Ruby versions with
# ruby-build, including a list of environment variables for adjusting # ruby-build, including a list of environment variables for adjusting
...@@ -49,6 +50,7 @@ indent() { ...@@ -49,6 +50,7 @@ indent() {
unset FORCE unset FORCE
unset KEEP unset KEEP
unset VERBOSE unset VERBOSE
unset HAS_PATCH
parse_options "$@" parse_options "$@"
for option in "${OPTIONS[@]}"; do for option in "${OPTIONS[@]}"; do
...@@ -70,6 +72,9 @@ for option in "${OPTIONS[@]}"; do ...@@ -70,6 +72,9 @@ for option in "${OPTIONS[@]}"; do
"v" | "verbose" ) "v" | "verbose" )
VERBOSE="-v" VERBOSE="-v"
;; ;;
"p" | "patch" )
HAS_PATCH="-p"
;;
"version" ) "version" )
exec ruby-build --version exec ruby-build --version
;; ;;
...@@ -161,7 +166,7 @@ trap cleanup SIGINT ...@@ -161,7 +166,7 @@ trap cleanup SIGINT
# Invoke `ruby-build` and record the exit status in $STATUS. # Invoke `ruby-build` and record the exit status in $STATUS.
STATUS=0 STATUS=0
ruby-build $KEEP $VERBOSE "$DEFINITION" "$PREFIX" || STATUS="$?" ruby-build $KEEP $VERBOSE $HAS_PATCH "$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
......
...@@ -364,6 +364,8 @@ build_package() { ...@@ -364,6 +364,8 @@ build_package() {
echo "Installing ${package_name}..." >&2 echo "Installing ${package_name}..." >&2
[ -n "$HAS_PATCH" ] && apply_ruby_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
...@@ -770,13 +772,21 @@ isolated_gem_install() { ...@@ -770,13 +772,21 @@ isolated_gem_install() {
gem install "$@" gem install "$@"
} }
apply_ruby_patch() {
case "$1" in
ruby-* | jruby-* | rubinius-* )
patch -p0 -i "${2:--}"
;;
esac
}
version() { version() {
echo "ruby-build ${RUBY_BUILD_VERSION}" echo "ruby-build ${RUBY_BUILD_VERSION}"
} }
usage() { usage() {
{ version { version
echo "usage: ruby-build [-k|--keep] [-v|--verbose] definition prefix" echo "usage: ruby-build [-k|--keep] [-v|--verbose] [-p|--patch] definition prefix"
echo " ruby-build --definitions" echo " ruby-build --definitions"
} >&2 } >&2
...@@ -796,6 +806,7 @@ list_definitions() { ...@@ -796,6 +806,7 @@ list_definitions() {
unset VERBOSE unset VERBOSE
unset KEEP_BUILD_PATH unset KEEP_BUILD_PATH
unset HAS_PATCH
RUBY_BUILD_ROOT="$(abs_dirname "$0")/.." RUBY_BUILD_ROOT="$(abs_dirname "$0")/.."
parse_options "$@" parse_options "$@"
...@@ -807,6 +818,7 @@ for option in "${OPTIONS[@]}"; do ...@@ -807,6 +818,7 @@ for option in "${OPTIONS[@]}"; do
{ echo { echo
echo " -k/--keep Do not remove source tree after installation" echo " -k/--keep Do not remove source tree after installation"
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 " --definitions List all built-in definitions" echo " --definitions List all built-in definitions"
echo echo
} >&2 } >&2
...@@ -822,6 +834,9 @@ for option in "${OPTIONS[@]}"; do ...@@ -822,6 +834,9 @@ for option in "${OPTIONS[@]}"; do
"v" | "verbose" ) "v" | "verbose" )
VERBOSE=true VERBOSE=true
;; ;;
"p" | "patch" )
HAS_PATCH=true
;;
"version" ) "version" )
version version
exit 0 exit 0
......
...@@ -71,6 +71,30 @@ make -j 2 ...@@ -71,6 +71,30 @@ make -j 2
OUT OUT
} }
@test "apply ruby patch before building" {
cached_tarball "yaml-0.1.4"
cached_tarball "ruby-2.0.0"
stub brew false
stub_make_install
stub_make_install
stub patch ' : echo patch "$@" >> build.log'
install_fixture --patch definitions/needs-yaml
assert_success
unstub make
unstub patch
assert_build_log <<OUT
yaml-0.1.4: --prefix=$INSTALL_ROOT
make -j 2
patch -p0 -i -
ruby-2.0.0: --prefix=$INSTALL_ROOT
make -j 2
OUT
}
@test "yaml is linked from Homebrew" { @test "yaml is linked from Homebrew" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0"
......
...@@ -51,11 +51,18 @@ run_inline_definition() { ...@@ -51,11 +51,18 @@ run_inline_definition() {
} }
install_fixture() { install_fixture() {
local args
while [ "${1#-}" != "$1" ]; do
args="$args $1"
shift 1
done
local name="$1" local name="$1"
local destination="$2" local destination="$2"
[ -n "$destination" ] || destination="$INSTALL_ROOT" [ -n "$destination" ] || destination="$INSTALL_ROOT"
run ruby-build "$FIXTURE_ROOT/$name" "$destination" run ruby-build $args "$FIXTURE_ROOT/$name" "$destination"
} }
assert() { assert() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment