src/HOL/Mirabelle/lib/Tools/mirabelle
author blanchet
Wed, 21 Jun 2017 22:48:55 +0200
changeset 66156 f54c32c413a9
parent 48703 d408ff0abf23
child 72342 4195e75a92ef
permissions -rwxr-xr-x
added -d option to Mirabelle
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
     1
#!/usr/bin/env bash
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
     2
#
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
     3
# Author: Sascha Boehme
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
     4
#
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
     5
# DESCRIPTION: testing tool for automated proof tools
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     6
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     7
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
     8
PRG="$(basename "$0")"
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     9
47848
030d3c89eacf more robust wrt. spaces in directory names;
wenzelm
parents: 47846
diff changeset
    10
function print_action_names()
030d3c89eacf more robust wrt. spaces in directory names;
wenzelm
parents: 47846
diff changeset
    11
{
030d3c89eacf more robust wrt. spaces in directory names;
wenzelm
parents: 47846
diff changeset
    12
  for TOOL in "$MIRABELLE_HOME/Tools"/mirabelle_*.ML
32397
1899b8c47961 more quoting for shell variables, canonical isabelle process
boehmes
parents: 32385
diff changeset
    13
  do
47848
030d3c89eacf more robust wrt. spaces in directory names;
wenzelm
parents: 47846
diff changeset
    14
    echo "$TOOL" | perl -w -p -e 's/.*mirabelle_(.*)\.ML/    $1/'
32397
1899b8c47961 more quoting for shell variables, canonical isabelle process
boehmes
parents: 32385
diff changeset
    15
  done
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    16
}
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    17
47480
24d8c9e9dae4 Mirabelle's 'usage' description relating to Sledgehammer now synchs with the ML code of the Mirabelle-Sledgehammer action
sultana
parents: 47479
diff changeset
    18
function print_sledgehammer_options() {
47848
030d3c89eacf more robust wrt. spaces in directory names;
wenzelm
parents: 47846
diff changeset
    19
  grep -e "^val .*K =" "$MIRABELLE_HOME/Tools/mirabelle_sledgehammer.ML" | \
030d3c89eacf more robust wrt. spaces in directory names;
wenzelm
parents: 47846
diff changeset
    20
  perl -w -p -e 's/val .*K *= *"(.*)" *\(\*(.*)\*\)/    $1$2/'
47480
24d8c9e9dae4 Mirabelle's 'usage' description relating to Sledgehammer now synchs with the ML code of the Mirabelle-Sledgehammer action
sultana
parents: 47479
diff changeset
    21
}
24d8c9e9dae4 Mirabelle's 'usage' description relating to Sledgehammer now synchs with the ML code of the Mirabelle-Sledgehammer action
sultana
parents: 47479
diff changeset
    22
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    23
function usage() {
42069
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
    24
  [ -n "$MIRABELLE_OUTPUT_PATH" ] && out="$MIRABELLE_OUTPUT_PATH" || out="None"
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    25
  timeout="$MIRABELLE_TIMEOUT"
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    26
  echo
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    27
  echo "Usage: isabelle $PRG [OPTIONS] ACTIONS FILES"
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    28
  echo
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    29
  echo "  Options are:"
40976
8df0a190df1e correcting usage documentation in mirabelle tool
bulwahn
parents: 34035
diff changeset
    30
  echo "    -L LOGIC     parent logic to use (default $MIRABELLE_LOGIC)"
66156
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    31
  echo "    -O DIR       output directory for test data (default $out)"
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    32
  echo "    -S FILE      user-provided setup file (no actions required)"
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    33
  echo "    -T THEORY    parent theory to use (default $MIRABELLE_THEORY)"
66156
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    34
  echo "    -d DIR       include session directory"
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    35
  echo "    -q           be quiet (suppress output of Isabelle process)"
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    36
  echo "    -t TIMEOUT   timeout for each action in seconds (default $timeout)"
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    37
  echo
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    38
  echo "  Apply the given actions (i.e., automated proof tools)"
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    39
  echo "  at all proof steps in the given theory files."
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    40
  echo
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    41
  echo "  ACTIONS is a colon-separated list of actions, where each action is"
32522
1b70db55c811 Mirabelle: command-line action options may either be key=value or just key
boehmes
parents: 32521
diff changeset
    42
  echo "  either NAME or NAME[OPTION,...,OPTION]. Available actions are:"
32397
1899b8c47961 more quoting for shell variables, canonical isabelle process
boehmes
parents: 32385
diff changeset
    43
  print_action_names
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    44
  echo
33248
95478a5b4c05 included description for sledgehammer options in Mirabelle script
boehmes
parents: 32522
diff changeset
    45
  echo "  Available OPTIONs for the ACTION sledgehammer:"
47480
24d8c9e9dae4 Mirabelle's 'usage' description relating to Sledgehammer now synchs with the ML code of the Mirabelle-Sledgehammer action
sultana
parents: 47479
diff changeset
    46
  print_sledgehammer_options
32522
1b70db55c811 Mirabelle: command-line action options may either be key=value or just key
boehmes
parents: 32521
diff changeset
    47
  echo
32397
1899b8c47961 more quoting for shell variables, canonical isabelle process
boehmes
parents: 32385
diff changeset
    48
  echo "  FILES is a list of theory files, where each file is either NAME.thy"
1899b8c47961 more quoting for shell variables, canonical isabelle process
boehmes
parents: 32385
diff changeset
    49
  echo "  or NAME.thy[START:END] and START and END are numbers indicating the"
1899b8c47961 more quoting for shell variables, canonical isabelle process
boehmes
parents: 32385
diff changeset
    50
  echo "  range the given actions are to be applied."
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    51
  echo
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    52
  exit 1
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    53
}
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    54
42034
a77df5241959 propagate mirabelle failures properly;
krauss
parents: 40976
diff changeset
    55
