CLI: get rid of duplication in JVM/JS scripts

This commit is contained in:
Alexander Udalov
2015-06-14 00:46:48 +03:00
parent 5ec4576844
commit cdd53de9a7
6 changed files with 185 additions and 276 deletions
+84 -14
View File
@@ -1,17 +1,87 @@
#!/bin/bash --posix
#
##############################################################################
# Copyright 2002-2011, LAMP/EPFL
# Copyright 2011-2015, JetBrains
#
# This is free software; see the distribution for copying conditions.
# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
##############################################################################
# Copyright 2010-2015 JetBrains s.r.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[ -n "$KOTLIN_COMPILER" ] || KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
"$(dirname "$(which "$0")")"/kotlinc-jvm "$@"
cygwin=false;
case "`uname`" in
CYGWIN*) cygwin=true ;;
esac
# Finding the root folder for this Kotlin distribution
SOURCE=$0;
SCRIPT=`basename "$SOURCE"`;
while [ -h "$SOURCE" ]; do
SCRIPT=`basename "$SOURCE"`;
LOOKUP=`ls -ld "$SOURCE"`;
TARGET=`expr "$LOOKUP" : '.*-> \(.*\)$'`;
if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then
SOURCE=${TARGET:-.};
else
SOURCE=`dirname "$SOURCE"`/${TARGET:-.};
fi;
done;
# see #2092
KOTLIN_HOME=`dirname "$SOURCE"`
KOTLIN_HOME=`cd "$KOTLIN_HOME"; pwd -P`
KOTLIN_HOME=`cd "$KOTLIN_HOME"/..; pwd`
if $cygwin; then
# Remove spaces from KOTLIN_HOME on windows
KOTLIN_HOME=`cygpath --windows --short-name "$KOTLIN_HOME"`
fi
[ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx256M -Xms32M -noverify"
# break out -D and -J options and add them to JAVA_OPTS as well
# so they reach the underlying JVM in time to do some good. The
# -D options will be available as system properties.
declare -a java_args
declare -a kotlin_args
while [ $# -gt 0 ]; do
case "$1" in
-D*)
# pass to kotlin as well: otherwise we lose it sometimes when we
# need it, e.g. communicating with a server compiler.
java_args=("${java_args[@]}" "$1")
kotlin_args=("${kotlin_args[@]}" "$1")
shift
;;
-J*)
# as with -D, pass to kotlin even though it will almost
# never be used.
java_args=("${java_args[@]}" "${1:2}")
kotlin_args=("${kotlin_args[@]}" "$1")
shift
;;
*)
kotlin_args=("${kotlin_args[@]}" "$1")
shift
;;
esac
done
# reset "$@" to the remaining args
set -- "${kotlin_args[@]}"
if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
JAVACMD="$JAVA_HOME/bin/java"
fi
"${JAVACMD:=java}" \
$JAVA_OPTS \
"${java_args[@]}" \
-cp "${KOTLIN_HOME}/lib/kotlin-preloader.jar" \
org.jetbrains.kotlin.preloading.Preloader \
"${KOTLIN_HOME}/lib/kotlin-compiler.jar" \
$KOTLIN_COMPILER 4096 notime "$@"