From 88dc416932f7bd6e48899e0f289e4a487ac7bec5 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 9 May 2019 00:28:14 -0400 Subject: [PATCH] expand -no-colors alias in SBT_OPTS Fixes #260 This expands the JVM flag aliaes in SBT_OPTS, so `-no-colors` etc would work. --- .../src/test/scala/RunnerTest.scala | 23 +++- src/universal/bin/sbt | 120 ++++++++++-------- 2 files changed, 84 insertions(+), 59 deletions(-) diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index 074d75c04..489edb899 100644 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -10,10 +10,10 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { sbt.internal.Process(sbtScript.getAbsolutePath + " " + arg, new File("citest"), "JAVA_OPTS" -> "", "SBT_OPTS" -> "") - def sbtProcessWithOpts(arg: String) = + def sbtProcessWithOpts(arg: String, javaOpts: String, sbtOpts: String) = sbt.internal.Process(sbtScript.getAbsolutePath + " " + arg, new File("citest"), - "JAVA_OPTS" -> "-Xmx1024m", - "SBT_OPTS" -> "") + "JAVA_OPTS" -> javaOpts, + "SBT_OPTS" -> sbtOpts) test("sbt runs") { assert(sbtScript.exists) @@ -58,9 +58,22 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { () } - test("sbt -mem 503 with JAVA_OPTS") { - val out = sbtProcessWithOpts("compile -mem 503 -v").!!.linesIterator.toList + test("sbt with -mem 503 in JAVA_OPTS") { + val out = sbtProcessWithOpts("compile -mem 503 -v", "-Xmx1024m", "").!!.linesIterator.toList assert(out.contains[String]("-Xmx503m")) () } + + test("sbt with -Xms2048M -Xmx2048M -Xss6M in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-Xms2048M -Xmx2048M -Xss6M").!!.linesIterator.toList + assert(out.contains[String]("-Xss6M")) + () + } + + test("sbt with --no-colors in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "--no-colors").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.log.noformat=true")) + () + } + } diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index 688b6b6e4..9dd623ec8 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -224,43 +224,6 @@ jdk_version() { echo "$result" } -process_args () { - while [[ $# -gt 0 ]]; do - case "$1" in - -h|-help) usage; exit 1 ;; - -v|-verbose) verbose=1 && shift ;; - -d|-debug) debug=1 && addSbt "-debug" && shift ;; - - -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;; - -mem) require_arg integer "$1" "$2" && addMemory "$2" && shift 2 ;; - -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; - -batch) exec -sbt-create|--sbt-create) sbt_create=true && shift ;; @@ -516,6 +468,66 @@ process_my_args () { } } +## map over argument array. this is used to process both command line arguments and SBT_OPTS +map_args () { + local retarr=() + 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 ;; + esac + done + declare -p retarr +} + +process_args () { + while [[ $# -gt 0 ]]; do + case "$1" in + -h|-help) usage; exit 1 ;; + -v|-verbose) verbose=1 && shift ;; + -d|-debug) debug=1 && addSbt "-debug" && shift ;; + + -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;; + -mem) require_arg integer "$1" "$2" && addMemory "$2" && shift 2 ;; + -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; + -batch) exec