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 @@
#
# Summary: Install a Ruby version using the ruby-build plugin
#
# Usage: rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <version>
# rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <definition-file>
# Usage: rbenv install [-f|--force] [-k|--keep] [-v|--verbose] [-p|--patch] <version>
# rbenv install [-f|--force] [-k|--keep] [-v|--verbose] [-p|--patch] <definition-file>
# rbenv install -l|--list
#
# -l/--list List all available versions
......@@ -11,6 +11,7 @@
# -k/--keep Keep source tree in $RBENV_BUILD_ROOT after installation
# (defaults to $RBENV_ROOT/sources)
# -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
# ruby-build, including a list of environment variables for adjusting
......@@ -49,6 +50,7 @@ indent() {
unset FORCE
unset KEEP
unset VERBOSE
unset HAS_PATCH
parse_options "$@"
for option in "${OPTIONS[@]}"; do
......@@ -70,6 +72,9 @@ for option in "${OPTIONS[@]}"; do
"v" | "verbose" )
VERBOSE="-v"
;;
"p" | "patch" )
HAS_PATCH="-p"
;;
"version" )
exec ruby-build --version
;;
......@@ -161,7 +166,7 @@ trap cleanup SIGINT
# Invoke `ruby-build` and record the exit status in $STATUS.
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.
if [ "$STATUS" == "2" ]; then
......
......@@ -364,6 +364,8 @@ build_package() {
echo "Installing ${package_name}..." >&2
[ -n "$HAS_PATCH" ] && apply_ruby_patch "$package_name"
for command in $commands; do
"build_package_${command}" "$package_name"
done
......@@ -770,13 +772,21 @@ isolated_gem_install() {
gem install "$@"
}
apply_ruby_patch() {
case "$1" in
ruby-* | jruby-* | rubinius-* )
patch -p0 -i "${2:--}"
;;
esac
}
version() {
echo "ruby-build ${RUBY_BUILD_VERSION}"
}
usage() {
{ 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"
} >&2
......@@ -796,6 +806,7 @@ list_definitions() {
unset VERBOSE
unset KEEP_BUILD_PATH
unset HAS_PATCH
RUBY_BUILD_ROOT="$(abs_dirname "$0")/.."
parse_options "$@"
......@@ -807,6 +818,7 @@ for option in "${OPTIONS[@]}"; do
{ echo
echo " -k/--keep Do not remove source tree after installation"
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
} >&2
......@@ -822,6 +834,9 @@ for option in "${OPTIONS[@]}"; do
"v" | "verbose" )
VERBOSE=true
;;
"p" | "patch" )
HAS_PATCH=true
;;
"version" )
version
exit 0
......
......@@ -71,6 +71,30 @@ make -j 2
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" {
cached_tarball "ruby-2.0.0"
......
......@@ -51,11 +51,18 @@ run_inline_definition() {
}
install_fixture() {
local args
while [ "${1#-}" != "$1" ]; do
args="$args $1"
shift 1
done
local name="$1"
local destination="$2"
[ -n "$destination" ] || destination="$INSTALL_ROOT"
run ruby-build "$FIXTURE_ROOT/$name" "$destination"
run ruby-build $args "$FIXTURE_ROOT/$name" "$destination"
}
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