bin/isabelle-process
author wenzelm
Sun May 12 13:46:41 2013 +0200 (2013-05-12)
changeset 51938 cf9c8d8d8939
parent 51932 f196352201d6
child 51948 cb5dbc9a06f9
permissions -rwxr-xr-x
Proof General interaction always uses Isar loop;
pass Isabelle/Scala options to Proof General process as well;
wenzelm@11550
     1
#!/usr/bin/env bash
wenzelm@11550
     2
#
wenzelm@11550
     3
# Author: Markus Wenzel, TU Muenchen
wenzelm@11550
     4
#
wenzelm@11550
     5
# Isabelle process startup script.
wenzelm@11550
     6
wenzelm@15843
     7
if [ -L "$0" ]; then
wenzelm@15843
     8
  TARGET="$(LC_ALL=C ls -l "$0" | sed 's/.* -> //')"
wenzelm@15967
     9
  exec "$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd "$(dirname "$TARGET")"; pwd)/$(basename "$TARGET")" "$@"
wenzelm@15843
    10
fi
wenzelm@15843
    11
wenzelm@11550
    12
wenzelm@11550
    13
## settings
wenzelm@11550
    14
wenzelm@11550
    15
PRG="$(basename "$0")"
wenzelm@11550
    16
wenzelm@15967
    17
ISABELLE_HOME="$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd ..; pwd)"
wenzelm@15967
    18
source "$ISABELLE_HOME/lib/scripts/getsettings" || exit 2
wenzelm@11550
    19
wenzelm@11550
    20
wenzelm@11550
    21
## diagnostics
wenzelm@11550
    22
wenzelm@11550
    23
function usage()
wenzelm@11550
    24
{
wenzelm@11550
    25
  echo
wenzelm@11550
    26
  echo "Usage: $PRG [OPTIONS] [INPUT] [OUTPUT]"
wenzelm@11550
    27
  echo
wenzelm@11550
    28
  echo "  Options are:"
wenzelm@11550
    29
  echo "    -I           startup Isar interaction mode"
wenzelm@11550
    30
  echo "    -P           startup Proof General interaction mode"
wenzelm@20929
    31
  echo "    -S           secure mode -- disallow critical operations"
wenzelm@45028
    32
  echo "    -T ADDR      startup process wrapper, with socket address"
wenzelm@38253
    33
  echo "    -W IN:OUT    startup process wrapper, with input/output fifos"
wenzelm@11550
    34
  echo "    -e MLTEXT    pass MLTEXT to the ML session"
wenzelm@11550
    35
  echo "    -f           pass 'Session.finish();' to the ML session"
wenzelm@11550
    36
  echo "    -m MODE      add print mode for output"
wenzelm@11550
    37
  echo "    -q           non-interactive session"
wenzelm@11550
    38
  echo "    -r           open heap file read-only"
wenzelm@11550
    39
  echo "    -u           pass 'use\"ROOT.ML\";' to the ML session"
wenzelm@11550
    40
  echo "    -w           reset write permissions on OUTPUT"
wenzelm@11550
    41
  echo
wenzelm@11550
    42
  echo "  INPUT (default \"$ISABELLE_LOGIC\") and OUTPUT specify in/out heaps."
wenzelm@11550
    43
  echo "  These are either names to be searched in the Isabelle path, or"
wenzelm@11550
    44
  echo "  actual file names (containing at least one /)."
wenzelm@11550
    45
  echo "  If INPUT is \"RAW_ML_SYSTEM\", just start the bare bones ML system."
wenzelm@11550
    46
  echo
wenzelm@11550
    47
  exit 1
wenzelm@11550
    48
}
wenzelm@11550
    49
wenzelm@11550
    50
function fail()
wenzelm@11550
    51
{
wenzelm@11550
    52
  echo "$1" >&2
wenzelm@11550
    53
  exit 2
wenzelm@11550
    54
}
wenzelm@11550
    55
wenzelm@11550
    56
wenzelm@11550
    57
