lib/Tools/build
author wenzelm
Thu, 26 Jul 2012 12:27:47 +0200
changeset 48509 4854ced3e9d7
parent 48474 5b9d79c6323b
child 48511 37999ee01156
permissions -rwxr-xr-x
support session groups; tuned signature;
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
48474
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    12
function show_settings()
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    13
{
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    14
  local PREFIX="$1"
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    15
  echo "${PREFIX}ISABELLE_BUILD_OPTIONS=\"$ISABELLE_BUILD_OPTIONS\""
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    16
  echo
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    17
  echo "${PREFIX}ML_PLATFORM=\"$ML_PLATFORM\""
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    18
  echo "${PREFIX}ML_HOME=\"$ML_HOME\""
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    19
  echo "${PREFIX}ML_SYSTEM=\"$ML_SYSTEM\""
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    20
  echo "${PREFIX}ML_OPTIONS=\"$ML_OPTIONS\""
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    21
}
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    22
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    23
function usage()
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    24
{
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    25
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    26
  echo "Usage: isabelle $PRG [OPTIONS] [SESSIONS ...]"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    27
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    28
  echo "  Options are:"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    29
  echo "    -a           all sessions"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    30
  echo "    -b           build target images"
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    31
  echo "    -d DIR       include session directory with ROOT file"
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    32
  echo "    -g NAME      include session group NAME"
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    33
  echo "    -j INT       maximum number of jobs (default 1)"
48469
826a771cff33 clarified build -n (no build);
wenzelm
parents: 48459
diff changeset
    34
  echo "    -n           no build -- test dependencies only"
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    35
  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
    36
  echo "    -s           system build mode: produce output in ISABELLE_HOME"
48459
375e45df6fdf timing is command line options, not system option;
wenzelm
parents: 48447
diff changeset
    37
  echo "    -t           inner session timing"
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    38
  echo "    -v           verbose"
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    39
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    40
  echo "  Build and manage Isabelle sessions, depending on implicit"
48474
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
    41
  show_settings "  "
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    42
  echo
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    43
  exit 1
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    44
}
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    45
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    46
function fail()
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    47
{
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    48
  echo "$1" >&2
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    49
  exit 2
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    50
}
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    51
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    52
function check_number()
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    53
{
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    54
  [ -n "$1" -a -z "$(echo "$1" | tr -d '[0-9]')" ] || fail "Bad number: \"$1\""
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    55
}
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    56
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    57
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    58
## process command line
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    59
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    60
ALL_SESSIONS=false
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    61
BUILD_IMAGES=false
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    62
declare -a MORE_DIRS=()
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    63
declare -a SESSION_GROUPS=()
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    64
MAX_JOBS=1
48469
826a771cff33 clarified build -n (no build);
wenzelm
parents: 48459
diff changeset
    65
NO_BUILD=false
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    66
eval "declare -a BUILD_OPTIONS=($ISABELLE_BUILD_OPTIONS)"
48447
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    67
SYSTEM_MODE=false
48459
375e45df6fdf timing is command line options, not system option;
wenzelm
parents: 48447
diff changeset
    68
TIMING=false
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    69
VERBOSE=false
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    70
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    71
while getopts "abd:g:j:no:stv" OPT
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    72
do
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    73
  case "$OPT" in
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    74
    a)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    75
      ALL_SESSIONS="true"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    76
      ;;
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    77
    b)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    78
      BUILD_IMAGES="true"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    79
      ;;
48340
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
    80
    d)
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
    81
      MORE_DIRS["${#MORE_DIRS[@]}"]="$OPTARG"
6f4fc030882a allow explicit specification of additional session directories;
wenzelm
parents: 48276
diff changeset
    82
      ;;
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    83
    g)
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    84
      SESSION_GROUPS["${#SESSION_GROUPS[@]}"]="$OPTARG"
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
    85
      ;;
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    86
    j)
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    87
      check_number "$OPTARG"
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    88
      MAX_JOBS="$OPTARG"
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
    89
      ;;
48469
826a771cff33 clarified build -n (no build);
wenzelm
parents: 48459
diff changeset
    90
    n)
826a771cff33 clarified build -n (no build);
wenzelm
parents: 48459
diff changeset
    91
      NO_BUILD="true"
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    92
      ;;
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    93
    o)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    94
      BUILD_OPTIONS["${#BUILD_OPTIONS[@]}"]="$OPTARG"
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    95
      ;;
48447
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    96
    s)
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    97
      SYSTEM_MODE="true"
ef600ce4559c added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents: 48425
diff changeset
    98
      ;;
48459
375e45df6fdf timing is command line options, not system option;
wenzelm
parents: 48447
diff changeset
    99
    t)
375e45df6fdf timing is command line options, not system option;
wenzelm
parents: 48447
diff changeset
   100
      TIMING="true"
375e45df6fdf timing is command line options, not system option;
wenzelm
parents: 48447
diff changeset
   101
      ;;
48425
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
   102
    v)
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
   103
      VERBOSE="true"
0d95980e9aae parallel scheduling of jobs;
wenzelm
parents: 48340
diff changeset
   104
      ;;
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   105
    \?)
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   106
      usage
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   107
      ;;
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   108
  esac
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   109
done
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   110
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   111
shift $(($OPTIND - 1))
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   112
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   113
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   114
## main
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   115
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   116
[ -e "$ISABELLE_HOME/Admin/build" ] && { "$ISABELLE_HOME/Admin/build" jars || exit $?; }
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   117
48474
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   118
if [ "$NO_BUILD" = false ]; then
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   119
  echo "Started at $(date) ($ML_IDENTIFIER on $(hostname))"
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   120
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   121
  if [ "$VERBOSE" = true ]; then
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   122
    show_settings ""
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   123
    echo
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   124
  fi
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   125
  . "$ISABELLE_HOME/lib/scripts/timestart.bash"
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   126
fi
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   127
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   128
"$ISABELLE_TOOL" java isabelle.Build \
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
   129
  "$ALL_SESSIONS" "$BUILD_IMAGES" "$MAX_JOBS" "$NO_BUILD" "$SYSTEM_MODE" "$TIMING" "$VERBOSE" \
4854ced3e9d7 support session groups;
wenzelm
parents: 48474
diff changeset
   130
  "${MORE_DIRS[@]}" $'\n' "${SESSION_GROUPS[@]}" $'\n' "${BUILD_OPTIONS[@]}" $'\n' "$@"
48474
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   131
RC="$?"
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   132
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   133
if [ "$NO_BUILD" = false ]; then
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   134
  echo -n "Finished at "; date
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   135
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   136
  . "$ISABELLE_HOME/lib/scripts/timestop.bash"
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   137
  echo "$TIMES_REPORT"
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   138
fi
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   139
5b9d79c6323b tuned messages (cf. isabelle makeall);
wenzelm
parents: 48469
diff changeset
   140
exit "$RC"