From 02a1424519ceedff6dca8ef7f036c93c6b8fac7f Mon Sep 17 00:00:00 2001 From: Robert Soeldner Date: Thu, 16 Nov 2017 21:16:56 +0100 Subject: [PATCH 1/2] Add custom classpath, #3477 --- dist/bin/dotr | 53 +++++++++++++++++++++++----- project/scripts/sbtBootstrappedTests | 26 +++++++------- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/dist/bin/dotr b/dist/bin/dotr index c2563808e67b..861e6b8af304 100755 --- a/dist/bin/dotr +++ b/dist/bin/dotr @@ -1,5 +1,6 @@ #!/usr/bin/env bash +IFS="" # Try to autodetect real location of the script if [ -z "$PROG_HOME" ] ; then @@ -31,18 +32,52 @@ source "$PROG_HOME/bin/common" CLASS_PATH=".$PSEP$DOTTY_LIB$PSEP$SCALA_LIB" -# -d must be the first option -case "$1" in - -d) DEBUG="$DEBUG_STR" && shift ;; -esac +addResidual () { + residual_args+=("$1") +} -first_arg="$1" +addCustomClassPath () { + classpath_args+=("$1:") +} -if [ -z "$1" ]; then +run_repl=false + +while [[ $# -gt 0 ]]; do +key=$1 +case $key in + -repl) + run_repl=true + shift + ;; + -classpath) + addCustomClassPath "$2" + shift + shift + ;; + -d) + DEBUG="$DEBUG_STR" + shift + ;; + *) + addResidual "$1" + shift + ;; + + esac +done + +if [ $run_repl == true ]; then + echo "Starting dotty REPL" + if [ -z $classpath_args ]; then + classpath_args="" + else + classpath_args="-classpath \"${classpath_args[*]}\"" + fi + eval "$PROG_HOME/bin/dotc $classpath_args -repl ${residual_args[@]}" +elif [ -z $residual_args ]; then echo "Starting dotty REPL..." eval "$PROG_HOME/bin/dotc -repl" -elif [[ ${first_arg:0:1} == "-" ]]; then - eval "$PROG_HOME/bin/dotc -repl $@" else - eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$CLASS_PATH\"" $@ + CLASS_PATH="${classpath_args[*]}$CLASS_PATH" + eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$CLASS_PATH\"" "${residual_args[@]}" fi diff --git a/project/scripts/sbtBootstrappedTests b/project/scripts/sbtBootstrappedTests index 9704a0bd1a83..1e6f20e7ec94 100755 --- a/project/scripts/sbtBootstrappedTests +++ b/project/scripts/sbtBootstrappedTests @@ -11,13 +11,14 @@ echo "testing sbt dotc and dotr" mkdir out/scriptedtest0 ./bin/dotc tests/pos/sbtDotrTest.scala -d out/scriptedtest0 + # FIXME #3477 -#./bin/dotr -classpath out/scriptedtest0 dotrtest.Test" > sbtdotr1.out -#if grep -e "dotr test ok" sbtdotr1.out; then -# echo "output ok" -#else -# exit -1 -#fi +./bin/dotr -classpath out/scriptedtest0 dotrtest.Test" > sbtdotr1.out +if grep -e "dotr test ok" sbtdotr1.out; then + echo "output ok" +else + exit -1 +fi # check that `dotc` compiles and `dotr` runs it @@ -26,10 +27,9 @@ mkdir out/scriptedtest1 mkdir out/scriptedtest2 ./bin/dotc tests/pos/sbtDotrTest.scala -d out/scriptedtest1/ ./bin/dotc -from-tasty -classpath out/scriptedtest1/ -d out/scriptedtest2/ dotrtest.Test -# FIXME #3477 -#./bin/dotr -classpath out/scriptedtest2/ dotrtest.Test" > sbtdotr2.out -#if grep -e "dotr test ok" sbtdotr2.out; then -# echo "output ok" -#else -# exit -1 -#fi +./bin/dotr -classpath out/scriptedtest2/ dotrtest.Test" > sbtdotr2.out +if grep -e "dotr test ok" sbtdotr2.out; then + echo "output ok" +else + exit -1 +fi From a477cd5e2d35045019804b28896325fab68a34d7 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Mon, 20 Nov 2017 20:02:31 +0100 Subject: [PATCH 2/2] Polish --- dist/bin/dotr | 76 ++++++++++++---------------- project/scripts/sbtBootstrappedTests | 2 - 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/dist/bin/dotr b/dist/bin/dotr index 861e6b8af304..568f201f38ad 100755 --- a/dist/bin/dotr +++ b/dist/bin/dotr @@ -1,6 +1,5 @@ #!/usr/bin/env bash -IFS="" # Try to autodetect real location of the script if [ -z "$PROG_HOME" ] ; then @@ -30,54 +29,45 @@ fi source "$PROG_HOME/bin/common" -CLASS_PATH=".$PSEP$DOTTY_LIB$PSEP$SCALA_LIB" - -addResidual () { - residual_args+=("$1") -} - -addCustomClassPath () { - classpath_args+=("$1:") -} - +declare -a residual_args run_repl=false +CLASS_PATH="" while [[ $# -gt 0 ]]; do -key=$1 -case $key in - -repl) - run_repl=true - shift - ;; - -classpath) - addCustomClassPath "$2" - shift - shift - ;; - -d) - DEBUG="$DEBUG_STR" - shift - ;; - *) - addResidual "$1" - shift - ;; + case "$1" in + -repl) + run_repl=true + shift + ;; + -classpath) + CLASS_PATH="$2" + shift + shift + ;; + -d) + DEBUG="$DEBUG_STR" + shift + ;; + *) + residual_args+=("$1") + shift + ;; esac done -if [ $run_repl == true ]; then - echo "Starting dotty REPL" - if [ -z $classpath_args ]; then - classpath_args="" - else - classpath_args="-classpath \"${classpath_args[*]}\"" - fi - eval "$PROG_HOME/bin/dotc $classpath_args -repl ${residual_args[@]}" -elif [ -z $residual_args ]; then - echo "Starting dotty REPL..." - eval "$PROG_HOME/bin/dotc -repl" +if [ $run_repl == true ] || [ ${#residual_args[@]} -eq 0 ]; then + if [ "$CLASS_PATH" ]; then + cp_arg="-classpath $CLASS_PATH" + fi + echo "Starting dotty REPL" + eval "$PROG_HOME/bin/dotc $cp_arg -repl ${residual_args[@]}" else - CLASS_PATH="${classpath_args[*]}$CLASS_PATH" - eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$CLASS_PATH\"" "${residual_args[@]}" + cp_arg="-classpath $DOTTY_LIB$PSEP$SCALA_LIB" + if [ -z "$CLASS_PATH" ]; then + cp_arg+="$PSEP." + else + cp_arg+="$PSEP$CLASS_PATH" + fi + eval exec "\"$JAVACMD\"" "$DEBUG" "$cp_arg" "${residual_args[@]}" fi diff --git a/project/scripts/sbtBootstrappedTests b/project/scripts/sbtBootstrappedTests index 1e6f20e7ec94..a306916fdf00 100755 --- a/project/scripts/sbtBootstrappedTests +++ b/project/scripts/sbtBootstrappedTests @@ -3,7 +3,6 @@ # check that benchmarks can run ./project/scripts/sbt "dotty-bench-bootstrapped/jmh:run 1 1 tests/pos/alias.scala" - # setup for `dotc`/`dotr` script tests ./project/scripts/sbt dist-bootstrapped/pack @@ -12,7 +11,6 @@ echo "testing sbt dotc and dotr" mkdir out/scriptedtest0 ./bin/dotc tests/pos/sbtDotrTest.scala -d out/scriptedtest0 -# FIXME #3477 ./bin/dotr -classpath out/scriptedtest0 dotrtest.Test" > sbtdotr1.out if grep -e "dotr test ok" sbtdotr1.out; then echo "output ok"