Files
kotlin-fork/cmd/konanc
T
Ilya Matveev fbc14becfc tools: Add dependecy download helpers
This patch adds 2 helpers to download dependencies for compiler and
stub generator during their execution.

They take list of external dependencies as a parameter and directory
where they must be located. Helpers check if these dependencies exist
in the given directory and download not existing ones.
2017-03-24 19:31:23 +07:00

69 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
JAVACMD="$JAVA_HOME/bin/java"
else
JAVACMD=java
fi
[ -n "$JAVACMD" ] || JAVACMD=java
declare -a java_args
declare -a konan_args
while [ $# -gt 0 ]; do
case "$1" in
-D*)
java_args=("${java_args[@]}" "$1")
shift
;;
-J*)
java_args=("${java_args[@]}" "${1:2}")
shift
;;
-X*)
echo "TODO: need to pass arguments to all the tools somehow."
shift
;;
-time)
konan_args=("${konan_args[@]}" -time)
java_args=("${java_args[@]}" -agentlib:hprof=cpu=samples -Dkonan.profile=true)
JAVACMD="time $JAVACMD"
shift
;;
*)
konan_args[${#konan_args[@]}]=$1
shift
;;
esac
done
findHome() {
local source="${BASH_SOURCE[0]}"
while [ -h "$source" ] ; do
local linked="$(readlink "$source")"
local dir="$(cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd)"
source="$dir/$(basename "$linked")"
done
(cd -P "$(dirname "$source")/.." && pwd)
}
KONAN_HOME="$(findHome)"
KONAN_JAR="${KONAN_HOME}/konan/lib/backend.native.jar"
KOTLIN_JAR="${KONAN_HOME}/konan/lib/kotlin-compiler.jar"
INTEROP_JAR="${KONAN_HOME}/konan/lib/Runtime.jar"
HELPERS_JAR="${KONAN_HOME}/konan/lib/helpers.jar"
NATIVE_LIB="${KONAN_HOME}/konan/nativelib"
KONAN_CLASSPATH="$KOTLIN_JAR:$INTEROP_JAR:$KONAN_JAR:$HELPERS_JAR"
KONAN_COMPILER=org.jetbrains.kotlin.cli.bc.K2NativeKt
JAVA_OPTS=-ea
#
# KONAN BACKEND INVOCATION
#
java_args=("${java_args[@]} -noverify -Dkonan.home=${KONAN_HOME} -Djava.library.path=${NATIVE_LIB}")
$JAVACMD $JAVA_OPTS ${java_args[@]} -cp $KONAN_CLASSPATH $KONAN_COMPILER "${konan_args[@]}"