Skip to content

Commit

Permalink
try to infer KOTLIN_HOME from context if missing (fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerbrandl committed Apr 18, 2017
1 parent 15c7cc4 commit 01d6b36
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
13 changes: 13 additions & 0 deletions kscript
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@ fi
#jar ufm ${jarFile} ${mainJava}.manimain
#jar tf ${jarFile}


# Infer KOTLIN_HOME from kotlinc if not set
if [ -z "$KOTLIN_HOME" ]; then
KOTLIN_HOME="$(dirname $(which kotlinc))/.."
fi

## fail if KOTLIN_HOME is still unknown or does not exist
if [ ! -d "$KOTLIN_HOME" ]; then
echo "ERROR: KOTLIN_HOME is not set and could not be inferred from context" >&2
exit 1;
fi


# http://stackoverflow.com/questions/3706689/java-class-files-in-current-directory
# also see https://youtrack.jetbrains.com/issue/KT-17100
exec kotlin ${kotlin_opts} -classpath ${jarFile}:${KOTLIN_HOME}/lib/kotlin-script-runtime.jar:"$classpath" Main_${className} "$@"
8 changes: 4 additions & 4 deletions test/TestsReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ To run the tests, just run the [`test_suite.sh`](test_suite.sh)
export KSCRIPT_HOME="/Users/brandl/projects/kotlin/kscript"
## change into this/test directory

cd ${KSCRIPT_HOME}

## make sure to use devel-version
export PATH=${KSCRIPT_HOME}:${PATH}

cd ${KSCRIPT_HOME}/test

## clean up the environment
sdk use kotlin 1.1-RC
#sdk use kotlin 1.1-RC
kscript --clear-cache

./test_suite.sh

# run again with kotlin 1.0.X
sdk use kotlin 1.0.6
#sdk use kotlin 1.0.6
./test_suite.sh


Expand Down
7 changes: 7 additions & 0 deletions test/test_suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ assert "kscript -i " "To create a shell with script dependencies run:\nkotlinc


assert_end cli_helper_tests



assert "unset KOTLIN_HOME; echo 'println(99)' | kscript -" "99"


assert_end environment_tests

0 comments on commit 01d6b36

Please sign in to comment.