lib/Tools/build
author wenzelm
Mon Jul 30 13:48:56 2012 +0200 (2012-07-30)
changeset 48601 655b08c2cd89
parent 48595 231e6fa96dbb
child 48737 f3bbb9ca57d6
permissions -rwxr-xr-x
less verbosity;
     1 #!/usr/bin/env bash
     2 #
     3 # Author: Makarius
     4 #
     5 # DESCRIPTION: build and manage Isabelle sessions
     6 
     7 
     8 ## diagnostics
     9 
    10 PRG="$(basename "$0")"
    11 
    12 function show_settings()
    13 {
    14   local PREFIX="$1"
    15   echo "${PREFIX}ISABELLE_BUILD_OPTIONS=\"$ISABELLE_BUILD_OPTIONS\""
    16   echo
    17   echo "${PREFIX}ML_PLATFORM=\"$ML_PLATFORM\""
    18   echo "${PREFIX}ML_HOME=\"$ML_HOME\""
    19   echo "${PREFIX}ML_SYSTEM=\"$ML_SYSTEM\""
    20   echo "${PREFIX}ML_OPTIONS=\"$ML_OPTIONS\""
    21 }
    22 
    23 function usage()
    24 {
    25   echo
    26   echo "Usage: isabelle $PRG [OPTIONS] [SESSIONS ...]"
    27   echo
    28   echo "  Options are:"
    29   echo "    -a           select all sessions"
    30   echo "    -b           build heap images"
    31   echo "    -c           clean build"
    32   echo "    -d DIR       include session directory with ROOT file"
    33   echo "    -g NAME      select session group NAME"
    34   echo "    -j INT       maximum number of parallel jobs (default 1)"
    35   echo "    -n           no build -- test dependencies only"
    36   echo "    -o OPTION    override session configuration OPTION (via NAME=VAL or NAME)"
    37   echo "    -s           system build mode: produce output in ISABELLE_HOME"
    38   echo "    -v           verbose"
    39   echo
    40   echo "  Build and manage Isabelle sessions, depending on implicit"
    41   show_settings "  "
    42   echo
    43   exit 1
    44 }
    45 
    46 function fail()
    47 {
    48   echo "$1" >&2
    49   exit 2
    50 }
    51 
    52 function check_number()
    53 {
    54   [ -n "$1" -a -z "$(echo "$1" | tr -d '[0-9]')" ] || fail "Bad number: \"$1\""
    55 }
    56 
    57 
    58 ## process command line
    59 
    60 ALL_SESSIONS=false
    61 BUILD_HEAP=false
    62 CLEAN_BUILD=false
    63 declare -a MORE_DIRS=()
    64 declare -a SESSION_GROUPS=()
    65 MAX_JOBS=1
    66 NO_BUILD=false
    67 eval "declare -a BUILD_OPTIONS=($ISABELLE_BUILD_OPTIONS)"
    68 SYSTEM_MODE=false
    69 VERBOSE=false
    70 
    71 while getopts "abcd:g:j:no:sv" OPT
    72 do
    73   case "$OPT" in
    74     a)
    75       ALL_SESSIONS="true"
    76       ;;
    77     b)
    78       BUILD_HEAP="true"
    79       ;;
    80     c)
    81       CLEAN_BUILD="true"
    82       ;;
    83     d)
    84       MORE_DIRS["${#MORE_DIRS[@]}"]="$OPTARG"
    85       ;;
    86     g)
    87       SESSION_GROUPS["${#SESSION_GROUPS[@]}"]="$OPTARG"
    88       ;;
    89     j)
    90       check_number "$OPTARG"
    91       MAX_JOBS="$OPTARG"
    92       ;;
    93     n)
    94       NO_BUILD="true"
    95       ;;
    96     o)
    97       BUILD_OPTIONS["${#BUILD_OPTIONS[@]}"]="$OPTARG"
    98       ;;
    99     s)
   100       SYSTEM_MODE="true"
   101       ;;
   102     v)
   103       VERBOSE="true"
   104       ;;
   105     \?)
   106       usage
   107       ;;
   108   esac
   109 done
   110 
   111 shift $(($OPTIND - 1))
   112 
   113 
   114 ## main
   115 
   116 [ -e "$ISABELLE_HOME/Admin/build" ] && { "$ISABELLE_HOME/Admin/build" jars || exit $?; }
   117 
   118 if [ "$NO_BUILD" = false -a "$VERBOSE" = true ]; then
   119   echo "Started at $(date) ($ML_IDENTIFIER on $(hostname))"
   120 
   121   show_settings ""
   122   echo
   123   . "$ISABELLE_HOME/lib/scripts/timestart.bash"
   124 fi
   125 
   126 "$ISABELLE_TOOL" java isabelle.Build \
   127   "$ALL_SESSIONS" "$BUILD_HEAP" "$CLEAN_BUILD" "$MAX_JOBS" \
   128   "$NO_BUILD" "$SYSTEM_MODE" "$VERBOSE" \
   129   "${MORE_DIRS[@]}" $'\n' "${SESSION_GROUPS[@]}" $'\n' "${BUILD_OPTIONS[@]}" $'\n' "$@"
   130 RC="$?"
   131 
   132 if [ "$NO_BUILD" = false -a "$VERBOSE" = true ]; then
   133   echo -n "Finished at "; date
   134 
   135   . "$ISABELLE_HOME/lib/scripts/timestop.bash"
   136   echo "$TIMES_REPORT"
   137 fi
   138 
   139 exit "$RC"