-
-
Save tchajed/20635813aec53677c65d482c1b1bb834 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash | |
# iris-release.sh prepares a commit for https://github.com/coq/opam to | |
# add a new version of std++ and Iris to the Coq opam repository. | |
# | |
# Requires a clone of opam-coq-archive. The opam files from std++ and Iris are | |
# retrieved by downloading their releases by tag. | |
set -eu | |
usage() { | |
echo "Usage: $0 [--opam-coq-archive PATH] [--stdpp VERSION] [--iris VERSION]" 1>&2 | |
echo 1>&2 | |
echo "--opam-coq-archive should point to a clone of https://github.com/coq/opam" 1>&2 | |
} | |
opam_coq_archive_path="" | |
stdpp_version="" | |
iris_version="" | |
while [[ "$#" -gt 0 ]]; do | |
case "$1" in | |
--opam-coq-archive) | |
shift | |
opam_coq_archive_path="$1" | |
shift | |
;; | |
--stdpp) | |
shift | |
stdpp_version="$1" | |
shift | |
;; | |
--iris) | |
shift | |
iris_version="$1" | |
shift | |
;; | |
-help | --help) | |
usage | |
exit 0 | |
;; | |
-*) | |
echo "error: unexpected flag $1" 2>&1 | |
usage | |
exit 1 | |
;; | |
*) | |
break | |
;; | |
esac | |
done | |
# We rely on GNU sed flags. On macOS try to use gsed hoping the user has | |
# installed it with brew install gnu-sed. | |
SED="sed" | |
# try to use GNU sed | |
if command -v gsed &>/dev/null; then | |
SED="gsed" | |
fi | |
if ! "$SED" --version >/dev/null 2>&1; then | |
echo "could not find GNU sed" 1>&2 | |
exit 1 | |
fi | |
TAR="tar" | |
# if tar is GNU tar, we need --wildcards | |
# BSD tar interprets patterns with wildcards by default and has no such option | |
if "$TAR" --version | grep "GNU tar" >/dev/null 2>&1; then | |
TAR="$TAR --wildcards" | |
fi | |
if [ -z "$opam_coq_archive_path" ] || [ -z "$stdpp_version" ] || | |
[ -z "$iris_version" ]; then | |
echo "error: arguments are all required" 1>&2 | |
usage | |
exit 1 | |
fi | |
cd "$opam_coq_archive_path" | |
git checkout master 1>/dev/null 2>&1 | |
git pull 1>/dev/null | |
## these functions use $pkg, $version, and $tarfile as global variables | |
set_pkg() { | |
export pkg="coq-$1" | |
export version="$2" | |
cd "$opam_coq_archive_path/released/packages/$pkg" | |
mkdir -p "$pkg.$version" | |
cd "$pkg.$version" | |
} | |
download_tarball() { | |
export url="$1" | |
export tarfile="$pkg-$version.tar.gz" | |
wget --quiet -O "$tarfile" "$url" | |
checksum=$(sha512sum "$tarfile" | awk '{ print $1 }') | |
export checksum | |
tarfile="$PWD/$tarfile" | |
} | |
extract_opam() { | |
# */$pkg.opam is a pattern to extract | |
# it is interpreted as a wildcard due to the setup of $TAR (which handles BSD | |
# tar vs GNU tar differences) | |
"$TAR" -O -xf "$tarfile" "*/$pkg.opam" >opam | |
## these changes are always needed | |
# delete version line | |
"$SED" -i '/^version:/d' opam | |
# add today's date as a tag | |
local date | |
date="$(date +'%Y-%m-%d')" | |
# need an escape to insert a literal space to the beginning of the line | |
"$SED" -i "/^tags:/a \ \"date:$date\"" opam | |
echo " | |
url { | |
src: | |
\"$url\" | |
checksum: | |
\"sha512=$checksum\" | |
}" >>opam | |
} | |
set_stdpp_dep() { | |
local stdpp_dep="(= \"$stdpp_version\") | (= \"dev\")" | |
"$SED" -E -i "/coq-stdpp/s/\{ .* \}/{ $stdpp_dep }/" opam | |
} | |
delete_tarball() { | |
rm "$tarfile" | |
} | |
set_pkg stdpp "$stdpp_version" | |
download_tarball "https://gitlab.mpi-sws.org/iris/stdpp/-/archive/coq-stdpp-$version.tar.gz" | |
extract_opam | |
delete_tarball | |
set_pkg iris "$iris_version" | |
download_tarball "https://gitlab.mpi-sws.org/iris/iris/-/archive/iris-$version.tar.gz" | |
extract_opam | |
set_stdpp_dep | |
set_pkg iris-heap-lang "$iris_version" | |
extract_opam | |
delete_tarball | |
echo "# Run the following in your clone of coq/opam (at $opam_coq_archive_path):" | |
echo | |
echo "git checkout -b iris-$iris_version" | |
echo "git add ." | |
echo "git commit -m \"Release Iris $iris_version and std++ $stdpp_version\"" |
Good catch, I don't see why that would have ever worked. Rather than relying on GNU tar's --wildcards
I just removed the quotes and use bash expansion.
this new version does not work either. I am pretty sure the wildcards
thing is necessary, since you need tar
to inspect the archive and select the proper file.
Ah I misunderstood what was going on. The reason it worked for me is because BSD tar (the default on macOS) already interprets that argument as a pattern, whereas GNU tar needs --wildcards
. I wrote the version check to handle both.
Thanks for testing this out and reporting bugs!
Hm, this does not seem to work for me...
../../iris/iris-release.sh: line 107: tar --wildcards: command not found
Ah, the issue is the quotes around "$TAR"
which make the entire thing one single argument.
I've put an updated version of the snippet (also supporting the new stdpp-bitvector package) at https://gitlab.mpi-sws.org/iris/iris/-/snippets/1704
tar needs a
--wildcards
on line 97, otherwise the script fails for me