Skip to content

Commit f68c8f5

Browse files
committed
Merge pull request rbenv#143 from raggi/keep_builds
Add options to keep the build directory around
2 parents 933b371 + fed031a commit f68c8f5

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ ruby-build provides an `rbenv-install` command that shortens this to:
5353

5454
$ rbenv install 1.9.2-p290
5555

56+
ruby-build supports $RUBY_BUILD_BUILD_PATH to override the location in which
57+
sources are downloaded and built. The -k/--keep flags will preserve this path
58+
after the build is complete.
59+
60+
rbenv-install also supports the -k/--keep flag, and additionally supports an
61+
environment variable option $RBENV_BUILD_ROOT that when set, will always build
62+
sources under that location, and keep the sources after build completion.
63+
5664
### Version History
5765

5866
#### 20120423

bin/rbenv-install

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ case "$DEFINITION" in
2323
} >&2
2424
exit 1
2525
;;
26+
"-k" | "--keep" )
27+
[ -z "${RBENV_BUILD_ROOT}" ] && RBENV_BUILD_ROOT="${RBENV_ROOT}/srcs"
28+
RUBY_BUILD_OPTIONS+=" -k"
29+
;;
2630
esac
2731

2832
VERSION_NAME="${DEFINITION##*/}"
2933
PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"
3034

31-
ruby-build "$DEFINITION" "$PREFIX"
32-
rbenv rehash
35+
# If RBENV_BUILD_ROOT is set, then always pass keep options to ruby-build
36+
if [ -n "${RBENV_BUILD_ROOT}" ]; then
37+
export RUBY_BUILD_BUILD_PATH="${RBENV_BUILD_ROOT}/${VERSION_NAME}"
38+
RUBY_BUILD_OPTIONS+=" -k"
39+
fi
40+
41+
ruby-build "$DEFINITION" "$PREFIX" "$RUBY_BUILD_OPTIONS"
42+
rbenv rehash

bin/ruby-build

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ build_failed() {
2828
echo "BUILD FAILED"
2929
echo
3030

31-
if ! rmdir "${TEMP_PATH}" 2>/dev/null; then
32-
echo "Inspect or clean up the working tree at ${TEMP_PATH}"
31+
if ! rmdir "${BUILD_PATH}" 2>/dev/null; then
32+
echo "Inspect or clean up the working tree at ${BUILD_PATH}"
3333

3434
if file_is_not_empty "$LOG_PATH"; then
3535
echo "Results logged to ${LOG_PATH}"
@@ -68,7 +68,7 @@ install_package_using() {
6868
local package_name="$3"
6969
shift 3
7070

71-
pushd "$TEMP_PATH" >&4
71+
pushd "$BUILD_PATH" >&4
7272
"fetch_${package_type}" "$package_name" $*
7373
shift $(($package_type_nargs))
7474
make_package "$package_name" $*
@@ -396,6 +396,15 @@ if [ -z "$PREFIX_PATH" ]; then
396396
usage
397397
fi
398398

399+
OPTIONS="$3"
400+
for option in $OPTIONS; do
401+
case "$option" in
402+
"-k" | "--keep" )
403+
KEEP_BUILD_PATH="y"
404+
;;
405+
esac
406+
done
407+
399408
if [ -z "$TMPDIR" ]; then
400409
TMP="/tmp"
401410
else
@@ -404,10 +413,15 @@ fi
404413

405414
SEED="$(date "+%Y%m%d%H%M%S").$$"
406415
LOG_PATH="${TMP}/ruby-build.${SEED}.log"
407-
TEMP_PATH="${TMP}/ruby-build.${SEED}"
408416
RUBY_BIN="${PREFIX_PATH}/bin/ruby"
409417
CWD="$(pwd)"
410418

419+
if [ -z $RUBY_BUILD_BUILD_PATH ]; then
420+
BUILD_PATH="${TMP}/ruby-build.${SEED}"
421+
else
422+
BUILD_PATH=$RUBY_BUILD_BUILD_PATH
423+
fi
424+
411425
exec 4<> "$LOG_PATH" # open the log file at fd 4
412426
if [ -n "$VERBOSE" ]; then
413427
tail -f "$LOG_PATH" &
@@ -421,7 +435,7 @@ unset RUBYOPT
421435
unset RUBYLIB
422436

423437
trap build_failed ERR
424-
mkdir -p "$TEMP_PATH"
438+
mkdir -p "$BUILD_PATH"
425439
source "$DEFINITION_PATH"
426-
rm -fr "$TEMP_PATH"
440+
[ -z "${KEEP_BUILD_PATH}" ] && rm -fr "$BUILD_PATH"
427441
trap - ERR

0 commit comments

Comments
 (0)