check-tarball.sh 1.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This script checks that a Menhir tarball can be compiled and installed.
# The command line argument should be the tarball's name without .tar.gz.

PACKAGE="$1"
TARBALL=$PACKAGE.tar.gz

# Some of the demos assume Menhir has been installed using ocamlfind, so that
# is what we do. For this reason, we must first check that ocamlfind does not
# already have some version of menhirLib and menhirSdk.

# We could also create a fresh opam switch, but that would be time-consuming.

if ocamlfind query menhirLib >/dev/null 2>/dev/null ; then
  if opam list -i menhir 2>/dev/null | grep -v -e "^#" | grep menhir ; then
    echo "Warning: menhir is already installed." ;
    read -p "Can I remove it [Enter/^C]?" -n 1 -r ;
    opam remove menhir ;
  else
    echo "Warning: menhirLib is already installed." ;
    read -p "Can I remove it [Enter/^C]?" -n 1 -r ;
    ocamlfind remove menhirLib ;
    ocamlfind remove menhirSdk || true ;
  fi ;
fi

# Create a temporary directory; extract, build, and install the package into
# it; build the demos using the installed binary.

TEMPDIR=`mktemp -d /tmp/menhir-test.XXXXXX`
INSTALL=$TEMPDIR/install
35
COQCONTRIB=$INSTALL/coq-contrib
36 37 38 39 40 41 42 43 44 45

cp $TARBALL $TEMPDIR

echo "   * Extracting. "
(cd $TEMPDIR && tar xfz $TARBALL)

echo "   * Compiling and installing."
mkdir $INSTALL
(cd $TEMPDIR/$PACKAGE &&
  make PREFIX=$INSTALL USE_OCAMLFIND=true &&
46 47 48
  make PREFIX=$INSTALL USE_OCAMLFIND=true install &&
  make -C coq-menhirlib all &&
  make -C coq-menhirlib CONTRIB=$COQCONTRIB install
49 50 51 52 53 54 55 56 57 58
) > $TEMPDIR/install.log 2>&1 || (cat $TEMPDIR/install.log; exit 1)

echo "   * Building the demos."
(cd $TEMPDIR/$PACKAGE &&
  make MENHIR=$INSTALL/bin/menhir -C demos
) > $TEMPDIR/demos.log 2>&1 || (cat $TEMPDIR/demos.log; exit 1)

echo "   * Uninstalling."
(cd $TEMPDIR/$PACKAGE &&
  make PREFIX=$INSTALL USE_OCAMLFIND=true uninstall
59
  make -C coq-menhirlib CONTRIB=$COQCONTRIB uninstall
60 61 62
) > $TEMPDIR/uninstall.log 2>&1 || (cat $TEMPDIR/uninstall.log; exit 1)

rm -rf $TEMPDIR