lib/Tools/build
author wenzelm
Mon, 23 Jul 2012 15:59:14 +0200
changeset 48447 ef600ce4559c
parent 48425 0d95980e9aae
child 48459 375e45df6fdf
permissions -rwxr-xr-x
added system build mode: produce output in ISABELLE_HOME; determine output location more explicitly;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     1
#!/usr/bin/env bash
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     2
#
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     3
# Author: Makarius
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     4
#
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     5
# DESCRIPTION: build and manage Isabelle sessions
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     6
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     7
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     8
## diagnostics
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     9
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    10
PRG="$(basename "$0")"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    11
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    12
function usage()
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    13
{
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    14
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    15
  echo "Usage: isabelle $PRG [OPTIONS] [SESSIONS ...]"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    16
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    17
  echo "  Options are:"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    18
  echo "    -a           all sessions"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    19
  echo "    -b           build target images"
48340
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
    20
  echo "    -d DIR       additional session directory with ROOT file"
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    21
  echo "    -j INT       maximum number of jobs (default 1)"
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    22
  echo "    -l           list sessions only"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    23
  echo "    -o OPTION    override session configuration OPTION (via NAME=VAL or NAME)"
48447
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    24
  echo "    -s           system build mode: produce output in ISABELLE_HOME"
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    25
  echo "    -v           verbose"
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    26
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    27
  echo "  Build and manage Isabelle sessions, depending on implicit"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    28
  echo "  ISABELLE_BUILD_OPTIONS=\"$ISABELLE_BUILD_OPTIONS\""
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    29
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    30
  echo "  ML_PLATFORM=\"$ML_PLATFORM\""
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    31
  echo "  ML_HOME=\"$ML_HOME\""
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    32
  echo "  ML_SYSTEM=\"$ML_SYSTEM\""
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    33
  echo "  ML_OPTIONS=\"$ML_OPTIONS\""
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    34
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    35
  exit 1
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    36
}
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    37
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    38
function fail()
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    39
{
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    40
  echo "$1" >&2
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    41
  exit 2
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    42
}
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    43
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    44
function check_number()
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    45
{
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    46
  [ -n "$1" -a -z "$(echo "$1" | tr -d '[0-9]')" ] || fail "Bad number: \"$1\""
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    47
}
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    48
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    49
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    50
## process command line
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    51
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    52
ALL_SESSIONS=false
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    53
BUILD_IMAGES=false
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    54
MAX_JOBS=1
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    55
LIST_ONLY=false
48447
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    56
SYSTEM_MODE=false
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    57
VERBOSE=false
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    58
48340
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
    59
declare -a MORE_DIRS=()
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    60
eval "declare -a BUILD_OPTIONS=($ISABELLE_BUILD_OPTIONS)"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    61
48447
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    62
while getopts "abd:j:lo:sv" OPT
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    63
do
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    64
  case "$OPT" in
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    65
    a)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    66
      ALL_SESSIONS="true"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    67
      ;;
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    68
    b)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    69
      BUILD_IMAGES="true"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    70
      ;;
48340
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
    71
    d)
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
    72
      MORE_DIRS["${#MORE_DIRS[@]}"]="$OPTARG"
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
    73
      ;;
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    74
    j)
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    75
      check_number "$OPTARG"
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    76
      MAX_JOBS="$OPTARG"
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    77
      ;;
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    78
    l)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    79
      LIST_ONLY="true"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    80
      ;;
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    81
    o)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    82
      BUILD_OPTIONS["${#BUILD_OPTIONS[@]}"]="$OPTARG"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    83
      ;;
48447
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    84
    s)
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    85
      SYSTEM_MODE="true"
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    86
      ;;
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    87
    v)
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    88
      VERBOSE="true"
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    89
      ;;
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    90
    \?)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    91
      usage
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    92
      ;;
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    93
  esac
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    94
done
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    95
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    96
shift $(($OPTIND - 1))
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    97
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    98
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    99
## main
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   100
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   101
[ -e "$ISABELLE_HOME/Admin/build" ] && { "$ISABELLE_HOME/Admin/build" jars || exit $?; }
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   102
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   103
exec "$ISABELLE_TOOL" java isabelle.Build \
48447
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
   104
  "$ALL_SESSIONS" "$BUILD_IMAGES" "$MAX_JOBS" "$LIST_ONLY" "$SYSTEM_MODE" "$VERBOSE" \
48340
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
   105
  "${MORE_DIRS[@]}" $'\n' "${BUILD_OPTIONS[@]}" $'\n' "$@"