From 9637c049fed7533f19662f88c773771c6b2931a9 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Sun, 14 Jun 2015 14:31:26 +0300 Subject: [PATCH] CLI: update KOTLIN_HOME lookup process in Bash script The original code was taken from the 'scalac' script, where it has evolved since and now is a lot easier to understand --- compiler/cli/bin/kotlinc | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/compiler/cli/bin/kotlinc b/compiler/cli/bin/kotlinc index a8e27327636..fcc15150836 100755 --- a/compiler/cli/bin/kotlinc +++ b/compiler/cli/bin/kotlinc @@ -16,24 +16,18 @@ 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; +# Based on findScalaHome() from scalac script +findKotlinHome() { + 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) +} -# see #2092 -KOTLIN_HOME=`dirname "$SOURCE"` -KOTLIN_HOME=`cd "$KOTLIN_HOME"; pwd -P` -KOTLIN_HOME=`cd "$KOTLIN_HOME"/..; pwd` +KOTLIN_HOME="$(findKotlinHome)" if $cygwin; then # Remove spaces from KOTLIN_HOME on windows