Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

add options for timings, traces, supershell, and color #259

Merged
merged 2 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions integration-test/src/test/scala/RunnerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions {
()
}

test("sbt --no-colors") {
val out = sbtProcess("compile --no-colors -v").!!.linesIterator.toList
assert(out.contains[String]("-Dsbt.log.noformat=true"))
()
}

test("sbt --color=false") {
val out = sbtProcess("compile --color=false -v").!!.linesIterator.toList
assert(out.contains[String]("-Dsbt.color=false"))
()
}

test("sbt --supershell=never") {
val out = sbtProcess("compile --supershell=never -v").!!.linesIterator.toList
assert(out.contains[String]("-Dsbt.supershell=never"))
()
}

test("sbt --timings") {
val out = sbtProcess("compile --timings -v").!!.linesIterator.toList
assert(out.contains[String]("-Dsbt.task.timings=true"))
()
}

test("sbt -mem 503") {
val out = sbtProcess("compile -mem 503 -v").!!.linesIterator.toList
assert(out.contains[String]("-Xmx503m"))
Expand Down
102 changes: 57 additions & 45 deletions src/universal/bin/sbt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CYGWIN_FLAG=$(if is_cygwin; then echo true; else echo false; fi)
# windows style paths.
cygwinpath() {
local file="$1"
if [[ "$CYGWIN_FLAG" == "true" ]]; then
if [[ "$CYGWIN_FLAG" == "true" ]]; then #"
echo $(cygpath -w $file)
else
echo $file
Expand Down Expand Up @@ -387,7 +387,7 @@ run() {
copyRt

#If we're in cygwin, we should use the windows config, and terminal hacks
if [[ "$CYGWIN_FLAG" == "true" ]]; then
if [[ "$CYGWIN_FLAG" == "true" ]]; then #"
stty -icanon min 1 -echo > /dev/null 2>&1
addJava "-Djline.terminal=jline.UnixTerminal"
addJava "-Dsbt.cygwin=true"
Expand All @@ -405,7 +405,7 @@ run() {
exit_code=$?

# Clean up the terminal from cygwin hacks.
if [[ "$CYGWIN_FLAG" == "true" ]]; then
if [[ "$CYGWIN_FLAG" == "true" ]]; then #"
stty icanon echo > /dev/null 2>&1
fi
exit $exit_code
Expand All @@ -421,41 +421,47 @@ usage() {
cat <<EOM
Usage: `basename "$0"` [options]

-h | -help print this message
-v | -verbose this runner is chattier
-d | -debug set sbt log level to debug
-no-colors disable ANSI color codes
-sbt-create start sbt even if current directory contains no sbt project
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt)
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
-ivy <path> path to local Ivy repository (default: ~/.ivy2)
-mem <integer> set memory options (default: $sbt_default_mem, which is $(get_mem_opts))
-no-share use all local caches; no sharing
-no-global uses global caches, but does not use global ~/.sbt directory.
-jvm-debug <port> Turn on JVM debugging, open at the given port.
-batch Disable interactive mode
-h | --help print this message
-v | --verbose this runner is chattier
-d | --debug set sbt log level to debug
--no-colors disable ANSI color codes
--color=auto|always|true|false|never
enable or disable ANSI color codes (sbt 1.3 and above)
--supershell=auto|always|true|false|never
enable or disable supershell (sbt 1.3 and above)
--traces generate Trace Event report on shutdown (sbt 1.3 and above)
--timings display task timings report on shutdown
--sbt-create start sbt even if current directory contains no sbt project
--sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt)
--sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
--ivy <path> path to local Ivy repository (default: ~/.ivy2)
--mem <integer> set memory options (default: $sbt_default_mem, which is $(get_mem_opts))
--no-share use all local caches; no sharing
--no-global uses global caches, but does not use global ~/.sbt directory.
--jvm-debug <port> Turn on JVM debugging, open at the given port.
--batch disable interactive mode

# sbt version (default: from project/build.properties if present, else latest release)
-sbt-version <version> use the specified version of sbt
-sbt-jar <path> use the specified jar as the sbt launcher
-sbt-rc use an RC version of sbt
-sbt-snapshot use a snapshot version of sbt
--sbt-version <version> use the specified version of sbt
--sbt-jar <path> use the specified jar as the sbt launcher
--sbt-rc use an RC version of sbt
--sbt-snapshot use a snapshot version of sbt

# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
-java-home <path> alternate JAVA_HOME
--java-home <path> alternate JAVA_HOME

# jvm options and output control
JAVA_OPTS environment variable, if unset uses "$default_java_opts"
.jvmopts if this file exists in the current directory, its contents
are appended to JAVA_OPTS
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
.sbtopts if this file exists in the current directory, its contents
are prepended to the runner args
/etc/sbt/sbtopts if this file exists, it is prepended to the runner args
-Dkey=val pass -Dkey=val directly to the java runtime
-J-X pass option -X directly to the java runtime
(-J is stripped)
-S-X add -X to sbt's scalacOptions (-S is stripped)
JAVA_OPTS environment variable, if unset uses "$default_java_opts"
.jvmopts if this file exists in the current directory, its contents
are appended to JAVA_OPTS
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
.sbtopts if this file exists in the current directory, its contents
are prepended to the runner args
/etc/sbt/sbtopts if this file exists, it is prepended to the runner args
-Dkey=val pass -Dkey=val directly to the java runtime
-J-X pass option -X directly to the java runtime
(-J is stripped)
-S-X add -X to sbt's scalacOptions (-S is stripped)

In the case of duplicated or conflicting options, the order above
shows precedence: JAVA_OPTS lowest, command line options highest.
Expand All @@ -467,19 +473,25 @@ EOM
process_my_args () {
while [[ $# -gt 0 ]]; do
case "$1" in
-no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
-no-share) addJava "$noshare_opts" && shift ;;
-no-global) addJava "-Dsbt.global.base=$(pwd)/project/.sbtboot" && shift ;;
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
-sbt-dir) require_arg path "$1" "$2" && addJava "-Dsbt.global.base=$2" && shift 2 ;;
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
-batch) exec </dev/null && shift ;;

-sbt-create) sbt_create=true && shift ;;

new) sbt_new=true && addResidual "$1" && shift ;;

