From b7558e11b91e6f00c0227852e92627af6d4c99e9 Mon Sep 17 00:00:00 2001 From: Henri Cook Date: Mon, 25 May 2020 18:57:53 +0100 Subject: [PATCH 1/3] Support debug flags in SBT_OPTs --- src/universal/bin/sbt | 50 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index 23d309e21..17ae8f426 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -133,7 +133,7 @@ addJava () { java_args=( "${java_args[@]}" "$1" ) } addSbt () { - dlog "[addSbt] arg = '$1'" + echoerr "[addSbt] arg = '$1'" sbt_commands=( "${sbt_commands[@]}" "$1" ) } addResidual () { @@ -350,14 +350,21 @@ copyRt() { } run() { - local retarr=() java_args=($JAVA_OPTS) sbt_options0=(${SBT_OPTS:-$default_sbt_opts}) - miniscript=$(map_args "${sbt_options0[@]}") && eval "${miniscript/retarr/sbt_options}" - miniscript=$(map_args "$@") && eval "${miniscript/retarr/args1}" + + # Split SBT_OPTs into options/commands + miniscript=$(map_args "${sbt_options0[@]}") && eval "${miniscript/options/sbt_options}" && \ + eval "${miniscript/commands/sbt_additional_commands}" + + # Combine command line options/commands and commands from SBT_OPTs + miniscript=$(map_args "$@") && eval "${miniscript/options/cli_options}" && eval "${miniscript/commands/cli_commands}" + args1=( "${cli_options[@]}" "${cli_commands[@]}" "${sbt_additional_commands[@]}" ) + # process the combined args, then reset "$@" to the residuals process_args "${args1[@]}" vlog "[sbt_options] $(declare -p sbt_options)" + addDefaultMemory set -- "${residual_args[@]}" argumentCount=$# @@ -378,7 +385,7 @@ run() { # Java 9 support copyRt - #If we're in cygwin, we should use the windows config, and terminal hacks + # If we're in cygwin, we should use the windows config, and terminal hacks if [[ "$CYGWIN_FLAG" == "true" ]]; then #" stty -icanon min 1 -echo > /dev/null 2>&1 addJava "-Djline.terminal=jline.UnixTerminal" @@ -509,25 +516,28 @@ process_my_args () { ## map over argument array. this is used to process both command line arguments and SBT_OPTS map_args () { - local retarr=() + local options=() + local commands=() while [[ $# -gt 0 ]]; do case "$1" in - -no-colors|--no-colors) retarr=( "${retarr[@]}" "-Dsbt.log.noformat=true" ) && shift ;; - -timings|--timings) retarr=( "${retarr[@]}" "-Dsbt.task.timings=true" "-Dsbt.task.timings.on.shutdown=true" ) && shift ;; - -traces|--traces) retarr=( "${retarr[@]}" "-Dsbt.traces=true" ) && shift ;; - --supershell=*) retarr=( "${retarr[@]}" "-Dsbt.supershell=${1:13}" ) && shift ;; - -supershell=*) retarr=( "${retarr[@]}" "-Dsbt.supershell=${1:12}" ) && shift ;; - --color=*) retarr=( "${retarr[@]}" "-Dsbt.color=${1:8}" ) && shift ;; - -color=*) retarr=( "${retarr[@]}" "-Dsbt.color=${1:7}" ) && shift ;; - -no-share|--no-share) retarr=( "${retarr[@]}" "$noshare_opts" ) && shift ;; - -no-global|--no-global) retarr=( "${retarr[@]}" "-Dsbt.global.base=$(pwd)/project/.sbtboot" ) && shift ;; - -sbt-boot|--sbt-boot) require_arg path "$1" "$2" && retarr=( "${retarr[@]}" "-Dsbt.boot.directory=$2" ) && shift 2 ;; - -sbt-dir|--sbt-dir) require_arg path "$1" "$2" && retarr=( "${retarr[@]}" "-Dsbt.global.base=$2" ) && shift 2 ;; - -debug-inc|--debug-inc) retarr=( "${retarr[@]}" "-Dxsbt.inc.debug=true" ) && shift ;; - *) retarr=( "${retarr[@]}" "$1" ) && shift ;; + -no-colors|--no-colors) options=( "${options[@]}" "-Dsbt.log.noformat=true" ) && shift ;; + -timings|--timings) options=( "${options[@]}" "-Dsbt.task.timings=true" "-Dsbt.task.timings.on.shutdown=true" ) && shift ;; + -traces|--traces) options=( "${options[@]}" "-Dsbt.traces=true" ) && shift ;; + --supershell=*) options=( "${options[@]}" "-Dsbt.supershell=${1:13}" ) && shift ;; + -supershell=*) options=( "${options[@]}" "-Dsbt.supershell=${1:12}" ) && shift ;; + --color=*) options=( "${options[@]}" "-Dsbt.color=${1:8}" ) && shift ;; + -color=*) options=( "${options[@]}" "-Dsbt.color=${1:7}" ) && shift ;; + -no-share|--no-share) options=( "${options[@]}" "$noshare_opts" ) && shift ;; + -no-global|--no-global) options=( "${options[@]}" "-Dsbt.global.base=$(pwd)/project/.sbtboot" ) && shift ;; + -sbt-boot|--sbt-boot) require_arg path "$1" "$2" && options=( "${options[@]}" "-Dsbt.boot.directory=$2" ) && shift 2 ;; + -sbt-dir|--sbt-dir) require_arg path "$1" "$2" && options=( "${options[@]}" "-Dsbt.global.base=$2" ) && shift 2 ;; + -debug|--debug) commands=( "${commands[@]}" "-debug" ) && shift ;; + -debug-inc|--debug-inc) options=( "${options[@]}" "-Dxsbt.inc.debug=true" ) && shift ;; + *) options=( "${options[@]}" "$1" ) && shift ;; esac done - declare -p retarr + declare -p options + declare -p commands } process_args () { From 4872ddf3efe4b84b780544d7877473ac94da6902 Mon Sep 17 00:00:00 2001 From: Henri Cook Date: Mon, 25 May 2020 19:31:20 +0100 Subject: [PATCH 2/3] Add tests for supporting -debug flag in SBT_OPTSs --- integration-test/src/test/scala/RunnerTest.scala | 14 ++++++++++++++ src/universal/bin/sbt | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index 29a0be9bb..7f0ec31d7 100755 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -137,6 +137,20 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { () } + test("sbt with -debug in SBT_OPTS appears in sbt commands") { + val out: List[String] = sbtProcessWithOpts("compile", "-v")("", "-debug").!!.linesIterator.toList + // Debug argument must appear in the 'commands' section after sbt-launch.jar to work + val locationOfSbtLaunchJarArg = out.zipWithIndex.collectFirst { + case (arg, index) if arg.endsWith("sbt-launch.jar") => index + } + + assert(locationOfSbtLaunchJarArg.nonEmpty) + + val argsAfterSbtLaunch = out.drop(locationOfSbtLaunchJarArg.get) + assert(argsAfterSbtLaunch.contains("-debug")) + () + } + test("sbt -V|-version|--version should print sbtVersion") { val out = sbtProcess("-version").!!.trim val expectedVersion = diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index 17ae8f426..2408265b7 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -353,11 +353,11 @@ run() { java_args=($JAVA_OPTS) sbt_options0=(${SBT_OPTS:-$default_sbt_opts}) - # Split SBT_OPTs into options/commands + # Split SBT_OPTS into options/commands miniscript=$(map_args "${sbt_options0[@]}") && eval "${miniscript/options/sbt_options}" && \ eval "${miniscript/commands/sbt_additional_commands}" - # Combine command line options/commands and commands from SBT_OPTs + # Combine command line options/commands and commands from SBT_OPTS miniscript=$(map_args "$@") && eval "${miniscript/options/cli_options}" && eval "${miniscript/commands/cli_commands}" args1=( "${cli_options[@]}" "${cli_commands[@]}" "${sbt_additional_commands[@]}" ) From 1bc60adbe75dc708f4e1495b2593c2d650698df0 Mon Sep 17 00:00:00 2001 From: Henri Cook Date: Mon, 25 May 2020 19:40:36 +0100 Subject: [PATCH 3/3] Tidy up -debug in SBT_OPTS for submission --- integration-test/src/test/scala/RunnerTest.scala | 7 +++++-- src/universal/bin/sbt | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index 7f0ec31d7..f94c26e76 100755 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -138,10 +138,13 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { } test("sbt with -debug in SBT_OPTS appears in sbt commands") { + if (isWindows) cancel("Test not supported on windows") + val out: List[String] = sbtProcessWithOpts("compile", "-v")("", "-debug").!!.linesIterator.toList - // Debug argument must appear in the 'commands' section after sbt-launch.jar to work + // Debug argument must appear in the 'commands' section (after the sbt-launch.jar argument) to work + val sbtLaunchMatcher = """^.+sbt-launch.jar["]{0,1}$""".r val locationOfSbtLaunchJarArg = out.zipWithIndex.collectFirst { - case (arg, index) if arg.endsWith("sbt-launch.jar") => index + case (arg, index) if sbtLaunchMatcher.findFirstIn(arg).nonEmpty => index } assert(locationOfSbtLaunchJarArg.nonEmpty) diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index 2408265b7..a3f9443e3 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -133,7 +133,7 @@ addJava () { java_args=( "${java_args[@]}" "$1" ) } addSbt () { - echoerr "[addSbt] arg = '$1'" + dlog "[addSbt] arg = '$1'" sbt_commands=( "${sbt_commands[@]}" "$1" ) } addResidual () {