Merge branch 'apply-patch'

Closes #469
This commit is contained in:
Mislav Marohnić 2013-12-20 19:07:34 +01:00
commit 8ebfd1d0a9
5 changed files with 79 additions and 6 deletions

View file

@ -123,6 +123,25 @@ You can set certain environment variables to control the build process.
make options for buildling MRI. These variables will be passed to Ruby only,
not any dependent packages (e.g. libyaml).
### Applying patches to Ruby before compiling
Both `rbenv install` and `ruby-build` support the `--patch` (`-p`) flag that
signals that a patch from stdin should be applied to Ruby, JRuby, or Rubinius
source code before the `./configure` and compilation steps.
Example usage:
```sh
# applying a single patch
$ rbenv install --patch 1.9.3-p429 < /path/to/ruby.patch
# applying a patch from HTTP
$ rbenv install --patch 1.9.3-p429 < <(curl -sSL http://git.io/ruby.patch)
# applying multiple patches
$ cat fix1.patch fix2.patch | rbenv install --patch 1.9.3-p429
```
### Checksum verification
If you have the `md5`, `openssl`, or `md5sum` tool installed, ruby-build will

View file

@ -1,16 +1,20 @@
#!/usr/bin/env bash
#
# Summary: Install a Ruby version using the ruby-build plugin
# Summary: Install a Ruby version using ruby-build
#
# Usage: rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <version>
# rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <definition-file>
# Usage: rbenv install [-f] [-kvp] <version>
# rbenv install [-f] [-kvp] <definition-file>
# rbenv install -l|--list
#
# -l/--list List all available versions
# -f/--force Install even if the version appears to be installed already
#
# ruby-build options:
#
# -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 +53,7 @@ indent() {
unset FORCE
unset KEEP
unset VERBOSE
unset HAS_PATCH
parse_options "$@"
for option in "${OPTIONS[@]}"; do
@ -70,6 +75,9 @@ for option in "${OPTIONS[@]}"; do
"v" | "verbose" )
VERBOSE="-v"
;;
"p" | "patch" )
HAS_PATCH="-p"
;;
"version" )
exec ruby-build --version
;;
@ -161,7 +169,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

View file

@ -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
@ -783,13 +785,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
@ -809,6 +819,7 @@ list_definitions() {
unset VERBOSE
unset KEEP_BUILD_PATH
unset HAS_PATCH
RUBY_BUILD_ROOT="$(abs_dirname "$0")/.."
parse_options "$@"
@ -820,6 +831,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
@ -835,6 +847,9 @@ for option in "${OPTIONS[@]}"; do
"v" | "verbose" )
VERBOSE=true
;;
"p" | "patch" )
HAS_PATCH=true
;;
"version" )
version
exit 0

View file

@ -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"

View file

@ -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() {