*) addResidual "$1" && shift ;;
-no-colors|--no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
-timings|--timings) addJava "-Dsbt.task.timings=true" && addJava "-Dsbt.task.timings.on.shutdown=true" && shift ;;
-traces|--traces) addJava "-Dsbt.traces=true" && shift ;;
--supershell=*) addJava "-Dsbt.supershell=${1:13}" && shift ;;
-supershell=*) addJava "-Dsbt.supershell=${1:12}" && shift ;;
--color=*) addJava "-Dsbt.color=${1:8}" && shift ;;
-color=*) addJava "-Dsbt.color=${1:7}" && shift ;;
-no-share|--no-share) addJava "$noshare_opts" && shift ;;
-no-global|--no-global) addJava "-Dsbt.global.base=$(pwd)/project/.sbtboot" && shift ;;
-sbt-boot|--sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
-sbt-dir|--sbt-dir) require_arg path "$1" "$2" && addJava "-Dsbt.global.base=$2" && shift 2 ;;
-debug-inc|--debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
-batch|--batch) exec </dev/null && shift ;; #>

-sbt-create|--sbt-create) sbt_create=true && shift ;;

new) sbt_new=true && addResidual "$1" && shift ;;

*) addResidual "$1" && shift ;;
esac
done

Expand Down
42 changes: 21 additions & 21 deletions src/universal/bin/sbt-launch-lib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,27 @@ jdk_version() {
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" && sbt_mem="$2" && shift 2 ;;
-jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
-batch) exec </dev/null && shift ;;

-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
-sbt-version) require_arg version "$1" "$2" && sbt_version="$2" && shift 2 ;;
-java-home) require_arg path "$1" "$2" &&
java_cmd="$2/bin/java" &&
export JAVA_HOME="$2" &&
export JDK_HOME="$2" &&
export PATH="$2/bin:$PATH" &&
shift 2 ;;

"-D*") addJava "$1" && shift ;;
-J*) addJava "${1:2}" && shift ;;
*) addResidual "$1" && shift ;;
-h|-help|--help) usage; exit 1 ;;
-v|-verbose|--verbose) verbose=1 && shift ;;
-d|-debug|--debug) debug=1 && addSbt "-debug" && shift ;;

-ivy|--ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
-mem|--mem) require_arg integer "$1" "$2" && sbt_mem="$2" && shift 2 ;;
-jvm-debug|--jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
-batch|--batch) exec </dev/null && shift ;;

-sbt-jar|--sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
-sbt-version|--sbt-version) require_arg version "$1" "$2" && sbt_version="$2" && shift 2 ;;
-java-home|--java-home) require_arg path "$1" "$2" &&
java_cmd="$2/bin/java" &&
export JAVA_HOME="$2" &&
export JDK_HOME="$2" &&
export PATH="$2/bin:$PATH" &&
shift 2 ;;

"-D*") addJava "$1" && shift ;;
-J*) addJava "${1:2}" && shift ;;
*) addResidual "$1" && shift ;;
esac
done

Expand Down
6 changes: 4 additions & 2 deletions src/universal/bin/sbt.bat
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ set INIT_SBT_VERSION=_TO_BE_REPLACED
:args_loop
if "%~1" == "" goto args_end

if "%~1" == "-jvm-debug" (
set JVM_DEBUG=true
if "%~1" == "-jvm-debug" set set JVM_DEBUG=true
if "%~1" == "--jvm-debug" set set JVM_DEBUG=true

if "%JVM_DEBUG%" == "true" (
set /a JVM_DEBUG_PORT=5005 2>nul >nul
) else if "!JVM_DEBUG!" == "true" (
set /a JVM_DEBUG_PORT=%1 2>nul >nul
Expand Down