aboutsummaryrefslogtreecommitdiff
path: root/bin/dotr
blob: e5a632565cf7c726e2090a5e0526b744b5080786 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash

# Try to autodetect real location of the script
DOTTY_ROOT="$(readlink "$0")"              #  relative, symbolic links resolved
if [[ "$DOTTY_ROOT" == "" ]]; then
  DOTTY_ROOT="$0"
fi
DOTTY_ROOT="$(dirname "$DOTTY_ROOT")"
DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.."  # absolute

# debug
DEBUG_STR=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
DEBUG=

# Load common functions and variables
source "$DOTTY_ROOT"/bin/common

CLASS_PATH="-classpath .:$DOTTY_LIB_JAR:.:$SCALA_LIBRARY_JAR"

function runMain {
    local jbin=$(which "java")

    if [ ! -z "$JAVA_BIN" ]; then
        jbin="$JAVA_BIN"
    fi

    if [ "$jbin" == "" ]; then
        echo "java bin not detected - please specify with \$JAVA_BIN or install java to a default location"
        exit 1
    else
        eval "$jbin $DEBUG $CLASS_PATH $@"
    fi
}

# parse command line params -d to enable debugging
while getopts "dx" opt; do
 case "$opt" in
    d)
      DEBUG="$DEBUG_STR"
      ;;
  esac
done

shift $((OPTIND-1))

first_arg="$1"

if [ -z "$1" ]; then
    echo "Starting dotty REPL..."
    eval "$DOTTY_ROOT/bin/dotc -repl"
elif [[ ${first_arg:0:1} == "-" ]]; then
    eval "$DOTTY_ROOT/bin/dotc -repl $@"
else
    runMain "$@"
fi