mirror of
https://github.com/rbenv/ruby-build.git
synced 2025-01-01 14:44:48 +01:00
Trap failures and print an error message. Use file descriptors to avoid swallowing errors.
This commit is contained in:
parent
1a8c14377f
commit
2b26f23dde
1 changed files with 24 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -E
|
||||
exec 3<&2 # preserve original stderr at fd 3
|
||||
|
||||
abs_dirname() {
|
||||
local cwd="$(pwd)"
|
||||
|
@ -16,12 +17,15 @@ abs_dirname() {
|
|||
cd "$cwd"
|
||||
}
|
||||
|
||||
log() {
|
||||
if [ -z "$VERBOSE" ]; then
|
||||
cat >>"$LOG_PATH"
|
||||
else
|
||||
tee -a "$LOG_PATH"
|
||||
fi
|
||||
build_failed() {
|
||||
{ echo
|
||||
echo "BUILD FAILED"
|
||||
echo
|
||||
echo "Inspect or clean up the working tree at ${TEMP_PATH}"
|
||||
echo "Results logged to ${LOG_PATH}"
|
||||
echo
|
||||
} >&3
|
||||
exit 1
|
||||
}
|
||||
|
||||
install_package() {
|
||||
|
@ -47,14 +51,14 @@ download_package() {
|
|||
|
||||
echo "Downloading ${package_url}..." >&2
|
||||
{ curl "$package_url" > "${package_name}.tar.gz"
|
||||
} 2>&1 | log
|
||||
} >&4 2>&1
|
||||
}
|
||||
|
||||
extract_package() {
|
||||
local package_name="$1"
|
||||
|
||||
{ tar xzvf "${package_name}.tar.gz"
|
||||
} 2>&1 | log
|
||||
} >&4 2>&1
|
||||
}
|
||||
|
||||
build_package() {
|
||||
|
@ -80,14 +84,14 @@ build_package_standard() {
|
|||
{ ./configure --prefix="$PREFIX_PATH"
|
||||
make -j 2
|
||||
make install
|
||||
} 2>&1 | log
|
||||
} >&4 2>&1
|
||||
}
|
||||
|
||||
build_package_ruby() {
|
||||
local package_name="$1"
|
||||
|
||||
{ "$RUBY_BIN" setup.rb
|
||||
} 2>&1 | log
|
||||
} >&4 2>&1
|
||||
}
|
||||
|
||||
build_package_rbx() {
|
||||
|
@ -95,7 +99,7 @@ build_package_rbx() {
|
|||
|
||||
{ ./configure --prefix="$PREFIX_PATH"
|
||||
rake install
|
||||
} 2>&1 | log
|
||||
} >&4 2>&1
|
||||
}
|
||||
|
||||
build_package_copy() {
|
||||
|
@ -181,12 +185,20 @@ TEMP_PATH="/tmp/ruby-build.${SEED}"
|
|||
RUBY_BIN="${PREFIX_PATH}/bin/ruby"
|
||||
CWD="$(pwd)"
|
||||
|
||||
exec 4<> "$LOG_PATH" # open the log file at fd 4
|
||||
if [ -n "$VERBOSE" ]; then
|
||||
tail -f "$LOG_PATH" &
|
||||
trap "kill 0" SIGINT SIGTERM EXIT
|
||||
fi
|
||||
|
||||
export LDFLAGS="-L'${PREFIX_PATH}/lib' ${LDFLAGS}"
|
||||
export CPPFLAGS="-I'${PREFIX_PATH}/include' ${CPPFLAGS}"
|
||||
|
||||
unset RUBYOPT
|
||||
unset RUBYLIB
|
||||
|
||||
trap build_failed ERR
|
||||
mkdir -p "$TEMP_PATH"
|
||||
source "$DEFINITION_PATH"
|
||||
rm -fr "$TEMP_PATH"
|
||||
trap - ERR
|
||||
|
|
Loading…
Reference in a new issue