src/Pure/build-jars
author wenzelm
Mon Apr 09 20:57:23 2012 +0200 (2012-04-09)
changeset 47408 63c05991882e
parent 47115 1a05adae1cc9
child 47663 20e0865ae9e7
permissions -rwxr-xr-x
slightly faster default compilation of Isabelle/Scala;
     1 #!/usr/bin/env bash
     2 #
     3 # Author: Makarius
     4 #
     5 # build-jars - build Isabelle/Scala
     6 #
     7 # Requires proper Isabelle settings environment.
     8 
     9 ## sources
    10 
    11 declare -a SOURCES=(
    12   Concurrent/counter.scala
    13   Concurrent/future.scala
    14   Concurrent/simple_thread.scala
    15   Concurrent/volatile.scala
    16   General/exn.scala
    17   General/graph.scala
    18   General/linear_set.scala
    19   General/path.scala
    20   General/position.scala
    21   General/pretty.scala
    22   General/properties.scala
    23   General/scan.scala
    24   General/sha1.scala
    25   General/symbol.scala
    26   General/time.scala
    27   General/timing.scala
    28   Isar/keyword.scala
    29   Isar/outer_syntax.scala
    30   Isar/parse.scala
    31   Isar/token.scala
    32   PIDE/blob.scala
    33   PIDE/command.scala
    34   PIDE/document.scala
    35   PIDE/isabelle_markup.scala
    36   PIDE/markup.scala
    37   PIDE/markup_tree.scala
    38   PIDE/protocol.scala
    39   PIDE/text.scala
    40   PIDE/xml.scala
    41   PIDE/yxml.scala
    42   System/cygwin.scala
    43   System/download.scala
    44   System/event_bus.scala
    45   System/gui_setup.scala
    46   System/invoke_scala.scala
    47   System/isabelle_charset.scala
    48   System/isabelle_process.scala
    49   System/isabelle_system.scala
    50   System/platform.scala
    51   System/session.scala
    52   System/session_manager.scala
    53   System/standard_system.scala
    54   System/swing_thread.scala
    55   System/system_channel.scala
    56   Thy/completion.scala
    57   Thy/html.scala
    58   Thy/thy_header.scala
    59   Thy/thy_info.scala
    60   Thy/thy_load.scala
    61   Thy/thy_syntax.scala
    62   library.scala
    63   package.scala
    64   term.scala
    65   term_xml.scala
    66 )
    67 
    68 
    69 ## diagnostics
    70 
    71 PRG="$(basename "$0")"
    72 
    73 function usage()
    74 {
    75   echo
    76   echo "Usage: isabelle $PRG [OPTIONS]"
    77   echo
    78   echo "  Options are:"
    79   echo "    -f           fresh build"
    80   echo "    -t           test separate compilation of PIDE"
    81   echo
    82   exit 1
    83 }
    84 
    85 function fail()
    86 {
    87   echo "$1" >&2
    88   exit 2
    89 }
    90 
    91 [ -z "$ISABELLE_HOME" ] && fail "Missing Isabelle settings environment"
    92 
    93 
    94 ## process command line
    95 
    96 # options
    97 
    98 FRESH=""
    99 TEST_PIDE=""
   100 
   101 while getopts "ft" OPT
   102 do
   103   case "$OPT" in
   104     f)
   105       FRESH=true
   106       ;;
   107     t)
   108       TEST_PIDE=true
   109       ;;
   110     \?)
   111       usage
   112       ;;
   113   esac
   114 done
   115 
   116 shift $(($OPTIND - 1))
   117 
   118 
   119 # args
   120 
   121 [ "$#" -ne 0 ] && usage
   122 
   123 
   124 
   125 # build
   126 
   127 TARGET_DIR="$ISABELLE_HOME/lib/classes"
   128 TARGET="$TARGET_DIR/ext/Pure.jar"
   129 
   130 declare -a PIDE_SOURCES=()
   131 declare -a PURE_SOURCES=()
   132 
   133 for DEP in "${SOURCES[@]}"
   134 do
   135   if grep "Module:.*PIDE" "$DEP" >/dev/null
   136   then
   137     PIDE_SOURCES["${#PIDE_SOURCES[@]}"]="$DEP"
   138   else
   139     PURE_SOURCES["${#PURE_SOURCES[@]}"]="$DEP"
   140   fi
   141 done
   142 
   143 declare -a UPDATED=()
   144 
   145 if [ -n "$FRESH" ]; then
   146   OUTDATED=true
   147 else
   148   OUTDATED=false
   149   if [ ! -e "$TARGET" ]; then
   150     OUTDATED=true
   151   else
   152     for DEP in "${SOURCES[@]}"
   153     do
   154       [ ! -e "$DEP" ] && fail "Missing file: $DEP"
   155       [ "$DEP" -nt "$TARGET" ] && {
   156         OUTDATED=true
   157         UPDATED["${#UPDATED[@]}"]="$DEP"
   158       }
   159     done
   160   fi
   161 fi
   162 
   163 if [ "$OUTDATED" = true ]
   164 then
   165   echo "### Building Isabelle/Scala layer ..."
   166 
   167   [ "${#UPDATED[@]}" -gt 0 ] && {
   168     echo "Changed files:"
   169     for FILE in "${UPDATED[@]}"
   170     do
   171       echo "  $FILE"
   172     done
   173   }
   174 
   175   rm -rf classes && mkdir classes
   176 
   177   SCALAC_OPTIONS="$ISABELLE_SCALA_BUILD_OPTIONS -d classes"
   178 
   179   if [ "$TEST_PIDE" = true ]; then
   180     isabelle_scala scalac $SCALAC_OPTIONS "${PIDE_SOURCES[@]}" || \
   181       fail "Failed to compile PIDE sources"
   182     isabelle_scala scalac $SCALAC_OPTIONS -classpath classes "${PURE_SOURCES[@]}" || \
   183       fail "Failed to compile Pure sources"
   184   else
   185     isabelle_scala scalac $SCALAC_OPTIONS -classpath classes \
   186       "${PIDE_SOURCES[@]}" "${PURE_SOURCES[@]}" || \
   187       fail "Failed to compile sources"
   188   fi
   189 
   190   mkdir -p "$TARGET_DIR/ext" || fail "Failed to create directory $TARGET_DIR/ext"
   191 
   192   pushd classes >/dev/null
   193 
   194   CHARSET_SERVICE="META-INF/services/java.nio.charset.spi.CharsetProvider"
   195   mkdir -p "$(dirname "$CHARSET_SERVICE")"
   196   echo isabelle.Isabelle_Charset_Provider > "$CHARSET_SERVICE"
   197 
   198   isabelle_jdk jar cfe "$(jvmpath "$TARGET")" isabelle.GUI_Setup META-INF isabelle || \
   199     fail "Failed to produce $TARGET"
   200 
   201   cp "$SCALA_HOME/lib/scala-swing.jar" "$SCALA_HOME/lib/scala-library.jar" "$TARGET_DIR/ext"
   202 
   203   popd >/dev/null
   204 
   205   rm -rf classes
   206 fi