lib/Tools/build
author wenzelm
Thu Aug 23 13:26:27 2012 +0200 (2012-08-23)
changeset 48903 1621b3f26095
parent 48780 49a965020394
child 49131 aa1e2ba3c697
permissions -rwxr-xr-x
added build option -l (list files);
     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 "    -D DIR       include session directory and select its sessions"
    30   echo "    -a           select all sessions"
    31   echo "    -b           build heap images"
    32   echo "    -c           clean build"
    33   echo "    -d DIR       include session directory"
    34   echo "    -g NAME      select session group NAME"
    35   echo "    -j INT       maximum number of parallel jobs (default 1)"
    36   echo "    -l           list session source files"
    37   echo "    -n           no build -- test dependencies only"
    38   echo "    -o OPTION    override session configuration OPTION (via NAME=VAL or NAME)"
    39   echo "    -s           system build mode: produce output in ISABELLE_HOME"
    40   echo "    -v           verbose"
    41   echo
    42   echo "  Build and manage Isabelle sessions, depending on implicit"
    43   show_settings "  "
    44   echo
    45   exit 1
    46 }
    47 
    48 function fail()
    49 {
    50   echo "$1" >&2
    51   exit 2
    52 }
    53 
    54 function check_number()
    55 {
    56   [ -n "$1" -a -z "$(echo "$1" | tr -d '[0-9]')" ] || fail "Bad number: \"$1\""
    57 }
    58 
    59 
    60 ## process command line
    61 
    62 declare -a SELECT_DIRS=()
    63 ALL_SESSIONS=false
    64 BUILD_HEAP=false
    65 CLEAN_BUILD=false
    66 declare -a INCLUDE_DIRS=()
    67 declare -a SESSION_GROUPS=()
    68 MAX_JOBS=1
    69 LIST_FILES=false
    70 NO_BUILD=false
    71 eval "declare -a BUILD_OPTIONS=($ISABELLE_BUILD_OPTIONS)"
    72 SYSTEM_MODE=false
    73 VERBOSE=false
    74 
    75 while getopts "D:abcd:g:j:lno:sv" OPT
    76 do
    77   case "$OPT" in
    78     D)
    79       SELECT_DIRS["${#SELECT_DIRS[@]}"]="$OPTARG"
    80       ;;
    81     a)
    82       ALL_SESSIONS="true"
    83       ;;
    84     b)
    85       BUILD_HEAP="true"
    86       ;;
    87     c)
    88       CLEAN_BUILD="true"
    89       ;;
    90     d)
    91       INCLUDE_DIRS["${#INCLUDE_DIRS[@]}"]="$OPTARG"
    92       ;;
    93     g)
    94       SESSION_GROUPS["${#SESSION_GROUPS[@]}"]="$OPTARG"
    95       ;;
    96     j)
    97       check_number "$OPTARG"
    98       MAX_JOBS="$OPTARG"
    99       ;;
   100     l)
   101       LIST_FILES="true"
   102       ;;
   103     n)
   104       NO_BUILD="true"
   105       ;;
   106     o)
   107       BUILD_OPTIONS["${#BUILD_OPTIONS[@]}"]="$OPTARG"
   108       ;;
   109     s)
   110       SYSTEM_MODE="true"
   111       ;;
   112     v)
   113       VERBOSE="true"
   114       ;;
   115     \?)
   116       usage
   117       ;;
   118   esac
   119 done
   120 
   121 shift $(($OPTIND - 1))
   122 
   123 
   124 ## main
   125 
   126 [ -e "$ISABELLE_HOME/Admin/build" ] && { "$ISABELLE_HOME/Admin/build" jars || exit $?; }
   127 
   128 if [ "$NO_BUILD" = false -a "$VERBOSE" = true ]; then
   129   echo "Started at $(date) ($ML_IDENTIFIER on $(hostname))"
   130 
   131   show_settings ""
   132   echo
   133 fi
   134 
   135 . "$ISABELLE_HOME/lib/scripts/timestart.bash"
   136 
   137 "$ISABELLE_TOOL" java isabelle.Build \
   138   "$ALL_SESSIONS" "$BUILD_HEAP" "$CLEAN_BUILD" "$MAX_JOBS" \
   139   "$LIST_FILES" "$NO_BUILD" "$SYSTEM_MODE" "$VERBOSE" \
   140   "${SELECT_DIRS[@]}" $'\n' "${INCLUDE_DIRS[@]}" $'\n' \
   141   "${SESSION_GROUPS[@]}" $'\n' "${BUILD_OPTIONS[@]}" $'\n' "$@"
   142 RC="$?"
   143 
   144 if [ "$NO_BUILD" = false -a "$VERBOSE" = true ]; then
   145   echo -n "Finished at "; date
   146 
   147 fi
   148 
   149 . "$ISABELLE_HOME/lib/scripts/timestop.bash"
   150 echo "$TIMES_REPORT"
   151 
   152 exit "$RC"