function fail()
a77df5241959 propagate mirabelle failures properly;
krauss
parents: 40976
diff changeset
    56
{
a77df5241959 propagate mirabelle failures properly;
krauss
parents: 40976
diff changeset
    57
  echo "$1" >&2
a77df5241959 propagate mirabelle failures properly;
krauss
parents: 40976
diff changeset
    58
  exit 2
a77df5241959 propagate mirabelle failures properly;
krauss
parents: 40976
diff changeset
    59
}
a77df5241959 propagate mirabelle failures properly;
krauss
parents: 40976
diff changeset
    60
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    61
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    62
## process command line
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    63
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    64
# options
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    65
47479
e6add51fd7ba Mirabelle now gives usage info when no arguments given
sultana
parents: 47478
diff changeset
    66
[ $# -eq 0 ] && usage
e6add51fd7ba Mirabelle now gives usage info when no arguments given
sultana
parents: 47478
diff changeset
    67
66156
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    68
MIRABELLE_DIR=
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47848
diff changeset
    69
MIRABELLE_SETUP_FILE=
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47848
diff changeset
    70
66156
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    71
while getopts "L:T:O:d:t:S:q?" OPT
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    72
do
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    73
  case "$OPT" in
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    74
    L)
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    75
      MIRABELLE_LOGIC="$OPTARG"
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    76
      ;;
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    77
    T)
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    78
      MIRABELLE_THEORY="$OPTARG"
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    79
      ;;
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    80
    O)
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    81
      MIRABELLE_OUTPUT_PATH="$OPTARG"
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    82
      ;;
66156
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    83
    d)
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    84
      MIRABELLE_DIR="$OPTARG"
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
    85
      ;;
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    86
    t)
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    87
      MIRABELLE_TIMEOUT="$OPTARG"
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    88
      ;;
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47848
diff changeset
    89
    S)
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47848
diff changeset
    90
      MIRABELLE_SETUP_FILE="$OPTARG"
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47848
diff changeset
    91
      ;;
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32496
diff changeset
    92
    q)
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32496
diff changeset
    93
      MIRABELLE_QUIET="true"
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32496
diff changeset
    94
      ;;
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    95
    \?)
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    96
      usage
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    97
      ;;
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    98
  esac
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    99
done
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   100
66156
f54c32c413a9 added -d option to Mirabelle
blanchet
parents: 48703
diff changeset
   101
export MIRABELLE_DIR
48703
d408ff0abf23 extended Mirabelle to support user-provided setup files which contain the configuration for a Mirabelle run (avoids some layers of scripts and reduces the complexity of the overall Mirabelle setup)
boehmes
parents: 47848
diff changeset
   102
export MIRABELLE_SETUP_FILE
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32496
diff changeset
   103
export MIRABELLE_QUIET
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32496
diff changeset
   104
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   105
shift $(($OPTIND - 1))
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   106
32521
f20cc66b2c74 added initialization and cleanup of actions,
boehmes
parents: 32496
diff changeset
   107
export MIRABELLE_ACTIONS="$1"
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   108
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   109
shift
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   110
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   111
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   112
# setup
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   113
42069
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   114
if [ -z "$MIRABELLE_OUTPUT_PATH" ]; then
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   115
  MIRABELLE_OUTPUT_PATH="${ISABELLE_TMP_PREFIX}-mirabelle$$"
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   116
  PURGE_OUTPUT="true"
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   117
fi
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   118
32397
1899b8c47961 more quoting for shell variables, canonical isabelle process
boehmes
parents: 32385
diff changeset
   119
mkdir -p "$MIRABELLE_OUTPUT_PATH"
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   120
42069
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   121
export MIRABELLE_OUTPUT_PATH
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   122
47848
030d3c89eacf more robust wrt. spaces in directory names;
wenzelm
parents: 47846
diff changeset
   123
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   124
## main
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   125
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   126
for FILE in "$@"
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   127
do
42034
a77df5241959 propagate mirabelle failures properly;
krauss
parents: 40976
diff changeset
   128
  perl -w "$MIRABELLE_HOME/lib/scripts/mirabelle.pl" "$FILE" || fail "Mirabelle failed."
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
   129
done
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   130
42069
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   131
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   132
## cleanup
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   133
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   134
if [ -n "$PURGE_OUTPUT" ]; then
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   135
  rm -rf "$MIRABELLE_OUTPUT_PATH"
6a147393c62a replace hardwired MIRABELLE_OUTPUT_PATH by temporary directory derived from ISABELLE_TMP_PREFIX and $$ -- old behaviour can be achieved by manually setting MIRABELLE_OUTPUT_PATH
krauss
parents: 42034
diff changeset
   136
fi