2011-09-06 10:13:32 -05:00
|
|
|
#!/usr/bin/env bash
|
2011-08-02 08:46:34 -05:00
|
|
|
|
2014-09-19 09:04:50 -06:00
|
|
|
RUBY_BUILD_VERSION="20140919"
|
2011-09-06 14:56:07 -05:00
|
|
|
|
2011-08-07 15:41:20 -05:00
|
|
|
set -E
|
|
|
|
|
exec 3<&2 # preserve original stderr at fd 3
|
2011-08-02 08:46:34 -05:00
|
|
|
|
2012-08-15 13:28:01 -05:00
|
|
|
|
|
|
|
|
lib() {
|
|
|
|
|
parse_options() {
|
|
|
|
|
OPTIONS=()
|
|
|
|
|
ARGUMENTS=()
|
|
|
|
|
local arg option index
|
|
|
|
|
|
|
|
|
|
for arg in "$@"; do
|
|
|
|
|
if [ "${arg:0:1}" = "-" ]; then
|
|
|
|
|
if [ "${arg:1:1}" = "-" ]; then
|
|
|
|
|
OPTIONS[${#OPTIONS[*]}]="${arg:2}"
|
|
|
|
|
else
|
|
|
|
|
index=1
|
|
|
|
|
while option="${arg:$index:1}"; do
|
|
|
|
|
[ -n "$option" ] || break
|
|
|
|
|
OPTIONS[${#OPTIONS[*]}]="$option"
|
|
|
|
|
index=$(($index+1))
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
ARGUMENTS[${#ARGUMENTS[*]}]="$arg"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ "$1" == "--$FUNCNAME" ]; then
|
|
|
|
|
declare -f "$FUNCNAME"
|
2012-08-15 14:43:44 -05:00
|
|
|
echo "$FUNCNAME \"\$1\";"
|
2012-08-15 13:28:01 -05:00
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
lib "$1"
|
|
|
|
|
|
|
|
|
|
|
2011-08-16 23:22:52 +02:00
|
|
|
resolve_link() {
|
2011-12-30 13:58:12 -06:00
|
|
|
$(type -p greadlink readlink | head -1) "$1"
|
2011-08-16 23:22:52 +02:00
|
|
|
}
|
|
|
|
|
|
2011-08-07 12:36:08 -05:00
|
|
|
abs_dirname() {
|
|
|
|
|
local cwd="$(pwd)"
|
|
|
|
|
local path="$1"
|
|
|
|
|
|
|
|
|
|
while [ -n "$path" ]; do
|
|
|
|
|
cd "${path%/*}"
|
|
|
|
|
local name="${path##*/}"
|
2011-08-16 23:22:52 +02:00
|
|
|
path="$(resolve_link "$name" || true)"
|
2011-08-07 12:36:08 -05:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
pwd
|
|
|
|
|
cd "$cwd"
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-04 16:15:07 -06:00
|
|
|
capitalize() {
|
|
|
|
|
printf "%s" "$1" | tr a-z A-Z
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 20:15:55 -05:00
|
|
|
sanitize() {
|
|
|
|
|
printf "%s" "$1" | sed "s/[^A-Za-z0-9.-]/_/g; s/__*/_/g"
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 20:11:22 +01:00
|
|
|
colorize() {
|
|
|
|
|
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
|
|
|
|
|
else echo -n "$2"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-06 02:20:39 -07:00
|
|
|
os_information() {
|
|
|
|
|
if type -p lsb_release >/dev/null; then
|
|
|
|
|
lsb_release -sir | xargs echo
|
|
|
|
|
elif type -p sw_vers >/dev/null; then
|
|
|
|
|
echo "OS X $(sw_vers -productVersion)"
|
2014-09-08 22:58:05 -07:00
|
|
|
elif [ -r /etc/os-release ]; then
|
|
|
|
|
source /etc/os-release
|
|
|
|
|
echo "$NAME" $VERSION_ID
|
2014-09-06 02:20:39 -07:00
|
|
|
else
|
|
|
|
|
local os="$(cat /etc/{centos,redhat,fedora,system}-release /etc/debian_version 2>/dev/null | head -1)"
|
|
|
|
|
echo "${os:-$(uname -sr)}"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:41:20 -05:00
|
|
|
build_failed() {
|
|
|
|
|
{ echo
|
2014-09-06 01:23:17 -07:00
|
|
|
colorize 1 "BUILD FAILED"
|
2014-09-06 02:20:39 -07:00
|
|
|
echo " ($(os_information) using $(version))"
|
2011-08-07 15:41:20 -05:00
|
|
|
echo
|
2011-10-21 09:22:05 -05:00
|
|
|
|
2012-04-28 14:09:06 -07:00
|
|
|
if ! rmdir "${BUILD_PATH}" 2>/dev/null; then
|
|
|
|
|
echo "Inspect or clean up the working tree at ${BUILD_PATH}"
|
2011-10-30 10:39:07 -05:00
|
|
|
|
|
|
|
|
if file_is_not_empty "$LOG_PATH"; then
|
2014-09-06 02:17:11 -07:00
|
|
|
colorize 33 "Results logged to ${LOG_PATH}"
|
|
|
|
|
printf "\n\n"
|
2011-10-30 10:39:07 -05:00
|
|
|
echo "Last 10 log lines:"
|
|
|
|
|
tail -n 10 "$LOG_PATH"
|
|
|
|
|
fi
|
2011-10-21 09:22:05 -05:00
|
|
|
fi
|
2011-08-07 15:41:20 -05:00
|
|
|
} >&3
|
|
|
|
|
exit 1
|
2011-08-07 12:38:14 -05:00
|
|
|
}
|
|
|
|
|
|
2011-10-21 09:22:05 -05:00
|
|
|
file_is_not_empty() {
|
|
|
|
|
local filename="$1"
|
|
|
|
|
local line_count="$(wc -l "$filename" 2>/dev/null || true)"
|
|
|
|
|
|
|
|
|
|
if [ -n "$line_count" ]; then
|
|
|
|
|
words=( $line_count )
|
|
|
|
|
[ "${words[0]}" -gt 0 ]
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 22:24:12 +01:00
|
|
|
num_cpu_cores() {
|
2014-09-08 09:11:39 -07:00
|
|
|
local num
|
|
|
|
|
case "$(uname -s)" in
|
|
|
|
|
Darwin | *BSD )
|
2013-10-27 22:24:12 +01:00
|
|
|
num="$(sysctl -n hw.ncpu 2>/dev/null || true)"
|
2014-09-08 09:11:39 -07:00
|
|
|
;;
|
|
|
|
|
* )
|
|
|
|
|
num="$(grep ^processor /proc/cpuinfo 2>/dev/null | wc -l | xargs)"
|
|
|
|
|
num="${num#0}"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2013-10-27 22:24:12 +01:00
|
|
|
echo "${num:-2}"
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 08:46:34 -05:00
|
|
|
install_package() {
|
2013-02-08 16:47:52 -06:00
|
|
|
install_package_using "tarball" 1 "$@"
|
2011-09-12 22:12:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install_git() {
|
2013-02-08 16:47:52 -06:00
|
|
|
install_package_using "git" 2 "$@"
|
2011-09-12 22:12:44 -07:00
|
|
|
}
|
|
|
|
|
|
2012-10-06 09:17:08 +09:00
|
|
|
install_svn() {
|
2013-02-08 16:47:52 -06:00
|
|
|
install_package_using "svn" 2 "$@"
|
2012-10-06 09:17:08 +09:00
|
|
|
}
|
|
|
|
|
|
2011-09-12 22:12:44 -07:00
|
|
|
install_package_using() {
|
|
|
|
|
local package_type="$1"
|
|
|
|
|
local package_type_nargs="$2"
|
|
|
|
|
local package_name="$3"
|
|
|
|
|
shift 3
|
|
|
|
|
|
2013-02-08 16:47:52 -06:00
|
|
|
local fetch_args=( "$package_name" "${@:1:$package_type_nargs}" )
|
|
|
|
|
local make_args=( "$package_name" )
|
|
|
|
|
local arg last_arg
|
|
|
|
|
|
|
|
|
|
for arg in "${@:$(( $package_type_nargs + 1 ))}"; do
|
|
|
|
|
if [ "$last_arg" = "--if" ]; then
|
|
|
|
|
"$arg" || return 0
|
|
|
|
|
elif [ "$arg" != "--if" ]; then
|
|
|
|
|
make_args["${#make_args[@]}"]="$arg"
|
|
|
|
|
fi
|
|
|
|
|
last_arg="$arg"
|
|
|
|
|
done
|
|
|
|
|
|
2012-04-28 14:09:06 -07:00
|
|
|
pushd "$BUILD_PATH" >&4
|
2013-02-08 16:47:52 -06:00
|
|
|
"fetch_${package_type}" "${fetch_args[@]}"
|
|
|
|
|
make_package "${make_args[@]}"
|
2011-09-14 10:49:06 -05:00
|
|
|
popd >&4
|
2011-09-12 22:12:44 -07:00
|
|
|
|
2012-11-15 14:58:57 -06:00
|
|
|
{ echo "Installed ${package_name} to ${PREFIX_PATH}"
|
|
|
|
|
echo
|
|
|
|
|
} >&2
|
2011-09-12 22:12:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
make_package() {
|
2011-08-02 08:46:34 -05:00
|
|
|
local package_name="$1"
|
2011-09-12 22:12:44 -07:00
|
|
|
shift
|
2011-08-02 08:46:34 -05:00
|
|
|
|
2011-09-14 10:49:06 -05:00
|
|
|
pushd "$package_name" >&4
|
2011-12-01 17:09:27 -06:00
|
|
|
before_install_package "$package_name"
|
2011-08-02 08:46:34 -05:00
|
|
|
build_package "$package_name" $*
|
2011-08-02 20:55:10 -05:00
|
|
|
after_install_package "$package_name"
|
2011-09-06 13:25:56 -05:00
|
|
|
fix_directory_permissions
|
2011-09-14 10:49:06 -05:00
|
|
|
popd >&4
|
2011-08-02 08:46:34 -05:00
|
|
|
}
|
|
|
|
|
|
2014-04-15 16:45:57 +02:00
|
|
|
compute_sha2() {
|
|
|
|
|
local output
|
|
|
|
|
if type shasum &>/dev/null; then
|
|
|
|
|
output="$(shasum -a 256 -b)" || return 1
|
|
|
|
|
echo "${output% *}"
|
|
|
|
|
elif type openssl &>/dev/null; then
|
|
|
|
|
output="$(openssl dgst -sha256)" || return 1
|
|
|
|
|
echo "${output##* }"
|
|
|
|
|
elif type sha256sum &>/dev/null; then
|
|
|
|
|
output="$(sha256sum --quiet)" || return 1
|
|
|
|
|
echo "${output% *}"
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-14 19:53:57 -06:00
|
|
|
compute_md5() {
|
2014-04-15 16:45:57 +02:00
|
|
|
local output
|
2012-11-14 19:53:57 -06:00
|
|
|
if type md5 &>/dev/null; then
|
|
|
|
|
md5 -q
|
2012-11-15 15:24:44 -06:00
|
|
|
elif type openssl &>/dev/null; then
|
2014-04-15 16:45:57 +02:00
|
|
|
output="$(openssl md5)" || return 1
|
2012-11-16 00:48:17 -06:00
|
|
|
echo "${output##* }"
|
2012-11-14 19:53:57 -06:00
|
|
|
elif type md5sum &>/dev/null; then
|
2014-04-15 16:45:57 +02:00
|
|
|
output="$(md5sum -b)" || return 1
|
2012-11-14 19:53:57 -06:00
|
|
|
echo "${output% *}"
|
|
|
|
|
else
|
2012-11-15 16:03:39 -06:00
|
|
|
return 1
|
2012-11-14 19:53:57 -06:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
verify_checksum() {
|
2014-04-15 16:45:57 +02:00
|
|
|
# If there's no SHA2 support, return success
|
|
|
|
|
[ -n "$HAS_SHA2_SUPPORT" ] || return 0
|
2014-04-17 00:35:56 +02:00
|
|
|
local checksum_command="compute_sha2"
|
2012-11-15 16:03:39 -06:00
|
|
|
|
2012-11-19 23:45:00 -06:00
|
|
|
# If the specified filename doesn't exist, return success
|
2012-11-14 19:53:57 -06:00
|
|
|
local filename="$1"
|
2012-11-19 23:45:00 -06:00
|
|
|
[ -e "$filename" ] || return 0
|
2012-11-14 19:53:57 -06:00
|
|
|
|
2012-11-15 16:05:05 -06:00
|
|
|
# If there's no expected checksum, return success
|
2013-06-19 17:55:37 -04:00
|
|
|
local expected_checksum=`echo "$2" | tr [A-Z] [a-z]`
|
2012-11-15 16:05:05 -06:00
|
|
|
[ -n "$expected_checksum" ] || return 0
|
2012-11-14 19:53:57 -06:00
|
|
|
|
2014-04-17 00:35:56 +02:00
|
|
|
# If the checksum length is 32 chars, assume MD5, otherwise SHA2
|
|
|
|
|
if [ "${#expected_checksum}" -eq 32 ]; then
|
|
|
|
|
[ -n "$HAS_MD5_SUPPORT" ] || return 0
|
|
|
|
|
checksum_command="compute_md5"
|
|
|
|
|
fi
|
|
|
|
|
|
2012-11-15 16:05:05 -06:00
|
|
|
# If the computed checksum is empty, return failure
|
2014-04-17 00:35:56 +02:00
|
|
|
local computed_checksum=`echo "$($checksum_command < "$filename")" | tr [A-Z] [a-z]`
|
2012-11-15 16:05:05 -06:00
|
|
|
[ -n "$computed_checksum" ] || return 1
|
2012-11-14 19:53:57 -06:00
|
|
|
|
|
|
|
|
if [ "$expected_checksum" != "$computed_checksum" ]; then
|
|
|
|
|
{ echo
|
|
|
|
|
echo "checksum mismatch: ${filename} (file is corrupt)"
|
|
|
|
|
echo "expected $expected_checksum, got $computed_checksum"
|
|
|
|
|
echo
|
|
|
|
|
} >&4
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 14:58:57 -06:00
|
|
|
http() {
|
|
|
|
|
local method="$1"
|
|
|
|
|
local url="$2"
|
2013-03-12 16:40:13 +08:00
|
|
|
local file="$3"
|
2012-11-15 14:58:57 -06:00
|
|
|
[ -n "$url" ] || return 1
|
|
|
|
|
|
2012-11-15 15:03:22 -06:00
|
|
|
if type curl &>/dev/null; then
|
2013-03-12 16:40:13 +08:00
|
|
|
"http_${method}_curl" "$url" "$file"
|
2012-04-23 16:24:20 -05:00
|
|
|
elif type wget &>/dev/null; then
|
2013-03-12 16:40:13 +08:00
|
|
|
"http_${method}_wget" "$url" "$file"
|
2012-04-23 16:13:56 -05:00
|
|
|
else
|
|
|
|
|
echo "error: please install \`curl\` or \`wget\` and try again" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
2012-03-12 10:06:25 -07:00
|
|
|
|
2012-11-15 14:58:57 -06:00
|
|
|
http_head_curl() {
|
2013-02-10 23:52:11 +01:00
|
|
|
curl -qsILf "$1" >&4 2>&1
|
2012-11-15 14:58:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http_get_curl() {
|
2014-03-25 03:21:27 +01:00
|
|
|
curl -q -o "${2:--}" -sSLf "$1"
|
2012-11-15 14:58:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http_head_wget() {
|
|
|
|
|
wget -q --spider "$1" >&4 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http_get_wget() {
|
2014-03-25 03:21:27 +01:00
|
|
|
wget -nv -O "${2:--}" "$1"
|
2012-11-15 14:58:57 -06:00
|
|
|
}
|
|
|
|
|
|
2011-09-12 22:12:44 -07:00
|
|
|
fetch_tarball() {
|
2011-08-02 08:46:34 -05:00
|
|
|
local package_name="$1"
|
|
|
|
|
local package_url="$2"
|
2012-11-14 20:33:48 -06:00
|
|
|
local mirror_url
|
2012-11-16 10:30:49 -06:00
|
|
|
local checksum
|
2012-11-13 17:38:37 -06:00
|
|
|
|
2012-11-16 10:30:49 -06:00
|
|
|
if [ "$package_url" != "${package_url/\#}" ]; then
|
|
|
|
|
checksum="${package_url#*#}"
|
2012-11-14 19:53:57 -06:00
|
|
|
package_url="${package_url%%#*}"
|
2012-11-14 20:33:48 -06:00
|
|
|
|
|
|
|
|
if [ -n "$RUBY_BUILD_MIRROR_URL" ]; then
|
|
|
|
|
mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
|
|
|
|
|
fi
|
2012-11-14 19:53:57 -06:00
|
|
|
fi
|
|
|
|
|
|
2014-08-17 19:07:08 -07:00
|
|
|
local tar_args="xzf"
|
2012-11-14 19:53:57 -06:00
|
|
|
local package_filename="${package_name}.tar.gz"
|
2013-10-23 15:32:42 +02:00
|
|
|
|
|
|
|
|
if [ "$package_url" != "${package_url%bz2}" ]; then
|
|
|
|
|
package_filename="${package_filename%.gz}.bz2"
|
|
|
|
|
tar_args="${tar_args/z/j}"
|
|
|
|
|
fi
|
|
|
|
|
|
2014-03-25 04:15:50 +01:00
|
|
|
if ! reuse_existing_tarball "$package_filename" "$checksum"; then
|
2014-04-26 16:15:10 +01:00
|
|
|
local tarball_filename=$(basename $package_url)
|
|
|
|
|
echo "Downloading ${tarball_filename}..." >&2
|
2013-10-26 06:39:12 +02:00
|
|
|
http head "$mirror_url" &&
|
|
|
|
|
download_tarball "$mirror_url" "$package_filename" "$checksum" ||
|
2012-11-15 14:58:57 -06:00
|
|
|
download_tarball "$package_url" "$package_filename" "$checksum"
|
2013-10-26 06:39:12 +02:00
|
|
|
fi
|
2012-11-14 19:53:57 -06:00
|
|
|
|
2013-10-23 15:32:42 +02:00
|
|
|
{ if tar $tar_args "$package_filename"; then
|
2013-03-12 16:49:17 +08:00
|
|
|
if [ -z "$KEEP_BUILD_PATH" ]; then
|
|
|
|
|
rm -f "$package_filename"
|
|
|
|
|
else
|
|
|
|
|
true
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2012-11-14 19:53:57 -06:00
|
|
|
} >&4 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 04:15:50 +01:00
|
|
|
reuse_existing_tarball() {
|
2012-11-14 20:33:48 -06:00
|
|
|
local package_filename="$1"
|
|
|
|
|
local checksum="$2"
|
|
|
|
|
|
2014-03-25 04:15:50 +01:00
|
|
|
# Reuse existing file in build location
|
|
|
|
|
if [ -e "$package_filename" ] && verify_checksum "$package_filename" "$checksum"; then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Reuse previously downloaded file in cache location
|
|
|
|
|
[ -n "$RUBY_BUILD_CACHE_PATH" ] || return 1
|
|
|
|
|
local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"
|
|
|
|
|
|
2012-11-19 23:45:00 -06:00
|
|
|
[ -e "$cached_package_filename" ] || return 1
|
|
|
|
|
verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1
|
|
|
|
|
ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1
|
2012-11-14 19:53:57 -06:00
|
|
|
}
|
2011-08-02 08:46:34 -05:00
|
|
|
|
2012-11-14 19:53:57 -06:00
|
|
|
download_tarball() {
|
|
|
|
|
local package_url="$1"
|
2012-11-14 20:33:48 -06:00
|
|
|
[ -n "$package_url" ] || return 1
|
|
|
|
|
|
2012-11-14 19:53:57 -06:00
|
|
|
local package_filename="$2"
|
|
|
|
|
local checksum="$3"
|
|
|
|
|
|
2012-11-15 14:58:57 -06:00
|
|
|
echo "-> $package_url" >&2
|
|
|
|
|
|
2013-10-26 06:32:03 +02:00
|
|
|
if http get "$package_url" "$package_filename" >&4 2>&1; then
|
|
|
|
|
verify_checksum "$package_filename" "$checksum" >&4 2>&1 || return 1
|
|
|
|
|
else
|
|
|
|
|
echo "error: failed to download $package_filename" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
2012-11-14 19:53:57 -06:00
|
|
|
|
|
|
|
|
if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
|
|
|
|
|
local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"
|
|
|
|
|
{ mv "$package_filename" "$cached_package_filename"
|
|
|
|
|
ln -s "$cached_package_filename" "$package_filename"
|
2012-11-14 20:33:48 -06:00
|
|
|
} >&4 2>&1 || return 1
|
2012-11-13 17:39:48 -06:00
|
|
|
fi
|
2011-08-02 08:46:34 -05:00
|
|
|
}
|
|
|
|
|
|
2011-09-12 22:12:44 -07:00
|
|
|
fetch_git() {
|
2011-08-02 08:46:34 -05:00
|
|
|
local package_name="$1"
|
2011-09-12 22:12:44 -07:00
|
|
|
local git_url="$2"
|
|
|
|
|
local git_ref="$3"
|
2011-08-02 08:46:34 -05:00
|
|
|
|
2011-09-12 22:12:44 -07:00
|
|
|
echo "Cloning ${git_url}..." >&2
|
2012-04-23 16:19:41 -05:00
|
|
|
|
2012-04-23 16:24:20 -05:00
|
|
|
if type git &>/dev/null; then
|
2013-03-23 19:27:13 -04:00
|
|
|
if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
|
|
|
|
|
pushd "$RUBY_BUILD_CACHE_PATH" >&4
|
2013-04-18 20:15:55 -05:00
|
|
|
local clone_name="$(sanitize "$git_url")"
|
2013-03-23 19:27:13 -04:00
|
|
|
if [ -e "${clone_name}" ]; then
|
2014-04-17 00:35:38 +09:00
|
|
|
{ cd "${clone_name}"
|
2013-04-18 20:15:55 -05:00
|
|
|
git fetch --force "$git_url" "+${git_ref}:${git_ref}"
|
2014-04-17 00:35:38 +09:00
|
|
|
} >&4 2>&1
|
2013-03-23 19:27:13 -04:00
|
|
|
else
|
|
|
|
|
git clone --bare --branch "$git_ref" "$git_url" "${clone_name}" >&4 2>&1
|
|
|
|
|
fi
|
2013-03-25 07:58:57 -04:00
|
|
|
git_url="$RUBY_BUILD_CACHE_PATH/${clone_name}"
|
2013-03-23 19:27:13 -04:00
|
|
|
popd >&4
|
|
|
|
|
fi
|
|
|
|
|
|
2014-04-13 17:33:04 +09:00
|
|
|
if [ -e "${package_name}" ]; then
|
|
|
|
|
( cd "${package_name}"
|
2014-04-17 00:35:38 +09:00
|
|
|
git fetch --depth 1 origin "+${git_ref}"
|
|
|
|
|
git checkout -q -B "$git_ref" "origin/${git_ref}"
|
2014-04-13 17:33:04 +09:00
|
|
|
) >&4 2>&1
|
|
|
|
|
else
|
|
|
|
|
git clone --depth 1 --branch "$git_ref" "$git_url" "${package_name}" >&4 2>&1
|
|
|
|
|
fi
|
2012-04-23 16:19:41 -05:00
|
|
|
else
|
|
|
|
|
echo "error: please install \`git\` and try again" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2011-08-02 08:46:34 -05:00
|
|
|
}
|
|
|
|
|
|
2012-10-06 09:17:08 +09:00
|
|
|
fetch_svn() {
|
|
|
|
|
local package_name="$1"
|
|
|
|
|
local svn_url="$2"
|
|
|
|
|
local svn_rev="$3"
|
|
|
|
|
|
2012-10-07 08:07:35 +09:00
|
|
|
echo "Checking out ${svn_url}..." >&2
|
2012-10-06 09:17:08 +09:00
|
|
|
|
|
|
|
|
if type svn &>/dev/null; then
|
|
|
|
|
svn co -r "$svn_rev" "$svn_url" "${package_name}" >&4 2>&1
|
|
|
|
|
else
|
|
|
|
|
echo "error: please install \`svn\` and try again" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 08:46:34 -05:00
|
|
|
build_package() {
|
|
|
|
|
local package_name="$1"
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
|
|
if [ "$#" -eq 0 ]; then
|
|
|
|
|
local commands="standard"
|
|
|
|
|
else
|
|
|
|
|
local commands="$*"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Installing ${package_name}..." >&2
|
|
|
|
|
|
2013-12-11 21:16:47 +01:00
|
|
|
[ -n "$HAS_PATCH" ] && apply_ruby_patch "$package_name"
|
|
|
|
|
|
2011-08-02 08:46:34 -05:00
|
|
|
for command in $commands; do
|
2013-01-31 09:49:01 -06:00
|
|
|
"build_package_${command}" "$package_name"
|
2011-08-02 08:46:34 -05:00
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-04 16:15:07 -06:00
|
|
|
package_option() {
|
|
|
|
|
local package_name="$1"
|
|
|
|
|
local command_name="$2"
|
|
|
|
|
local variable="$(capitalize "${package_name}_${command_name}")_OPTS_ARRAY"
|
|
|
|
|
local array="$variable[@]"
|
|
|
|
|
shift 2
|
|
|
|
|
local value=( "${!array}" "$@" )
|
|
|
|
|
eval "$variable=( \"\${value[@]}\" )"
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 08:46:34 -05:00
|
|
|
build_package_standard() {
|
|
|
|
|
local package_name="$1"
|
2011-12-30 13:00:47 -06:00
|
|
|
|
2012-03-30 13:06:50 -07:00
|
|
|
if [ "${MAKEOPTS+defined}" ]; then
|
2011-12-30 13:00:47 -06:00
|
|
|
MAKE_OPTS="$MAKEOPTS"
|
|
|
|
|
elif [ -z "${MAKE_OPTS+defined}" ]; then
|
2013-10-27 22:24:12 +01:00
|
|
|
MAKE_OPTS="-j $(num_cpu_cores)"
|
2011-09-26 16:26:09 -06:00
|
|
|
fi
|
2011-12-30 13:00:47 -06:00
|
|
|
|
2013-01-31 09:49:01 -06:00
|
|
|
# Support YAML_CONFIGURE_OPTS, RUBY_CONFIGURE_OPTS, etc.
|
2013-02-04 16:15:07 -06:00
|
|
|
local package_var_name="$(capitalize "${package_name%%-*}")"
|
2013-01-23 22:03:53 -07:00
|
|
|
local PACKAGE_CONFIGURE="${package_var_name}_CONFIGURE"
|
|
|
|
|
local PACKAGE_PREFIX_PATH="${package_var_name}_PREFIX_PATH"
|
2013-01-31 09:49:01 -06:00
|
|
|
local PACKAGE_CONFIGURE_OPTS="${package_var_name}_CONFIGURE_OPTS"
|
2013-02-04 14:05:09 -06:00
|
|
|
local PACKAGE_CONFIGURE_OPTS_ARRAY="${package_var_name}_CONFIGURE_OPTS_ARRAY[@]"
|
2013-01-31 09:49:01 -06:00
|
|
|
local PACKAGE_MAKE_OPTS="${package_var_name}_MAKE_OPTS"
|
2013-02-04 14:05:09 -06:00
|
|
|
local PACKAGE_MAKE_OPTS_ARRAY="${package_var_name}_MAKE_OPTS_ARRAY[@]"
|
2014-01-21 16:03:46 -08:00
|
|
|
local PACKAGE_MAKE_INSTALL_OPTS="${package_var_name}_MAKE_INSTALL_OPTS"
|
|
|
|
|
local PACKAGE_MAKE_INSTALL_OPTS_ARRAY="${package_var_name}_MAKE_INSTALL_OPTS_ARRAY[@]"
|
2013-02-27 11:12:41 -06:00
|
|
|
local PACKAGE_CFLAGS="${package_var_name}_CFLAGS"
|
2013-01-31 09:49:01 -06:00
|
|
|
|
2013-12-11 23:49:18 +01:00
|
|
|
[ "$package_var_name" = "RUBY" ] && use_homebrew_readline || true
|
|
|
|
|
|
2013-05-06 18:03:54 -05:00
|
|
|
( if [ "${CFLAGS+defined}" ] || [ "${!PACKAGE_CFLAGS+defined}" ]; then
|
2013-05-06 19:44:35 -05:00
|
|
|
export CFLAGS="$CFLAGS ${!PACKAGE_CFLAGS}"
|
2013-05-06 18:03:54 -05:00
|
|
|
fi
|
2014-09-06 01:29:28 -07:00
|
|
|
${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" \
|
|
|
|
|
$CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
|
2013-05-06 18:03:54 -05:00
|
|
|
) >&4 2>&1
|
|
|
|
|
|
|
|
|
|
{ "$MAKE" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS} "${!PACKAGE_MAKE_OPTS_ARRAY}"
|
2014-01-22 11:55:01 -08:00
|
|
|
"$MAKE" install $MAKE_INSTALL_OPTS ${!PACKAGE_MAKE_INSTALL_OPTS} "${!PACKAGE_MAKE_INSTALL_OPTS_ARRAY}"
|
2011-08-07 15:41:20 -05:00
|
|
|
} >&4 2>&1
|
2011-08-02 08:46:34 -05:00
|
|
|
}
|
|
|
|
|
|
2011-09-12 22:12:44 -07:00
|
|
|
build_package_autoconf() {
|
|
|
|
|
{ autoconf
|
|
|
|
|
} >&4 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 08:46:34 -05:00
|
|
|
build_package_ruby() {
|
|
|
|
|
local package_name="$1"
|
|
|
|
|
|
|
|
|
|
{ "$RUBY_BIN" setup.rb
|
2011-08-07 15:41:20 -05:00
|
|
|
} >&4 2>&1
|
2011-08-02 08:46:34 -05:00
|
|
|
}
|
|
|
|
|
|
2011-09-22 11:49:16 -04:00
|
|
|
build_package_ree_installer() {
|
2013-10-28 00:25:02 +01:00
|
|
|
build_package_auto_tcltk
|
|
|
|
|
|
2011-09-22 11:49:16 -04:00
|
|
|
local options=""
|
|
|
|
|
if [[ "Darwin" = "$(uname)" ]]; then
|
|
|
|
|
options="--no-tcmalloc"
|
|
|
|
|
fi
|
2011-09-28 13:19:50 -05:00
|
|
|
|
2013-04-19 11:36:02 -05:00
|
|
|
local option
|
2013-10-29 01:39:28 +01:00
|
|
|
for option in $RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[@]}; do
|
2013-04-19 11:36:02 -05:00
|
|
|
options="$options -c $option"
|
|
|
|
|
done
|
|
|
|
|
|
2011-09-22 11:49:16 -04:00
|
|
|
# Work around install_useful_libraries crash with --dont-install-useful-gems
|
|
|
|
|
mkdir -p "$PREFIX_PATH/lib/ruby/gems/1.8/gems"
|
|
|
|
|
|
2011-10-21 10:53:09 -05:00
|
|
|
{ ./installer --auto "$PREFIX_PATH" --dont-install-useful-gems $options $CONFIGURE_OPTS
|
2011-09-22 11:49:16 -04:00
|
|
|
} >&4 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 10:12:06 -05:00
|
|
|
build_package_rbx() {
|
|
|
|
|
local package_name="$1"
|
|
|
|
|
|
2013-10-29 14:09:55 +01:00
|
|
|
{ bundle --path=vendor/bundle
|
2013-11-22 14:23:44 +01:00
|
|
|
RUBYOPT="-rubygems $RUBYOPT" ./configure --prefix="$PREFIX_PATH" $RUBY_CONFIGURE_OPTS
|
2011-08-05 10:12:06 -05:00
|
|
|
rake install
|
2013-10-20 02:18:29 +02:00
|
|
|
fix_rbx_gem_binstubs "$PREFIX_PATH"
|
2013-12-11 18:38:53 +01:00
|
|
|
fix_rbx_irb "$PREFIX_PATH"
|
2011-08-07 15:41:20 -05:00
|
|
|
} >&4 2>&1
|
2011-08-05 10:12:06 -05:00
|
|
|
}
|
|
|
|
|
|
2013-04-05 08:23:34 -06:00
|
|
|
build_package_mruby() {
|
|
|
|
|
local package_name="$1"
|
|
|
|
|
|
|
|
|
|
{ rake
|
|
|
|
|
mkdir -p "$PREFIX_PATH"
|
2013-07-16 19:57:49 -05:00
|
|
|
cp -fR build/host/* "$PREFIX_PATH"
|
2013-04-05 08:23:34 -06:00
|
|
|
cd "$PREFIX_PATH/bin"
|
|
|
|
|
ln -fs mruby ruby
|
|
|
|
|
ln -fs mirb irb
|
|
|
|
|
} >&4 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-28 17:19:25 -07:00
|
|
|
build_package_maglev() {
|
|
|
|
|
build_package_copy
|
|
|
|
|
|
|
|
|
|
{ cd "${PREFIX_PATH}"
|
|
|
|
|
./install.sh
|
2011-11-01 14:17:06 -07:00
|
|
|
cd "${PREFIX_PATH}/bin"
|
|
|
|
|
echo "Creating symlink for ruby*"
|
|
|
|
|
ln -fs maglev-ruby ruby
|
|
|
|
|
echo "Creating symlink for irb*"
|
|
|
|
|
ln -fs maglev-irb irb
|
2011-10-28 17:19:25 -07:00
|
|
|
} >&4 2>&1
|
|
|
|
|
echo
|
2011-11-01 14:17:06 -07:00
|
|
|
echo "Run 'maglev start' to start up the stone before using 'ruby' or 'irb'"
|
2011-10-28 17:19:25 -07:00
|
|
|
}
|
|
|
|
|
|
2013-04-07 11:14:44 +02:00
|
|
|
build_package_topaz() {
|
|
|
|
|
build_package_copy
|
|
|
|
|
{ cd "${PREFIX_PATH}/bin"
|
|
|
|
|
echo "Creating symlink for ruby*"
|
|
|
|
|
ln -fs topaz ruby
|
|
|
|
|
} >&4 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topaz_architecture() {
|
|
|
|
|
case "$(uname -s)" in
|
|
|
|
|
"Darwin") echo "osx64";;
|
|
|
|
|
"Linux") [[ "$(uname -m)" = "x86_64" ]] && echo "linux64" || echo "linux32";;
|
|
|
|
|
*)
|
|
|
|
|
echo "no nightly builds available" >&2
|
|
|
|
|
exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-25 14:30:52 -05:00
|
|
|
build_package_jruby() {
|
|
|
|
|
build_package_copy
|
|
|
|
|
cd "${PREFIX_PATH}/bin"
|
|
|
|
|
ln -fs jruby ruby
|
2014-02-09 15:25:42 +00:00
|
|
|
chmod +x ruby
|
2011-09-25 14:30:52 -05:00
|
|
|
install_jruby_launcher
|
|
|
|
|
remove_windows_files
|
2013-12-17 19:35:54 +01:00
|
|
|
fix_jruby_shebangs
|
2011-09-25 14:30:52 -05:00
|
|
|
}
|
|
|
|
|
|
2014-02-24 16:05:45 +00:00
|
|
|
graal_architecture() {
|
|
|
|
|
if [ "$(uname -m)" != "x86_64" ]; then
|
|
|
|
|
echo "no nightly builds available" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
case "$(uname -s)" in
|
|
|
|
|
"Darwin") echo "macosx-x86_64";;
|
|
|
|
|
"Linux") echo "linux-x86_64";;
|
|
|
|
|
*)
|
|
|
|
|
echo "no nightly builds available" >&2
|
|
|
|
|
exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-25 14:30:52 -05:00
|
|
|
install_jruby_launcher() {
|
2014-02-24 16:05:45 +00:00
|
|
|
# If this version of JRuby has been modified for Graal, don't overwrite the
|
|
|
|
|
# launcher scripts
|
|
|
|
|
if ! grep -q graalvm "${PREFIX_PATH}/bin/jruby"; then
|
|
|
|
|
cd "${PREFIX_PATH}/bin"
|
|
|
|
|
{ ./ruby gem install jruby-launcher
|
|
|
|
|
} >&4 2>&1
|
|
|
|
|
fi
|
2011-09-25 14:30:52 -05:00
|
|
|
}
|
|
|
|
|
|
2013-12-17 19:35:54 +01:00
|
|
|
fix_jruby_shebangs() {
|
|
|
|
|
for file in "${PREFIX_PATH}/bin"/*; do
|
|
|
|
|
if [ "$(head -c 20 "$file")" = "#!/usr/bin/env jruby" ]; then
|
2014-01-17 10:06:38 -05:00
|
|
|
sed -i.bak "1 s:.*:#\!${PREFIX_PATH}\/bin\/jruby:" "$file"
|
2013-12-20 14:26:41 -08:00
|
|
|
rm "$file".bak
|
2013-12-17 19:35:54 +01:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-25 14:30:52 -05:00
|
|
|
remove_windows_files() {
|
|
|
|
|
cd "$PREFIX_PATH"
|
|
|
|
|
rm -f bin/*.exe bin/*.dll bin/*.bat bin/jruby.sh
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 20:21:23 -05:00
|
|
|
build_package_copy() {
|
2011-10-21 01:08:21 -04:00
|
|
|
mkdir -p "$PREFIX_PATH"
|
2013-10-26 08:08:07 +02:00
|
|
|
cp -fR . "$PREFIX_PATH"
|
2011-08-02 20:21:23 -05:00
|
|
|
}
|
|
|
|
|
|
2011-12-01 17:09:27 -06:00
|
|
|
before_install_package() {
|
|
|
|
|
local stub=1
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 20:55:10 -05:00
|
|
|
after_install_package() {
|
|
|
|
|
local stub=1
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 13:25:56 -05:00
|
|
|
fix_directory_permissions() {
|
|
|
|
|
# Ensure installed directories are not world-writable to avoid Bundler warnings
|
2013-01-18 13:42:43 +09:00
|
|
|
find "$PREFIX_PATH" -type d \( -perm -020 -o -perm -002 \) -exec chmod go-w {} \;
|
2011-09-06 13:25:56 -05:00
|
|
|
}
|
|
|
|
|
|
2013-10-20 02:18:29 +02:00
|
|
|
fix_rbx_gem_binstubs() {
|
|
|
|
|
local prefix="$1"
|
|
|
|
|
local gemdir="${prefix}/gems/bin"
|
|
|
|
|
local bindir="${prefix}/bin"
|
Fix `irb`, `rake`, `rdoc`, `ri` for rbx-2.2.1
We symlink Rubinius' `PREFIX/gems/bin` into `PREFIX/bin` so that new
RubyGems binstubs get added to the main bin directory and therefore
become available to rbenv.
However, by throwing away `irb`, `rake`, `rdoc`, and `ri` binstubs
during this process (which are non-executable and have an invalid
shebang), we break the same commands in latest versions of Rubinius.
This change ensures that these binstubs get preserved, their shebang
corrected to `#!PREFIX/bin/rbx`, their executable bit flipped on, and
copied over to the main bin directory.
Fixes #468
2013-12-11 18:17:26 +01:00
|
|
|
local file binstub
|
2013-10-20 02:18:29 +02:00
|
|
|
# Symlink Rubinius' `gems/bin/` into `bin/`
|
|
|
|
|
if [ -d "$gemdir" ]; then
|
|
|
|
|
for file in "$gemdir"/*; do
|
Fix `irb`, `rake`, `rdoc`, `ri` for rbx-2.2.1
We symlink Rubinius' `PREFIX/gems/bin` into `PREFIX/bin` so that new
RubyGems binstubs get added to the main bin directory and therefore
become available to rbenv.
However, by throwing away `irb`, `rake`, `rdoc`, and `ri` binstubs
during this process (which are non-executable and have an invalid
shebang), we break the same commands in latest versions of Rubinius.
This change ensures that these binstubs get preserved, their shebang
corrected to `#!PREFIX/bin/rbx`, their executable bit flipped on, and
copied over to the main bin directory.
Fixes #468
2013-12-11 18:17:26 +01:00
|
|
|
binstub="${bindir}/${file##*/}"
|
|
|
|
|
rm -f "$binstub"
|
2014-04-05 21:29:38 +02:00
|
|
|
{ echo "#!${bindir}/ruby"
|
|
|
|
|
cat "$file"
|
|
|
|
|
} > "$binstub"
|
Fix `irb`, `rake`, `rdoc`, `ri` for rbx-2.2.1
We symlink Rubinius' `PREFIX/gems/bin` into `PREFIX/bin` so that new
RubyGems binstubs get added to the main bin directory and therefore
become available to rbenv.
However, by throwing away `irb`, `rake`, `rdoc`, and `ri` binstubs
during this process (which are non-executable and have an invalid
shebang), we break the same commands in latest versions of Rubinius.
This change ensures that these binstubs get preserved, their shebang
corrected to `#!PREFIX/bin/rbx`, their executable bit flipped on, and
copied over to the main bin directory.
Fixes #468
2013-12-11 18:17:26 +01:00
|
|
|
chmod +x "$binstub"
|
2013-10-20 02:18:29 +02:00
|
|
|
done
|
|
|
|
|
rm -rf "$gemdir"
|
|
|
|
|
ln -s ../bin "$gemdir"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 18:38:53 +01:00
|
|
|
fix_rbx_irb() {
|
|
|
|
|
local prefix="$1"
|
|
|
|
|
"${prefix}/bin/irb" --version &>/dev/null ||
|
|
|
|
|
"${prefix}/bin/gem" install rubysl-tracer -v '~> 2.0' --no-rdoc --no-ri &>/dev/null ||
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 15:22:21 +00:00
|
|
|
require_java7() {
|
2014-02-17 19:44:49 -07:00
|
|
|
local version="$(java -version 2>&1 | head -1)"
|
2014-02-10 20:11:22 +01:00
|
|
|
if [[ $version != *1.[789]* ]]; then
|
|
|
|
|
colorize 1 "ERROR" >&3
|
|
|
|
|
echo ": Java 7 required. Please install a 1.7-compatible JRE." >&3
|
2014-02-10 15:22:21 +00:00
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-20 17:46:33 -05:00
|
|
|
require_gcc() {
|
2011-10-20 17:33:31 -05:00
|
|
|
local gcc="$(locate_gcc || true)"
|
2012-04-23 15:45:08 -05:00
|
|
|
|
2011-10-20 17:33:31 -05:00
|
|
|
if [ -z "$gcc" ]; then
|
|
|
|
|
{ echo
|
2014-02-10 20:12:21 +01:00
|
|
|
colorize 1 "ERROR"
|
|
|
|
|
echo ": This package must be compiled with GCC, but ruby-build couldn't"
|
2012-04-23 15:18:57 -05:00
|
|
|
echo "find a suitable \`gcc\` executable on your system. Please install GCC"
|
|
|
|
|
echo "and try again."
|
2011-10-20 17:33:31 -05:00
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
if [ "$(uname -s)" = "Darwin" ]; then
|
2014-02-10 20:12:21 +01:00
|
|
|
colorize 1 "DETAILS"
|
|
|
|
|
echo ": Apple no longer includes the official GCC compiler with Xcode"
|
2012-04-23 15:45:08 -05:00
|
|
|
echo "as of version 4.2. Instead, the \`gcc\` executable is a symlink to"
|
|
|
|
|
echo "\`llvm-gcc\`, a modified version of GCC which outputs LLVM bytecode."
|
2011-10-30 10:31:40 -05:00
|
|
|
echo
|
2012-04-23 15:18:57 -05:00
|
|
|
echo "For most programs the \`llvm-gcc\` compiler works fine. However,"
|
|
|
|
|
echo "versions of Ruby older than 1.9.3-p125 are incompatible with"
|
|
|
|
|
echo "\`llvm-gcc\`. To build older versions of Ruby you must have the official"
|
|
|
|
|
echo "GCC compiler installed on your system."
|
2011-10-20 17:33:31 -05:00
|
|
|
echo
|
2013-04-05 12:19:39 -05:00
|
|
|
|
2014-02-10 20:12:21 +01:00
|
|
|
colorize 1 "TO FIX THE PROBLEM"
|
2013-04-05 12:19:39 -05:00
|
|
|
if type brew &>/dev/null; then
|
2014-02-10 20:12:21 +01:00
|
|
|
echo ": Install Homebrew's apple-gcc42 package with this"
|
|
|
|
|
echo -n "command: "
|
|
|
|
|
colorize 4 "brew tap homebrew/dupes ; brew install apple-gcc42"
|
2013-04-05 12:19:39 -05:00
|
|
|
else
|
2014-02-10 20:12:21 +01:00
|
|
|
echo ": Install the official GCC compiler using these"
|
|
|
|
|
echo -n "packages: "
|
|
|
|
|
colorize 4 "https://github.com/kennethreitz/osx-gcc-installer/downloads"
|
2013-04-05 12:19:39 -05:00
|
|
|
fi
|
|
|
|
|
|
2014-02-10 20:12:21 +01:00
|
|
|
echo
|
2012-04-23 15:18:57 -05:00
|
|
|
echo
|
|
|
|
|
echo "You will need to install the official GCC compiler to build older"
|
|
|
|
|
echo "versions of Ruby even if you have installed Apple's Command Line Tools"
|
|
|
|
|
echo "for Xcode package. The Command Line Tools for Xcode package only"
|
|
|
|
|
echo "includes \`llvm-gcc\`."
|
2011-10-20 17:33:31 -05:00
|
|
|
fi
|
|
|
|
|
} >&3
|
|
|
|
|
return 1
|
2011-08-03 23:47:23 -05:00
|
|
|
fi
|
2011-10-20 17:33:31 -05:00
|
|
|
|
|
|
|
|
export CC="$gcc"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locate_gcc() {
|
|
|
|
|
local gcc gccs
|
2011-12-30 13:35:18 -06:00
|
|
|
IFS=: gccs=($(gccs_in_path))
|
2011-10-20 17:33:31 -05:00
|
|
|
|
|
|
|
|
verify_gcc "$CC" ||
|
|
|
|
|
verify_gcc "$(command -v gcc || true)" || {
|
|
|
|
|
for gcc in "${gccs[@]}"; do
|
|
|
|
|
verify_gcc "$gcc" && break || true
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-30 13:35:18 -06:00
|
|
|
gccs_in_path() {
|
|
|
|
|
local gcc path paths
|
|
|
|
|
local gccs=()
|
|
|
|
|
IFS=: paths=($PATH)
|
|
|
|
|
|
|
|
|
|
shopt -s nullglob
|
|
|
|
|
for path in "${paths[@]}"; do
|
|
|
|
|
for gcc in "$path"/gcc-*; do
|
|
|
|
|
gccs["${#gccs[@]}"]="$gcc"
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
shopt -u nullglob
|
|
|
|
|
|
|
|
|
|
printf :%s "${gccs[@]}"
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-20 17:33:31 -05:00
|
|
|
verify_gcc() {
|
|
|
|
|
local gcc="$1"
|
|
|
|
|
if [ -z "$gcc" ]; then
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local version="$("$gcc" --version || true)"
|
|
|
|
|
if [ -z "$version" ]; then
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if echo "$version" | grep LLVM >/dev/null; then
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "$gcc"
|
2011-08-03 23:47:23 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-09 20:40:45 -04:00
|
|
|
needs_yaml() {
|
|
|
|
|
[[ "$RUBY_CONFIGURE_OPTS" != *--with-libyaml-dir=* ]] &&
|
|
|
|
|
! use_homebrew_yaml
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use_homebrew_yaml() {
|
|
|
|
|
local libdir="$(brew --prefix libyaml 2>/dev/null || true)"
|
|
|
|
|
if [ -d "$libdir" ]; then
|
|
|
|
|
package_option ruby configure --with-libyaml-dir="$libdir"
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 23:49:18 +01:00
|
|
|
use_homebrew_readline() {
|
|
|
|
|
if [[ "$RUBY_CONFIGURE_OPTS" != *--with-readline-dir=* ]]; then
|
|
|
|
|
local libdir="$(brew --prefix readline 2>/dev/null || true)"
|
|
|
|
|
if [ -d "$libdir" ]; then
|
|
|
|
|
package_option ruby configure --with-readline-dir="$libdir"
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-04 17:50:12 -06:00
|
|
|
has_broken_mac_openssl() {
|
|
|
|
|
[ "$(uname -s)" = "Darwin" ] &&
|
2013-05-29 09:12:04 -05:00
|
|
|
[[ "$(openssl version 2>/dev/null || true)" = "OpenSSL 0.9.8"?* ]] &&
|
2013-06-28 01:36:20 +02:00
|
|
|
[[ "$RUBY_CONFIGURE_OPTS" != *--with-openssl-dir=* ]] &&
|
|
|
|
|
! use_homebrew_openssl
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use_homebrew_openssl() {
|
|
|
|
|
local ssldir="$(brew --prefix openssl 2>/dev/null || true)"
|
|
|
|
|
if [ -d "$ssldir" ]; then
|
|
|
|
|
package_option ruby configure --with-openssl-dir="$ssldir"
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
2013-02-04 17:50:12 -06:00
|
|
|
}
|
2013-01-23 22:03:53 -07:00
|
|
|
|
2013-02-04 17:50:12 -06:00
|
|
|
build_package_mac_openssl() {
|
|
|
|
|
# Install to a subdirectory since we don't want shims for bin/openssl.
|
|
|
|
|
OPENSSL_PREFIX_PATH="${PREFIX_PATH}/openssl"
|
2013-01-23 22:03:53 -07:00
|
|
|
|
2013-02-04 17:50:12 -06:00
|
|
|
# Put openssl.conf, certs, etc in ~/.rbenv/versions/*/openssl/ssl
|
|
|
|
|
OPENSSLDIR="${OPENSSLDIR:-$OPENSSL_PREFIX_PATH/ssl}"
|
2013-01-23 22:03:53 -07:00
|
|
|
|
2013-02-04 17:50:12 -06:00
|
|
|
# Tell Ruby to use this openssl for its extension.
|
|
|
|
|
package_option ruby configure --with-openssl-dir="$OPENSSL_PREFIX_PATH"
|
|
|
|
|
|
2013-02-08 14:54:54 -07:00
|
|
|
# Hint OpenSSL that we prefer a 64-bit build.
|
|
|
|
|
export KERNEL_BITS="64"
|
|
|
|
|
OPENSSL_CONFIGURE="${OPENSSL_CONFIGURE:-./config}"
|
2013-02-04 17:50:12 -06:00
|
|
|
|
2013-02-25 12:44:56 -06:00
|
|
|
# Compile a shared lib with zlib dynamically linked, no kerberos.
|
|
|
|
|
package_option openssl configure --openssldir="$OPENSSLDIR" zlib-dynamic no-krb5 shared
|
2013-02-04 17:50:12 -06:00
|
|
|
|
|
|
|
|
# Default MAKE_OPTS are -j 2 which can confuse the build. Thankfully, make
|
|
|
|
|
# gives precedence to the last -j option, so we can override that.
|
|
|
|
|
package_option openssl make -j 1
|
|
|
|
|
|
|
|
|
|
build_package_standard "$@"
|
2013-01-23 22:03:53 -07:00
|
|
|
|
2013-02-08 17:20:25 -06:00
|
|
|
# Extract root certs from the system keychain in .pem format and rehash.
|
2013-02-24 20:06:08 -07:00
|
|
|
local pem_file="$OPENSSLDIR/cert.pem"
|
2013-02-08 17:20:25 -06:00
|
|
|
security find-certificate -a -p /Library/Keychains/System.keychain > "$pem_file"
|
|
|
|
|
security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain >> "$pem_file"
|
2013-01-23 22:03:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Post-install check that the openssl extension was built.
|
|
|
|
|
build_package_verify_openssl() {
|
2013-02-08 15:32:27 -06:00
|
|
|
"$RUBY_BIN" -e 'begin
|
2013-01-23 22:03:53 -07:00
|
|
|
require "openssl"
|
|
|
|
|
rescue LoadError
|
2014-08-17 18:59:16 -07:00
|
|
|
$stderr.puts "The Ruby openssl extension was not compiled. Missing the OpenSSL lib?"
|
|
|
|
|
$stderr.puts "Configure options used:"
|
|
|
|
|
require "rbconfig"; require "shellwords"
|
|
|
|
|
RbConfig::CONFIG.fetch("configure_args").shellsplit.each { |arg| $stderr.puts " #{arg}" }
|
|
|
|
|
exit 1
|
2013-01-23 22:03:53 -07:00
|
|
|
end' >&4 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 21:32:18 +01:00
|
|
|
# Ensure that directories listed in LDFLAGS exist
|
|
|
|
|
build_package_ldflags_dirs() {
|
|
|
|
|
local arg
|
|
|
|
|
for arg in $LDFLAGS; do
|
|
|
|
|
case "$arg" in
|
|
|
|
|
-L* ) mkdir -p "${arg#-L}" ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 00:25:02 +01:00
|
|
|
build_package_auto_tcltk() {
|
|
|
|
|
if [ "Darwin" = "$(uname -s)" ] && [ ! -d /usr/include/X11 ]; then
|
|
|
|
|
if [ -d /opt/X11/include ]; then
|
|
|
|
|
if [[ "$CPPFLAGS" != *-I/opt/X11/include* ]]; then
|
|
|
|
|
export CPPFLAGS="-I/opt/X11/include $CPPFLAGS"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
package_option ruby configure --without-tk
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-26 15:48:25 +02:00
|
|
|
rake() {
|
|
|
|
|
if [ -e "./Gemfile" ]; then
|
|
|
|
|
bundle exec rake "$@"
|
|
|
|
|
else
|
2013-10-26 17:39:55 +02:00
|
|
|
isolated_gem_dependency "rake --version" rake -v '~> 10.1.0'
|
2013-10-26 15:48:25 +02:00
|
|
|
command rake "$@"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-26 17:39:55 +02:00
|
|
|
bundle() {
|
|
|
|
|
isolated_gem_dependency "bundle --version" bundler -v '~> 1.3.5'
|
|
|
|
|
command bundle "$@"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isolated_gem_dependency() {
|
2013-10-29 14:03:26 +01:00
|
|
|
set +E
|
|
|
|
|
( command $1 &>/dev/null ) || {
|
|
|
|
|
set -E
|
2013-10-26 17:39:55 +02:00
|
|
|
shift 1
|
|
|
|
|
isolated_gem_install "$@"
|
2013-10-29 14:03:26 +01:00
|
|
|
}
|
|
|
|
|
set -E
|
2013-10-26 17:39:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isolated_gem_install() {
|
|
|
|
|
export GEM_HOME="${PWD}/.gem"
|
|
|
|
|
export PATH="${GEM_HOME}/bin:${PATH}"
|
|
|
|
|
gem install "$@"
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 21:16:47 +01:00
|
|
|
apply_ruby_patch() {
|
2014-04-21 16:01:06 +02:00
|
|
|
local patchfile
|
2013-12-11 21:16:47 +01:00
|
|
|
case "$1" in
|
|
|
|
|
ruby-* | jruby-* | rubinius-* )
|
2014-04-21 17:24:11 +02:00
|
|
|
patchfile="$(mktemp "${TMP}/ruby-patch.XXXXXX")"
|
2014-04-21 16:01:06 +02:00
|
|
|
cat "${2:--}" >"$patchfile"
|
|
|
|
|
|
|
|
|
|
local striplevel=0
|
|
|
|
|
grep -q '^diff --git a/' "$patchfile" && striplevel=1
|
|
|
|
|
patch -p$striplevel --force -i "$patchfile"
|
2013-12-11 21:16:47 +01:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 14:56:07 -05:00
|
|
|
version() {
|
2014-08-14 17:35:39 -07:00
|
|
|
local git_revision
|
|
|
|
|
# Read the revision from git if the remote points to "ruby-build" repository
|
|
|
|
|
if GIT_DIR="$RUBY_BUILD_INSTALL_PREFIX/.git" git remote -v 2>/dev/null | grep -q /ruby-build; then
|
|
|
|
|
git_revision="$(GIT_DIR="$RUBY_BUILD_INSTALL_PREFIX/.git" git describe --tags HEAD 2>/dev/null || true)"
|
|
|
|
|
git_revision="${git_revision#v}"
|
|
|
|
|
fi
|
|
|
|
|
echo "ruby-build ${git_revision:-$RUBY_BUILD_VERSION}"
|
2011-09-06 14:56:07 -05:00
|
|
|
}
|
|
|
|
|
|
2011-08-02 08:46:34 -05:00
|
|
|
usage() {
|
2011-09-06 14:56:07 -05:00
|
|
|
{ version
|
2013-12-11 21:16:47 +01:00
|
|
|
echo "usage: ruby-build [-k|--keep] [-v|--verbose] [-p|--patch] definition prefix"
|
2011-08-07 12:38:14 -05:00
|
|
|
echo " ruby-build --definitions"
|
|
|
|
|
} >&2
|
2011-08-07 12:44:52 -05:00
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2011-08-02 08:46:34 -05:00
|
|
|
}
|
|
|
|
|
|
2011-08-07 12:38:47 -05:00
|
|
|
list_definitions() {
|
2014-08-16 20:01:00 -07:00
|
|
|
{ for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
|
|
|
|
|
[ -d "$DEFINITION_DIR" ] && ls "$DEFINITION_DIR"
|
2011-08-07 12:38:47 -05:00
|
|
|
done
|
2014-09-08 13:06:48 -07:00
|
|
|
} | sort_versions
|
2011-08-07 12:38:47 -05:00
|
|
|
}
|
|
|
|
|
|
2014-09-08 13:06:48 -07:00
|
|
|
sort_versions() {
|
|
|
|
|
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \
|
|
|
|
|
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
|
|
|
|
|
}
|
2011-08-07 12:38:47 -05:00
|
|
|
|
2011-08-02 08:46:34 -05:00
|
|
|
|
2011-08-07 12:38:14 -05:00
|
|
|
unset VERBOSE
|
2012-08-15 13:28:01 -05:00
|
|
|
unset KEEP_BUILD_PATH
|
2013-12-11 21:16:47 +01:00
|
|
|
unset HAS_PATCH
|
2014-08-16 19:58:43 -07:00
|
|
|
|
2014-08-14 17:35:39 -07:00
|
|
|
RUBY_BUILD_INSTALL_PREFIX="$(abs_dirname "$0")/.."
|
2011-08-07 12:36:08 -05:00
|
|
|
|
2014-08-16 20:01:00 -07:00
|
|
|
OLDIFS="$IFS"
|
2014-08-14 17:35:39 -07:00
|
|
|
IFS=: RUBY_BUILD_DEFINITIONS=($RUBY_BUILD_DEFINITIONS ${RUBY_BUILD_ROOT:-$RUBY_BUILD_INSTALL_PREFIX}/share/ruby-build)
|
2014-08-16 20:01:00 -07:00
|
|
|
IFS="$OLDIFS"
|
|
|
|
|
|
2012-08-15 13:28:01 -05:00
|
|
|
parse_options "$@"
|
2011-08-07 12:38:14 -05:00
|
|
|
|
2012-08-15 13:28:01 -05:00
|
|
|
for option in "${OPTIONS[@]}"; do
|
|
|
|
|
case "$option" in
|
|
|
|
|
"h" | "help" )
|
|
|
|
|
usage without_exiting
|
|
|
|
|
{ echo
|
|
|
|
|
echo " -k/--keep Do not remove source tree after installation"
|
|
|
|
|
echo " -v/--verbose Verbose mode: print compilation status to stdout"
|
2013-12-11 21:16:47 +01:00
|
|
|
echo " -p/--patch Apply a patch from stdin before building"
|
2012-08-15 13:28:01 -05:00
|
|
|
echo " --definitions List all built-in definitions"
|
|
|
|
|
echo
|
|
|
|
|
} >&2
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
"definitions" )
|
|
|
|
|
list_definitions
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
"k" | "keep" )
|
|
|
|
|
KEEP_BUILD_PATH=true
|
|
|
|
|
;;
|
|
|
|
|
"v" | "verbose" )
|
|
|
|
|
VERBOSE=true
|
|
|
|
|
;;
|
2013-12-11 21:16:47 +01:00
|
|
|
"p" | "patch" )
|
|
|
|
|
HAS_PATCH=true
|
|
|
|
|
;;
|
2012-08-15 13:28:01 -05:00
|
|
|
"version" )
|
|
|
|
|
version
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2011-08-07 12:38:14 -05:00
|
|
|
|
2012-08-15 13:28:01 -05:00
|
|
|
DEFINITION_PATH="${ARGUMENTS[0]}"
|
2011-08-02 08:46:34 -05:00
|
|
|
if [ -z "$DEFINITION_PATH" ]; then
|
|
|
|
|
usage
|
2014-02-26 04:23:56 -05:00
|
|
|
elif [ ! -f "$DEFINITION_PATH" ]; then
|
2014-08-16 20:01:00 -07:00
|
|
|
for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
|
|
|
|
|
if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then
|
|
|
|
|
DEFINITION_PATH="${DEFINITION_DIR}/${DEFINITION_PATH}"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ ! -f "$DEFINITION_PATH" ]; then
|
2011-08-07 12:36:08 -05:00
|
|
|
echo "ruby-build: definition not found: ${DEFINITION_PATH}" >&2
|
2013-03-21 12:40:53 -05:00
|
|
|
exit 2
|
2011-08-07 12:36:08 -05:00
|
|
|
fi
|
2011-08-02 08:46:34 -05:00
|
|
|
fi
|
|
|
|
|
|
2012-08-15 13:28:01 -05:00
|
|
|
PREFIX_PATH="${ARGUMENTS[1]}"
|
2011-09-06 16:49:38 -05:00
|
|
|
if [ -z "$PREFIX_PATH" ]; then
|
2011-08-02 08:46:34 -05:00
|
|
|
usage
|
2013-10-26 05:24:25 +02:00
|
|
|
elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
|
|
|
|
|
PREFIX_PATH="${PWD}/${PREFIX_PATH}"
|
2011-08-02 08:46:34 -05:00
|
|
|
fi
|
|
|
|
|
|
2011-09-06 13:42:44 -05:00
|
|
|
if [ -z "$TMPDIR" ]; then
|
|
|
|
|
TMP="/tmp"
|
|
|
|
|
else
|
|
|
|
|
TMP="${TMPDIR%/}"
|
|
|
|
|
fi
|
|
|
|
|
|
2014-09-08 10:43:57 -07:00
|
|
|
# Check if TMPDIR is accessible and can hold executables.
|
|
|
|
|
tmp_executable="${TMP}/ruby-build-test.$$"
|
|
|
|
|
noexec=""
|
|
|
|
|
if mkdir -p "$TMP" && touch "$tmp_executable" 2>/dev/null; then
|
|
|
|
|
cat > "$tmp_executable" <<<"#!$BASH"
|
|
|
|
|
chmod +x "$tmp_executable"
|
|
|
|
|
else
|
2013-10-28 00:44:15 +01:00
|
|
|
echo "ruby-build: TMPDIR=$TMP is set to a non-accessible location" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2014-09-08 10:43:57 -07:00
|
|
|
"$tmp_executable" 2>/dev/null || noexec=1
|
|
|
|
|
rm -f "$tmp_executable"
|
|
|
|
|
if [ -n "$noexec" ]; then
|
|
|
|
|
echo "ruby-build: TMPDIR=$TMP cannot hold executables (partition possibly mounted with \`noexec\`)" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2013-10-28 00:44:15 +01:00
|
|
|
|
2013-04-01 18:57:22 -07:00
|
|
|
# Work around warnings building Ruby 2.0 on Clang 2.x:
|
|
|
|
|
# pass -Wno-error=shorten-64-to-32 if the compiler accepts it.
|
2013-04-26 15:06:43 -07:00
|
|
|
#
|
|
|
|
|
# When we set CFLAGS, Ruby won't apply its default flags, though. Since clang
|
|
|
|
|
# builds 1.9.x and 2.x only, where -O3 is default, we can safely set that flag.
|
|
|
|
|
# Ensure it's the first flag since later flags take precedence.
|
2013-04-01 18:57:22 -07:00
|
|
|
if "${CC:-cc}" -x c /dev/null -E -Wno-error=shorten-64-to-32 &>/dev/null; then
|
2013-04-26 15:06:43 -07:00
|
|
|
RUBY_CFLAGS="-O3 -Wno-error=shorten-64-to-32 $RUBY_CFLAGS"
|
2013-02-27 12:45:26 -06:00
|
|
|
fi
|
2013-02-04 16:15:30 -06:00
|
|
|
|
2013-01-29 18:09:13 -06:00
|
|
|
if [ -z "$MAKE" ]; then
|
2014-09-08 10:05:17 -07:00
|
|
|
if [ "FreeBSD" = "$(uname -s)" ] && [ "$(uname -r | sed 's/[^[:digit:]].*//')" -lt 10 ]; then
|
2013-02-21 22:11:17 +01:00
|
|
|
export MAKE="gmake"
|
|
|
|
|
else
|
|
|
|
|
export MAKE="make"
|
|
|
|
|
fi
|
2013-01-29 18:09:13 -06:00
|
|
|
fi
|
|
|
|
|
|
2012-11-13 17:36:39 -06:00
|
|
|
if [ -n "$RUBY_BUILD_CACHE_PATH" ] && [ -d "$RUBY_BUILD_CACHE_PATH" ]; then
|
2012-11-13 17:38:37 -06:00
|
|
|
RUBY_BUILD_CACHE_PATH="${RUBY_BUILD_CACHE_PATH%/}"
|
2012-11-13 17:36:39 -06:00
|
|
|
else
|
|
|
|
|
unset RUBY_BUILD_CACHE_PATH
|
Simple, optional tarball cache support
Rationale:
Both in development and in production, some usage patterns of ruby-build
are slowed down by the download phase. In scenarios such as
troubleshooting failing builds or with provisioning situations (chef,
vagrant...) the repeated download is unnerving, bandwidth wasting and
simply against etiquette towards tarball hosters.
It also happens that some source sites happen to be down and in such
cases it is helpful to be able to sideload sources to rbenv.
Behavior:
By default nothing changes.
If the variable CACHE_PATH is set, then ruby-build will use that
directory to store a successful download, and will check before
downloading if the tarball is already there, in which case downloading
is skipped.
The file is first downloaded as before in the tmp subdirectory and only
moved afterwards, thus ensuring consistency.
There is no default cache path and the optional variable is to be set by
hand, ensuring people know what they're doing when using ruby-build.
Additionnally, rbenv-install will helpfully set CACHE_PATH if and only
if a RBENV_ROOT/cache directory exists. Again, the directory has to be
created manually.
The CACHE_PATH variable internally ends with a slash to mutualize
non-cached cases. Still, consistency is ensured whether or not a slash
is provided externally.
Notes:
I'm not quite sure CACHE_PATH is a good name, maybe
RUBY_BUILD_CACHE_PATH is better and less conflicting.
2012-11-07 16:43:15 +01:00
|
|
|
fi
|
|
|
|
|
|
2012-11-14 20:33:48 -06:00
|
|
|
if [ -z "$RUBY_BUILD_MIRROR_URL" ]; then
|
2012-12-12 13:48:10 -06:00
|
|
|
RUBY_BUILD_MIRROR_URL="http://dqw8nmjcqpjn7.cloudfront.net"
|
2012-11-14 20:33:48 -06:00
|
|
|
else
|
|
|
|
|
RUBY_BUILD_MIRROR_URL="${RUBY_BUILD_MIRROR_URL%/}"
|
|
|
|
|
fi
|
|
|
|
|
|
2012-11-15 15:29:50 -06:00
|
|
|
if [ -n "$RUBY_BUILD_SKIP_MIRROR" ]; then
|
|
|
|
|
unset RUBY_BUILD_MIRROR_URL
|
|
|
|
|
fi
|
|
|
|
|
|
2014-04-15 16:45:57 +02:00
|
|
|
if echo test | compute_sha2 >/dev/null; then
|
|
|
|
|
HAS_SHA2_SUPPORT=1
|
2012-11-15 16:03:39 -06:00
|
|
|
else
|
2014-04-15 16:45:57 +02:00
|
|
|
unset HAS_SHA2_SUPPORT
|
2012-11-15 16:03:39 -06:00
|
|
|
unset RUBY_BUILD_MIRROR_URL
|
|
|
|
|
fi
|
|
|
|
|
|
2014-04-17 00:35:56 +02:00
|
|
|
if echo test | compute_md5 >/dev/null; then
|
|
|
|
|
HAS_MD5_SUPPORT=1
|
|
|
|
|
else
|
|
|
|
|
unset HAS_MD5_SUPPORT
|
|
|
|
|
fi
|
|
|
|
|
|
2011-08-07 12:33:09 -05:00
|
|
|
SEED="$(date "+%Y%m%d%H%M%S").$$"
|
2011-09-06 13:42:44 -05:00
|
|
|
LOG_PATH="${TMP}/ruby-build.${SEED}.log"
|
2011-08-02 08:46:34 -05:00
|
|
|
RUBY_BIN="${PREFIX_PATH}/bin/ruby"
|
|
|
|
|
CWD="$(pwd)"
|
|
|
|
|
|
2012-11-13 17:44:07 -06:00
|
|
|
if [ -z "$RUBY_BUILD_BUILD_PATH" ]; then
|
2012-04-28 14:09:06 -07:00
|
|
|
BUILD_PATH="${TMP}/ruby-build.${SEED}"
|
|
|
|
|
else
|
2012-11-13 17:44:07 -06:00
|
|
|
BUILD_PATH="$RUBY_BUILD_BUILD_PATH"
|
2012-04-28 14:09:06 -07:00
|
|
|
fi
|
|
|
|
|
|
2011-08-07 15:41:20 -05:00
|
|
|
exec 4<> "$LOG_PATH" # open the log file at fd 4
|
|
|
|
|
if [ -n "$VERBOSE" ]; then
|
|
|
|
|
tail -f "$LOG_PATH" &
|
2013-02-25 11:43:36 +09:00
|
|
|
TAIL_PID=$!
|
|
|
|
|
trap "kill $TAIL_PID" SIGINT SIGTERM EXIT
|
2011-08-07 15:41:20 -05:00
|
|
|
fi
|
|
|
|
|
|
2013-10-27 13:49:59 +09:00
|
|
|
export LDFLAGS="-L${PREFIX_PATH}/lib ${LDFLAGS}"
|
|
|
|
|
export CPPFLAGS="-I${PREFIX_PATH}/include ${CPPFLAGS}"
|
2011-08-05 11:29:36 -05:00
|
|
|
|
|
|
|
|
unset RUBYOPT
|
|
|
|
|
unset RUBYLIB
|
2011-08-02 08:46:34 -05:00
|
|
|
|
2011-08-07 15:41:20 -05:00
|
|
|
trap build_failed ERR
|
2012-04-28 14:09:06 -07:00
|
|
|
mkdir -p "$BUILD_PATH"
|
2011-08-02 08:46:34 -05:00
|
|
|
source "$DEFINITION_PATH"
|
2012-04-28 14:15:01 -07:00
|
|
|
[ -z "${KEEP_BUILD_PATH}" ] && rm -fr "$BUILD_PATH"
|
2011-08-07 15:41:20 -05:00
|
|
|
trap - ERR
|