Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fetch and install the latest nightly build of Ruby on macOX
#!/usr/bin/env zsh -e
zparseopts -D -- h=help -help=help \
j:=jobs -jobs:=jobs \
-no-install-deps=no_install_deps \
d:=rubies_dir -rubies-dir:=rubies_dir \
n:=ruby_name -ruby-name:=ruby_name \
s:=src_dir -src-dir:=src_dir \
u:=url -url:=url \
v=version -version=version
function nightly-log() {
if [[ -t 1 ]]; then
print -r -P "%B%F{green}>>>%F{reset_color}%b $1 ..."
else
print -r ">>> $1 ..."
fi
}
function nightly-brew-deps() {
brew install "$@" 2>/dev/null
brew upgrade "$@" || true
}
function nightly-remove-old() {
rm -f "$ruby_src"
rm -rf "$ruby_src_dir"
rm -rf "$rubies_dir/$ruby_name"
}
function nightly-fetch-source() {
mkdir -p "$src_dir"
curl -f "$ruby_url" > "$ruby_src"
tar -xjvf "$ruby_src" -C "$src_dir"
}
function nightly-configure() {
mkdir -p "$rubies_dir"
(cd "$ruby_src_dir" && "$ruby_src_dir/configure" "$@")
}
function nightly-build() {
make "$@" -C "$ruby_src_dir"
make install -C "$ruby_src_dir"
}
function nightly-usage() {
cat <<USAGE
usage: ${0:t} [OPTIONS]
Options:
-h, --help
-j, --jobs JOBS
--no-install-deps
-d, --rubies-dir DIR
-n, --ruby-name NAME
-s, --src-dir DIR
-u, --url URL
-v, --version
USAGE
}
if (( $# )); then
print -r -u2 "fatal: unrecognized option: $1"
exit 1
fi
if (( $+help[1] )); then
nightly-usage
exit
fi
if (( $+version[1] )); then
print -r "${0:t} 0.0.1"
exit
fi
if (( UID )); then
rubies_dir="${rubies_dir[2]:-$HOME/.rubies}"
src_dir="${src_dir[2]:-$HOME/src}"
else
rubies_dir="${rubies_dir[2]:-/opt/rubies}"
src_dir="${src_dir[2]:-/usr/local/src}"
fi
jobs="${jobs[2]:-8}"
ruby_name="${ruby_name[2]:-ruby-nightly}"
ruby_url="${url[2]:-https://cache.ruby-lang.org/pub/ruby/snapshot.tar.bz2}"
ruby_src="$src_dir/${ruby_url:t}"
ruby_src_dir="${ruby_src:r:r}"
opt_dirs=()
if (( $+commands[brew] )); then
for dep (gdbm libffi libyaml openssl readline) opt_dirs+=($(brew --prefix "$dep"))
if (( ! $+no_install_deps[1] )); then
nightly-log "Installing & updating Homebrew packages"
nightly-brew-deps automake bison gdbm jemalloc libffi libyaml openssl readline
fi
fi
nightly-log "Cleaning up previous $ruby_name install"
nightly-remove-old
nightly-log "Fetching $ruby_name source"
nightly-fetch-source
nightly-log "Configuring $ruby_name"
nightly-configure --prefix="$rubies_dir/$ruby_name" --with-opt-dir="${(j[:])opt_dirs}" --with-jemalloc
nightly-log "Building $ruby_name"
nightly-build -j "$jobs"
nightly-log "Successfully installed $ruby_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.