summaryrefslogtreecommitdiff
path: root/bin/kotlinc
diff options
context:
space:
mode:
Diffstat (limited to 'bin/kotlinc')
-rwxr-xr-xbin/kotlinc44
1 files changed, 31 insertions, 13 deletions
diff --git a/bin/kotlinc b/bin/kotlinc
index 7f45ac9..c200606 100755
--- a/bin/kotlinc
+++ b/bin/kotlinc
@@ -1,13 +1,9 @@
#!/usr/bin/env bash
-#
-##############################################################################
+
+# Based on scalac from the Scala distribution
# 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-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
+# Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
cygwin=false;
case "`uname`" in
@@ -25,6 +21,17 @@ findKotlinHome() {
(cd -P "$(dirname "$source")/.." && pwd)
}
+findJavaVersion() {
+ # Note that this only loads the first component of the version, so "1.8.0_265" -> "1".
+ # But it's fine because major version is 9 for JDK 9, and so on.
+ regex='^.*version "([[:digit:]]+).*$'
+ while read -r line; do
+ if [[ "$line" =~ $regex ]]; then
+ echo ${BASH_REMATCH[1]}
+ fi
+ done <<< $("${JAVACMD:=java}" -version 2>&1)
+}
+
KOTLIN_HOME="$(findKotlinHome)"
if $cygwin; then
@@ -45,6 +52,10 @@ while [ $# -gt 0 ]; do
;;
-J*)
java_args=("${java_args[@]}" "${1:2}")
+ if [ "x${1:2}" = "x" ]; then
+ echo "error: empty -J argument"
+ exit 1
+ fi
shift
;;
*)
@@ -60,17 +71,24 @@ fi
declare -a kotlin_app
-if [ -n "$KOTLIN_RUNNER" ];
-then
+java_version="$(findJavaVersion)"
+if [[ $java_version -ge 9 ]]; then
+ # Workaround the illegal reflective access warning from ReflectionUtil to ResourceBundle.setParent, see IDEA-248785.
+ java_args=("${java_args[@]}" "--add-opens" "java.base/java.util=ALL-UNNAMED")
+fi
+
+if [ -n "$KOTLIN_RUNNER" ]; then
java_args=("${java_args[@]}" "-Dkotlin.home=${KOTLIN_HOME}")
kotlin_app=("${KOTLIN_HOME}/lib/kotlin-runner.jar" "org.jetbrains.kotlin.runner.Main")
else
[ -n "$KOTLIN_COMPILER" ] || KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
- java_args=("${java_args[@]}" "-noverify")
+
+ if [[ $java_version < 13 ]]; then
+ java_args=("${java_args[@]}" "-noverify")
+ fi
declare additional_classpath=""
- if [ -n "$KOTLIN_TOOL" ];
- then
+ if [ -n "$KOTLIN_TOOL" ]; then
additional_classpath=":${KOTLIN_HOME}/lib/${KOTLIN_TOOL}"
fi