## process command line
wenzelm@11550
    58
wenzelm@11550
    59
# options
wenzelm@11550
    60
wenzelm@11550
    61
ISAR=false
wenzelm@11550
    62
PROOFGENERAL=""
wenzelm@20923
    63
SECURE=""
wenzelm@45028
    64
WRAPPER_SOCKET=""
wenzelm@38253
    65
WRAPPER_FIFOS=""
wenzelm@11550
    66
MLTEXT=""
wenzelm@11550
    67
MODES=""
wenzelm@11550
    68
TERMINATE=""
wenzelm@11550
    69
READONLY=""
wenzelm@11550
    70
NOWRITE=""
wenzelm@11550
    71
wenzelm@51932
    72
while getopts "IPST:W:e:fm:qruw" OPT
wenzelm@11550
    73
do
wenzelm@11550
    74
  case "$OPT" in
wenzelm@11550
    75
    I)
wenzelm@11550
    76
      ISAR=true
wenzelm@11550
    77
      ;;
wenzelm@11550
    78
    P)
wenzelm@51938
    79
      ISAR=true
wenzelm@11550
    80
      PROOFGENERAL=true
wenzelm@11550
    81
      ;;
wenzelm@20923
    82
    S)
wenzelm@20923
    83
      SECURE=true
wenzelm@20923
    84
      ;;
wenzelm@45028
    85
    T)
wenzelm@45028
    86
      WRAPPER_SOCKET="$OPTARG"
wenzelm@45028
    87
      ;;
wenzelm@25523
    88
    W)
wenzelm@38253
    89
      WRAPPER_FIFOS="$OPTARG"
wenzelm@25523
    90
      ;;
wenzelm@11550
    91
    e)
wenzelm@11550
    92
      MLTEXT="$MLTEXT $OPTARG"
wenzelm@11550
    93
      ;;
wenzelm@11550
    94
    f)
wenzelm@51312
    95
      MLTEXT="$MLTEXT Command_Line.tool0 Session.finish;"
wenzelm@11550
    96
      ;;
wenzelm@11550
    97
    m)
wenzelm@11550
    98
      if [ -z "$MODES" ]; then
wenzelm@11550
    99
        MODES="\"$OPTARG\""
wenzelm@11550
   100
      else
wenzelm@11550
   101
        MODES="\"$OPTARG\", $MODES"
wenzelm@11550
   102
      fi
wenzelm@11550
   103
      ;;
wenzelm@11550
   104
    q)
wenzelm@11550
   105
      TERMINATE=true
wenzelm@11550
   106
      ;;
wenzelm@11550
   107
    r)
wenzelm@11550
   108
      READONLY=true
wenzelm@11550
   109
      ;;
wenzelm@11550
   110
    u)
wenzelm@11550
   111
      MLTEXT="$MLTEXT use\"ROOT.ML\";"
wenzelm@11550
   112
      ;;
wenzelm@11550
   113
    w)
wenzelm@11550
   114
      NOWRITE=true
wenzelm@11550
   115
      ;;
wenzelm@11550
   116
    \?)
wenzelm@11550
   117
      usage
wenzelm@11550
   118
      ;;
wenzelm@11550
   119
  esac
wenzelm@11550
   120
done
wenzelm@11550
   121
wenzelm@11550
   122
shift $(($OPTIND - 1))
wenzelm@11550
   123
wenzelm@11550
   124
wenzelm@11550
   125
# args
wenzelm@11550
   126
wenzelm@11550
   127
INPUT=""
wenzelm@11550
   128
OUTPUT=""
wenzelm@11550
   129
wenzelm@11550
   130
if [ "$#" -ge 1 ]; then
wenzelm@11550
   131
  INPUT="$1"
wenzelm@11550
   132
  shift
wenzelm@11550
   133
fi
wenzelm@11550
   134
wenzelm@11550
   135
if [ "$#" -ge 1 ]; then
wenzelm@11550
   136
  OUTPUT="$1"
