From fe43d0b975b05d658d1443adbaa339e757a8d009 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Fri, 8 Nov 2019 10:23:53 +0800 Subject: [PATCH 1/5] Add special handling for -XX Fix special handling for -D where > null should be > nul Fix the problem that only the first option of SBT_OPTS and JAVA_OPTS got processed --- src/universal/bin/sbt.bat | 67 +++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/src/universal/bin/sbt.bat b/src/universal/bin/sbt.bat index 577a2adac..547f7c000 100755 --- a/src/universal/bin/sbt.bat +++ b/src/universal/bin/sbt.bat @@ -49,7 +49,11 @@ rem users can set SBT_OPTS via .sbtopts if exist .sbtopts for /F %%A in (.sbtopts) do ( set _sbtopts_line=%%A if not "!_sbtopts_line:~0,1!" == "#" ( - set _SBT_OPTS=%%A %SBT_OPTS% + if defined _SBT_OPTS ( + set _SBT_OPTS=!_SBT_OPTS! %%A + ) else ( + set _SBT_OPTS=%%A + ) ) ) @@ -404,7 +408,7 @@ if "%~0" == "new" ( if "%g:~0,2%" == "-D" ( rem special handling for -D since '=' gets parsed away - echo "%g%" | find "=" > null + echo "%g%" | find "=" > nul if ERRORLEVEL 1 ( if not "%~1" == "" ( call :dlog [args_loop] -D argument %~0=%~1 @@ -422,6 +426,26 @@ if "%g:~0,2%" == "-D" ( ) ) +if "%g:~0,3%" == "-XX" ( + rem special handling for -XX since '=' gets parsed away + echo "%g%" | find "=" > nul + if ERRORLEVEL 1 ( + if not "%~1" == "" ( + call :dlog [args_loop] -XX argument %~0=%~1 + set "SBT_ARGS=!SBT_ARGS! %~0=%~1" + shift + goto args_loop + ) else ( + echo %g% is missing a value + goto error + ) + ) else ( + call :dlog [args_loop] -XX argument %~0 + set "SBT_ARGS=!SBT_ARGS! %~0" + goto args_loop + ) +) + rem the %0 (instead of %~0) preserves original argument quoting set SBT_ARGS=!SBT_ARGS! %0 @@ -584,16 +608,24 @@ shift if [%0] EQU [] goto echolist_end set "p=%0" -rem special handling for -D since '=' gets parsed away if "%p:~0,2%" == "-D" ( - rem if "-Dscala.ext.dirs" (replace all = with nothing) == "-Dscala.ext.dirs" - rem (e.g. verify it doesn't have the = already) - - if "x%p:^==%" == "x%p%" if not "%~1" == "" ( + rem special handling for -D since '=' gets parsed away + echo "%p%" | find "=" > nul + if ERRORLEVEL 1 if not "%~1" == "" ( echo %0=%1 shift goto echolist - ) + ) +) + +if "%p:~0,3%" == "-XX" ( + rem special handling for -D since '=' gets parsed away + echo "%p%" | find "=" > nul + if ERRORLEVEL 1 if not "%~1" == "" ( + echo %0=%1 + shift + goto echolist + ) ) echo %0 @@ -613,24 +645,33 @@ exit /B 0 rem evict memory related options set _new_java_opts= - - for /F %%g in ("!_JAVA_OPTS!") do ( + set _old_java_opts=!_JAVA_OPTS! +:next_java_opt + if "!_old_java_opts!" == "" goto :done_java_opt + for /F "tokens=1,*" %%g in ("!_old_java_opts!") do ( set "p=%%g" if not "!p:~0,4!" == "-Xmx" if not "!p:~0,4!" == "-Xms" if not "!p:~0,15!" == "-XX:MaxPermSize" if not "!p:~0,20!" == "-XX:MaxMetaspaceSize" if not "!p:~0,25!" == "-XX:ReservedCodeCacheSize" ( set _new_java_opts=!_new_java_opts! %%g ) + set "_old_java_opts=%%h" ) + goto :next_java_opt +:done_java_opt set _JAVA_OPTS=!_new_java_opts! set _new_sbt_opts= - - for /F %%g in ("!_SBT_OPTS!") do ( + set _old_sbt_opts=!_SBT_OPTS! +:next_sbt_opt + if "!_old_sbt_opts!" == "" goto :done_sbt_opt + for /F "tokens=1,*" %%g in ("!_old_sbt_opts!") do ( set "p=%%g" if not "!p:~0,4!" == "-Xmx" if not "!p:~0,4!" == "-Xms" if not "!p:~0,15!" == "-XX:MaxPermSize" if not "!p:~0,20!" == "-XX:MaxMetaspaceSize" if not "!p:~0,25!" == "-XX:ReservedCodeCacheSize" ( set _new_sbt_opts=!_new_sbt_opts! %%g ) + set "_old_sbt_opts=%%h" ) - + goto :next_sbt_opt +:done_sbt_opt set _SBT_OPTS=!_new_sbt_opts! rem a ham-fisted attempt to move some memory settings in concert From c742f66dd861e70c89dd86970057b42f65765047 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Sat, 9 Nov 2019 22:44:13 +0800 Subject: [PATCH 2/5] Add tests for -XX and mutiple -D --- integration-test/src/test/scala/RunnerTest.scala | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index d810f9475..fd8b3a0dd 100755 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -95,12 +95,25 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { } test("sbt with -Xms2048M -Xmx2048M -Xss6M in SBT_OPTS") { - if (isWindows) cancel("Test not supported on windows") val out = sbtProcessWithOpts("compile -v", "", "-Xms2048M -Xmx2048M -Xss6M").!!.linesIterator.toList assert(out.contains[String]("-Xss6M")) () } + test("sbt with -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080").!!.linesIterator.toList + assert(out.contains[String]("-Dhttp.proxyHost=proxy")) + assert(out.contains[String]("-Dhttp.proxyPort=8080")) + () + } + + test("sbt with -XX:ParallelGCThreads=16 -XX:PermSize=128M in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-XX:ReservedCodeCacheSize=256m -XX:MaxPermSize=256m").!!.linesIterator.toList + assert(out.contains[String]("-XX:ParallelGCThreads=16")) + assert(out.contains[String]("-XX:PermSize=128M")) + () + } + test("sbt with --no-colors in SBT_OPTS") { if (isWindows) cancel("Test not supported on windows") val out = sbtProcessWithOpts("compile -v", "", "--no-colors").!!.linesIterator.toList From 34ca7297190c5f13a11fbebb8aa297949a28db56 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Sun, 10 Nov 2019 20:46:55 +0800 Subject: [PATCH 3/5] Fix Travis CI error: find: '=': No such file or directory --- src/universal/bin/sbt.bat | 58 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/universal/bin/sbt.bat b/src/universal/bin/sbt.bat index 547f7c000..46fceb0a6 100755 --- a/src/universal/bin/sbt.bat +++ b/src/universal/bin/sbt.bat @@ -408,41 +408,45 @@ if "%~0" == "new" ( if "%g:~0,2%" == "-D" ( rem special handling for -D since '=' gets parsed away - echo "%g%" | find "=" > nul - if ERRORLEVEL 1 ( - if not "%~1" == "" ( - call :dlog [args_loop] -D argument %~0=%~1 - set "SBT_ARGS=!SBT_ARGS! %~0=%~1" - shift - goto args_loop + for /F "tokens=1 delims==" %%a in ("%g%") do ( + rem make sure it doesn't have the '=' already + if "%g%" == "%%a" ( + if not "%~1" == "" ( + call :dlog [args_loop] -D argument %~0=%~1 + set "SBT_ARGS=!SBT_ARGS! %~0=%~1" + shift + goto args_loop + ) else ( + echo %g% is missing a value + goto error + ) ) else ( - echo %g% is missing a value - goto error + call :dlog [args_loop] -D argument %~0 + set "SBT_ARGS=!SBT_ARGS! %~0" + goto args_loop ) - ) else ( - call :dlog [args_loop] -D argument %~0 - set "SBT_ARGS=!SBT_ARGS! %~0" - goto args_loop ) ) if "%g:~0,3%" == "-XX" ( - rem special handling for -XX since '=' gets parsed away - echo "%g%" | find "=" > nul - if ERRORLEVEL 1 ( - if not "%~1" == "" ( - call :dlog [args_loop] -XX argument %~0=%~1 - set "SBT_ARGS=!SBT_ARGS! %~0=%~1" - shift - goto args_loop + rem special handling for -D since '=' gets parsed away + for /F "tokens=1 delims==" %%a in ("%g%") do ( + rem make sure it doesn't have the '=' already + if "%g%" == "%%a" ( + if not "%~1" == "" ( + call :dlog [args_loop] -XX argument %~0=%~1 + set "SBT_ARGS=!SBT_ARGS! %~0=%~1" + shift + goto args_loop + ) else ( + echo %g% is missing a value + goto error + ) ) else ( - echo %g% is missing a value - goto error + call :dlog [args_loop] -XX argument %~0 + set "SBT_ARGS=!SBT_ARGS! %~0" + goto args_loop ) - ) else ( - call :dlog [args_loop] -XX argument %~0 - set "SBT_ARGS=!SBT_ARGS! %~0" - goto args_loop ) ) From cb19634350401cede4d41e5a30a4286b8c25f71e Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Mon, 11 Nov 2019 10:56:10 +0800 Subject: [PATCH 4/5] Fix tests for -XX, then add test for -XX:+ and -XX:- --- .../src/test/scala/RunnerTest.scala | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index fd8b3a0dd..d3dc0c580 100755 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -108,12 +108,28 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { } test("sbt with -XX:ParallelGCThreads=16 -XX:PermSize=128M in SBT_OPTS") { - val out = sbtProcessWithOpts("compile -v", "", "-XX:ReservedCodeCacheSize=256m -XX:MaxPermSize=256m").!!.linesIterator.toList + val out = sbtProcessWithOpts("compile -v", "", "-XX:ParallelGCThreads=16 -XX:PermSize=128M").!!.linesIterator.toList assert(out.contains[String]("-XX:ParallelGCThreads=16")) assert(out.contains[String]("-XX:PermSize=128M")) () } + test("sbt with -XX:+UseG1GC -XX:+PrintGC in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-XX:+UseG1GC -XX:+PrintGC").!!.linesIterator.toList + assert(out.contains[String]("-XX:+UseG1GC")) + assert(out.contains[String]("-XX:+PrintGC")) + assert(!out.contains[String]("-XX:+UseG1GC=-XX:+PrintGC")) + () + } + + test("sbt with -XX:-UseG1GC -XX:-PrintGC in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-XX:-UseG1GC -XX:-PrintGC").!!.linesIterator.toList + assert(out.contains[String]("-XX:-UseG1GC")) + assert(out.contains[String]("-XX:-PrintGC")) + assert(!out.contains[String]("-XX:-UseG1GC=-XX:-PrintGC")) + () + } + test("sbt with --no-colors in SBT_OPTS") { if (isWindows) cancel("Test not supported on windows") val out = sbtProcessWithOpts("compile -v", "", "--no-colors").!!.linesIterator.toList From 1318c0f59407a0034d8ac7e1f8910f676e705824 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Mon, 11 Nov 2019 10:59:06 +0800 Subject: [PATCH 5/5] Add special handling for -XX, -XX:+ and -XX:0 --- src/universal/bin/sbt.bat | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/universal/bin/sbt.bat b/src/universal/bin/sbt.bat index 46fceb0a6..417b79ad3 100755 --- a/src/universal/bin/sbt.bat +++ b/src/universal/bin/sbt.bat @@ -428,8 +428,8 @@ if "%g:~0,2%" == "-D" ( ) ) -if "%g:~0,3%" == "-XX" ( - rem special handling for -D since '=' gets parsed away +if not "%g:~0,5%" == "-XX:+" if not "%g:~0,5%" == "-XX:-" if "%g:~0,3%" == "-XX" ( + rem special handling for -XX since '=' gets parsed away for /F "tokens=1 delims==" %%a in ("%g%") do ( rem make sure it doesn't have the '=' already if "%g%" == "%%a" ( @@ -614,21 +614,25 @@ set "p=%0" if "%p:~0,2%" == "-D" ( rem special handling for -D since '=' gets parsed away - echo "%p%" | find "=" > nul - if ERRORLEVEL 1 if not "%~1" == "" ( - echo %0=%1 - shift - goto echolist + for /F "tokens=1 delims==" %%a in ("%p%") do ( + rem make sure it doesn't have the '=' already + if "%p%" == "%%a" if not "%~1" == "" ( + echo %0=%1 + shift + goto echolist + ) ) ) -if "%p:~0,3%" == "-XX" ( - rem special handling for -D since '=' gets parsed away - echo "%p%" | find "=" > nul - if ERRORLEVEL 1 if not "%~1" == "" ( - echo %0=%1 - shift - goto echolist +if not "%p:~0,5%" == "-XX:+" if not "%p:~0,5%" == "-XX:-" if "%p:~0,3%" == "-XX" ( + rem special handling for -XX since '=' gets parsed away + for /F "tokens=1 delims==" %%a in ("%p%") do ( + rem make sure it doesn't have the '=' already + if "%p%" == "%%a" if not "%~1" == "" ( + echo %0=%1 + shift + goto echolist + ) ) )