src/Pure/build-jars
author wenzelm
Sun, 22 Jul 2012 12:26:41 +0200
changeset 48423 0ccf143a2a69
parent 48411 5b3440850d36
child 49065 8ead9e8b15fb
permissions -rwxr-xr-x
maintain set of source digests, including relevant parts of session entry;

#!/usr/bin/env bash
#
# Author: Makarius
#
# build-jars - build Isabelle/Scala
#
# Requires proper Isabelle settings environment.

## sources

declare -a SOURCES=(
  Concurrent/counter.scala
  Concurrent/future.scala
  Concurrent/simple_thread.scala
  Concurrent/volatile.scala
  General/exn.scala
  General/file.scala
  General/graph.scala
  General/linear_set.scala
  General/path.scala
  General/position.scala
  General/pretty.scala
  General/properties.scala
  General/scan.scala
  General/sha1.scala
  General/symbol.scala
  General/time.scala
  General/timing.scala
  Isar/keyword.scala
  Isar/outer_syntax.scala
  Isar/parse.scala
  Isar/token.scala
  PIDE/blob.scala
  PIDE/command.scala
  PIDE/document.scala
  PIDE/isabelle_markup.scala
  PIDE/markup.scala
  PIDE/markup_tree.scala
  PIDE/protocol.scala
  PIDE/text.scala
  PIDE/xml.scala
  PIDE/yxml.scala
  System/build.scala
  System/command_line.scala
  System/event_bus.scala
  System/gui_setup.scala
  System/invoke_scala.scala
  System/isabelle_charset.scala
  System/isabelle_process.scala
  System/isabelle_system.scala
  System/main.scala
  System/options.scala
  System/platform.scala
  System/session.scala
  System/standard_system.scala
  System/swing_thread.scala
  System/system_channel.scala
  Thy/completion.scala
  Thy/html.scala
  Thy/thy_header.scala
  Thy/thy_info.scala
  Thy/thy_load.scala
  Thy/thy_syntax.scala
  library.scala
  package.scala
  term.scala
  term_xml.scala
)


## diagnostics

PRG="$(basename "$0")"

function usage()
{
  echo
  echo "Usage: isabelle $PRG [OPTIONS]"
  echo
  echo "  Options are:"
  echo "    -f           fresh build"
  echo "    -t           test separate compilation of PIDE"
  echo
  exit 1
}

function fail()
{
  echo "$1" >&2
  exit 2
}

[ -z "$ISABELLE_HOME" ] && fail "Missing Isabelle settings environment"


## process command line

# options

FRESH=""
TEST_PIDE=""

while getopts "ft" OPT
do
  case "$OPT" in
    f)
      FRESH=true
      ;;
    t)
      TEST_PIDE=true
      ;;
    \?)
      usage
      ;;
  esac
done

shift $(($OPTIND - 1))


# args

[ "$#" -ne 0 ] && usage



# build

TARGET_DIR="$ISABELLE_HOME/lib/classes"
TARGET="$TARGET_DIR/ext/Pure.jar"

declare -a PIDE_SOURCES=()
declare -a PURE_SOURCES=()

for DEP in "${SOURCES[@]}"
do
  if grep "Module:.*PIDE" "$DEP" >/dev/null
  then
    PIDE_SOURCES["${#PIDE_SOURCES[@]}"]="$DEP"
  else
    PURE_SOURCES["${#PURE_SOURCES[@]}"]="$DEP"
  fi
done

declare -a UPDATED=()

if [ -n "$FRESH" ]; then
  OUTDATED=true
else
  OUTDATED=false
  if [ ! -e "$TARGET" ]; then
    OUTDATED=true
  else
    for DEP in "${SOURCES[@]}"
    do
      [ ! -e "$DEP" ] && fail "Missing file: $DEP"
      [ "$DEP" -nt "$TARGET" ] && {
        OUTDATED=true
        UPDATED["${#UPDATED[@]}"]="$DEP"
      }
    done
  fi
fi

if [ "$OUTDATED" = true ]
then
  echo "### Building Isabelle/Scala layer ..."

  [ "${#UPDATED[@]}" -gt 0 ] && {
    echo "Changed files:"
    for FILE in "${UPDATED[@]}"
    do
      echo "  $FILE"
    done
  }

  rm -rf classes && mkdir classes

  SCALAC_OPTIONS="$ISABELLE_SCALA_BUILD_OPTIONS -d classes"

  if [ "$TEST_PIDE" = true ]; then
    isabelle_scala scalac $SCALAC_OPTIONS "${PIDE_SOURCES[@]}" || \
      fail "Failed to compile PIDE sources"
    isabelle_scala scalac $SCALAC_OPTIONS -classpath classes "${PURE_SOURCES[@]}" || \
      fail "Failed to compile Pure sources"
  else
    isabelle_scala scalac $SCALAC_OPTIONS -classpath classes \
      "${PIDE_SOURCES[@]}" "${PURE_SOURCES[@]}" || \
      fail "Failed to compile sources"
  fi

  mkdir -p "$TARGET_DIR/ext" || fail "Failed to create directory $TARGET_DIR/ext"

  pushd classes >/dev/null

  CHARSET_SERVICE="META-INF/services/java.nio.charset.spi.CharsetProvider"
  mkdir -p "$(dirname "$CHARSET_SERVICE")"
  echo isabelle.Isabelle_Charset_Provider > "$CHARSET_SERVICE"

  isabelle_jdk jar cfe "$(jvmpath "$TARGET")" isabelle.GUI_Setup META-INF isabelle || \
    fail "Failed to produce $TARGET"

  cp "$SCALA_HOME/lib/scala-compiler.jar" \
    "$SCALA_HOME/lib/scala-library.jar" \
    "$SCALA_HOME/lib/scala-swing.jar" "$TARGET_DIR/ext"

  [ -e "$SCALA_HOME/lib/scala-actors.jar" ] && \
    cp "$SCALA_HOME/lib/scala-actors.jar" "$TARGET_DIR/ext"

  popd >/dev/null

  rm -rf classes
fi