Skip to content

Instantly share code, notes, and snippets.

@aliak00
Created November 7, 2018 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliak00/bc878cf9e24be75776c55d60e8758f38 to your computer and use it in GitHub Desktop.
Save aliak00/bc878cf9e24be75776c55d60e8758f38 to your computer and use it in GitHub Desktop.
If you ever feel the need to update dmd for homebrew
#!/usr/bin/env bash
#
# This is just convenience to make updating dmd for homebrew a one liner (ish)
# You still need to "git commit" the changes and push and make a PR.
#
show_help() {
echo "usage: $(basename "$0") -f <brew-fork-dir> -v <released-dmd-version>"
}
dmd_version=""
brew_fork=""
while getopts "f:v:" opt; do
case "$opt" in
f)
brew_fork=${OPTARG}
;;
v) dmd_version=${OPTARG}
;;
*)
show_help
;;
esac
done
if [[ -z $dmd_version ]]; then
echo "Must specify which DMD version you want to push"
show_help
exit 1
fi
if [[ -z $brew_fork ]]; then
echo "Must specify directory where your fork of homebrew-core is"
show_help
exit 1
fi
if [ ! -f $brew_fork/Formula/dmd.rb ]; then
echo "Cannot find 'Formula/dmd.rb' in directory $brew_fork"
show_help
exit 1
fi
dmd_filename="dmd.tar.gz"
druntime_filename="druntime.tar.gz"
phobos_filename="phobos.tar.gz"
tools_filename="tools.tar.gz"
archive="v$dmd_version.tar.gz"
dmd_url="https://github.com/dlang/dmd/archive/$archive"
druntime_url="https://github.com/dlang/druntime/archive/$archive"
phobos_url="https://github.com/dlang/phobos/archive/$archive"
tools_url="https://github.com/dlang/tools/archive/$archive"
tmp_dir=`mktemp -d`
echo "Downloading DMD files to $tmp_dir"
wget -O "$tmp_dir/$dmd_filename" -q --show-progress $dmd_url
wget -O "$tmp_dir/$druntime_filename" -q --show-progress $druntime_url
wget -O "$tmp_dir/$phobos_filename" -q --show-progress $phobos_url
wget -O "$tmp_dir/$tools_filename" -q --show-progress $tools_url
dmd_sha=`shasum -a 256 $tmp_dir/$dmd_filename | awk '{print $1;}'`
druntime_sha=`shasum -a 256 $tmp_dir/$druntime_filename | awk '{print $1;}'`
phobos_sha=`shasum -a 256 $tmp_dir/$phobos_filename | awk '{print $1;}'`
tools_sha=`shasum -a 256 $tmp_dir/$tools_filename | awk '{print $1;}'`
rm -rf $tmp_dir
read -d '' changes << EOM
stable do
url "$dmd_url"
sha256 "$dmd_sha"
resource "druntime" do
url "$druntime_url"
sha256 "$druntime_sha"
end
resource "phobos" do
url "$phobos_url"
sha256 "$phobos_sha"
end
resource "tools" do
url "$tools_url"
sha256 "$tools_sha"
end
end
b
EOM
# The weirdness with the lone b above is because I can't figure out how to tell the perl command
# below to INCLUDE the trailing whitespace and newlines when doing the substitution. Consequently,
# the regex below is also "ottle do" instead of the actual "bottle do"
perl -i -p0e "s/stable do.+?(?=ottle do)/${changes//\//\\/}/s" $brew_fork/Formula/dmd.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment