Commit 8ebfd1d0 by Mislav Marohnić

Merge branch 'apply-patch'

Closes #469
parents 379cd32a f4a34da8
...@@ -123,6 +123,25 @@ You can set certain environment variables to control the build process. ...@@ -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, make options for buildling MRI. These variables will be passed to Ruby only,
not any dependent packages (e.g. libyaml). 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 ### Checksum verification
If you have the `md5`, `openssl`, or `md5sum` tool installed, ruby-build will If you have the `md5`, `openssl`, or `md5sum` tool installed, ruby-build will
......
#!/usr/bin/env bash #!/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> # Usage: rbenv install [-f] [-kvp] <version>
# rbenv install [-f|--force] [-k|--keep] [-v|--verbose] <definition-file> # rbenv install [-f] [-kvp] <definition-file>
# rbenv install -l|--list # rbenv 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
#
# ruby-build options:
#
# -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 +53,7 @@ indent() { ...@@ -49,6 +53,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 +75,9 @@ for option in "${OPTIONS[@]}"; do ...@@ -70,6 +75,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 +169,7 @@ trap cleanup SIGINT ...@@ -161,7 +169,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
...@@ -783,13 +785,21 @@ isolated_gem_install() { ...@@ -783,13 +785,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
...@@ -809,6 +819,7 @@ list_definitions() { ...@@ -809,6 +819,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 "$@"
...@@ -820,6 +831,7 @@ for option in "${OPTIONS[@]}"; do ...@@ -820,6 +831,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
...@@ -835,6 +847,9 @@ for option in "${OPTIONS[@]}"; do ...@@ -835,6 +847,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