wenzelm@11550
   137
  shift
wenzelm@11550
   138
fi
wenzelm@11550
   139
wenzelm@11550
   140
[ "$#" -ne 0 ] && { echo "Bad args: $*"; usage; }
wenzelm@11550
   141
wenzelm@11550
   142
wenzelm@11550
   143
## check ML system
wenzelm@11550
   144
wenzelm@11550
   145
[ -z "$ML_SYSTEM" ] && fail "Missing ML system settings! Unable to run Isabelle."
wenzelm@11550
   146
wenzelm@11550
   147
wenzelm@11550
   148
## input heap file
wenzelm@11550
   149
wenzelm@11550
   150
[ -z "$INPUT" ] && INPUT="$ISABELLE_LOGIC"
wenzelm@11550
   151
wenzelm@11550
   152
case "$INPUT" in
wenzelm@11550
   153
  RAW_ML_SYSTEM)
wenzelm@11550
   154
    INFILE=""
wenzelm@11550
   155
    ;;
wenzelm@11550
   156
  */*)
wenzelm@27201
   157
    INFILE="$INPUT"
wenzelm@11550
   158
    [ ! -f "$INFILE" ] && fail "Bad heap file: \"$INFILE\""
wenzelm@11550
   159
    ;;
wenzelm@11550
   160
  *)
wenzelm@11550
   161
    INFILE=""
wenzelm@11550
   162
    ISA_PATH=""
wenzelm@11550
   163
wenzelm@32390
   164
    splitarray ":" "$ISABELLE_PATH"; PATHS=("${SPLITARRAY[@]}")
wenzelm@32322
   165
    for DIR in "${PATHS[@]}"
wenzelm@11550
   166
    do
wenzelm@11550
   167
      DIR="$DIR/$ML_IDENTIFIER"
wenzelm@11550
   168
      ISA_PATH="$ISA_PATH  $DIR\n"
wenzelm@27201
   169
      [ -z "$INFILE" -a -f "$DIR/$INPUT" ] && INFILE="$DIR/$INPUT"
wenzelm@11550
   170
    done
wenzelm@11550
   171
wenzelm@11550
   172
    if [ -z "$INFILE" ]; then
wenzelm@11550
   173
      echo "Unknown logic \"$INPUT\" -- no heap file found in:" >&2
wenzelm@11550
   174
      echo -ne "$ISA_PATH" >&2
wenzelm@11550
   175
      exit 2
wenzelm@11550
   176
    fi
wenzelm@11550
   177
    ;;
wenzelm@11550
   178
esac
wenzelm@11550
   179
wenzelm@11550
   180
wenzelm@11550
   181
## output heap file
wenzelm@11550
   182
wenzelm@11550
   183
case "$OUTPUT" in
wenzelm@11550
   184
  "")
wenzelm@33920
   185
    if [ -z "$READONLY" -a -w "$INFILE" ]; then
wenzelm@33920
   186
      perl -e "exit (((stat('$INFILE'))[2] & 0222) != 0 ? 0 : 1);" && OUTFILE="$INFILE"
wenzelm@33920
   187
    fi
wenzelm@11550
   188
    ;;
wenzelm@11550
   189
  */*)
wenzelm@27201
   190
    OUTFILE="$OUTPUT"
wenzelm@11550
   191
    ;;
wenzelm@11550
   192
  *)
wenzelm@11550
   193
    mkdir -p "$ISABELLE_OUTPUT"
wenzelm@27201
   194
    OUTFILE="$ISABELLE_OUTPUT/$OUTPUT"
wenzelm@11550
   195
    ;;
wenzelm@11550
   196
esac
wenzelm@11550
   197
wenzelm@11550
   198
wenzelm@11550
   199
## prepare tmp directory
wenzelm@11550
   200
wenzelm@11550
   201
[ -z "$ISABELLE_TMP_PREFIX" ] && ISABELLE_TMP_PREFIX=/tmp/isabelle
wenzelm@16874
   202
ISABELLE_PID="$$"
wenzelm@17792
   203
ISABELLE_TMP="$ISABELLE_TMP_PREFIX$ISABELLE_PID"
wenzelm@16874
   204
mkdir -p "$ISABELLE_TMP"
wenzelm@11550
   205
wenzelm@11550
   206
wenzelm@11550
   207
## run it!
wenzelm@11550
   208
wenzelm@11550
   209
ML_SYSTEM_BASE=$(echo "$ML_SYSTEM" | cut -f1 -d-)
wenzelm@11550
   210
wenzelm@45056
   211
[ -n "$MODES" ] && MLTEXT="Unsynchronized.change print_mode (append [$MODES]); $MLTEXT"
wenzelm@11550
   212
wenzelm@20923
   213
[ -n "$SECURE" ] && MLTEXT="$MLTEXT Secure.set_secure ();"
wenzelm@20923
   214
wenzelm@25645
   215
NICE="nice"
wenzelm@38253
   216
wenzelm@45028
   217
if [ -n "$WRAPPER_SOCKET" ]; then
wenzelm@45028
   218
  MLTEXT="$MLTEXT; Isabelle_Process.init_socket \"$WRAPPER_SOCKET\";"
wenzelm@45028
   219
elif [ -n "$WRAPPER_FIFOS" ]; then
wenzelm@38253
   220
  splitarray ":" "$WRAPPER_FIFOS"; FIFOS=("${SPLITARRAY[@]}")
wenzelm@38253
   221
  [ "${#FIFOS[@]}" -eq 2 ] || fail "Expected IN:OUT fifo specification"
wenzelm@38253
   222
  [ -p "${FIFOS[0]}" ] || fail "Bad input fifo: ${FIFOS[0]}"
wenzelm@38253
   223
  [ -p "${FIFOS[1]}" ] || fail "Bad output fifo: ${FIFOS[1]}"
wenzelm@45028
   224
  MLTEXT="$MLTEXT; Isabelle_Process.init_fifos \"${FIFOS[0]}\" \"${FIFOS[1]}\";"
wenzelm@11550
   225
elif [ "$ISAR" = true ]; then
wenzelm@48698
   226
  if [ -z "$ISABELLE_PROCESS_OPTIONS" ]; then
wenzelm@48698
   227
    ISABELLE_PROCESS_OPTIONS="$ISABELLE_TMP/options"
wenzelm@48698
   228
    "$ISABELLE_TOOL" options -x "$ISABELLE_PROCESS_OPTIONS" || fail "Failed to retrieve options"
wenzelm@48698
   229
  fi
wenzelm@51938
   230
  if [ -n "$PROOFGENERAL" ]; then
wenzelm@51938
   231
    MLTEXT="$MLTEXT; ProofGeneral.init ();"
wenzelm@51938
   232
  else
wenzelm@51938
   233
    MLTEXT="$MLTEXT; Isar.main ();"
wenzelm@51938
   234
  fi
wenzelm@25645
   235
else
wenzelm@25645
   236
  NICE=""
wenzelm@11550
   237
fi
wenzelm@11550
   238
wenzelm@48698
   239
export INFILE OUTFILE MLTEXT TERMINATE NOWRITE ISABELLE_PID ISABELLE_TMP ISABELLE_PROCESS_OPTIONS
wenzelm@11550
   240
wenzelm@11550
   241
if [ -f "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM" ]; then
wenzelm@25645
   242
  $NICE "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM"
wenzelm@11550
   243
else
wenzelm@25645
   244
  $NICE "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM_BASE"
wenzelm@11550
   245
fi
wenzelm@11550
   246
RC="$?"
wenzelm@11550
   247
wenzelm@48698
   248
[ -n "$ISABELLE_PROCESS_OPTIONS" ] && rm -f "$ISABELLE_PROCESS_OPTIONS"
wenzelm@11550
   249
rmdir "$ISABELLE_TMP"
wenzelm@11550
   250
wenzelm@11550
   251
exit "$RC"