diff --git a/dist/bin/common.bat b/dist/bin/common.bat index 0ffaed18652c..9f47198e757b 100644 --- a/dist/bin/common.bat +++ b/dist/bin/common.bat @@ -33,9 +33,12 @@ if not exist "%_JAVACMD%" ( set _EXITCODE=1 goto :eof ) - -if not defined _PROG_HOME set "_PROG_HOME=%~dp0" -for /f "delims=" %%f in ("%_PROG_HOME%\.") do set "_LIB_DIR=%%~dpflib" +if not defined _PROG_HOME ( + echo Error: Variable _PROG_HOME undefined 1>&2 + set _EXITCODE=1 + goto :eof +) +set "_LIB_DIR=%_PROG_HOME%\lib" set _PSEP=; diff --git a/dist/bin/scala.bat b/dist/bin/scala.bat index edf7bfc5a1c2..ca908fd340be 100644 --- a/dist/bin/scala.bat +++ b/dist/bin/scala.bat @@ -6,9 +6,12 @@ setlocal enabledelayedexpansion set _EXITCODE=0 -set "_PROG_HOME=%~dp0" - -call "%_PROG_HOME%\common.bat" +for %%f in ("%~dp0.") do ( + set "_PROG_HOME=%%~dpf" + @rem get rid of the trailing slash + set "_PROG_HOME=!_PROG_HOME:~0,-1!" +) +call "%_PROG_HOME%\bin\common.bat" if not %_EXITCODE%==0 goto end call :args %* @@ -16,46 +19,10 @@ call :args %* @rem ######################################################################### @rem ## Main -set _CASE_REPL=0 -if %_EXECUTE_REPL%==1 set _CASE_REPL=1 -if %_EXECUTE_RUN%==0 if %_OPTIONS_INDICATOR%==0 set _CASE_REPL=1 - -set _CASE_EXEC=0 -if %_EXECUTE_REPL%==1 set _CASE_EXEC=1 -if defined _RESIDUAL_ARGS set _CASE_EXEC=1 - -if %_EXECUTE_SCRIPT%==1 ( - set _SCALAC_ARGS= - if defined _CLASS_PATH set _SCALAC_ARGS=-classpath "%_CLASS_PATH%" - set _RESIDUAL_ARGS=!_RESIDUAL_ARGS! "-Dscript.path=%_TARGET_SCRIPT%" - set _SCALAC_ARGS=!_SCALAC_ARGS! %_JAVA_OPTS% !_RESIDUAL_ARGS! -script "%_TARGET_SCRIPT%" %_SCRIPT_ARGS% - call "%_PROG_HOME%\scalac.bat" !_SCALAC_ARGS! - if not !ERRORLEVEL!==0 ( set _EXITCODE=1& goto end ) -@rem if [ $execute_repl == true ] || ([ $execute_run == false ] && [ $options_indicator == 0 ]); then -) else if %_CASE_REPL%==1 ( - set _SCALAC_ARGS= - if defined _CLASS_PATH set _SCALAC_ARGS=-classpath "%_CLASS_PATH%" - set _SCALAC_ARGS=!_SCALAC_ARGS! %_JAVA_OPTS% -repl %_RESIDUAL_ARGS% - call "%_PROG_HOME%\scalac.bat" !_SCALAC_ARGS! - if not !ERRORLEVEL!==0 ( set _EXITCODE=1& goto end ) -@rem elif [ $execute_repl == true ] || [ ${#residual_args[@]} -ne 0 ]; then -) else if %_CASE_EXEC%==1 ( - set "_CP_ARG=%_SCALA3_LIB%%_PSEP%%_SCALA_LIB%" - if defined _CLASS_PATH ( set "_CP_ARG=!_CP_ARG!%_PSEP%%_CLASS_PATH%" - ) else ( set "_CP_ARG=!_CP_ARG!%_PSEP%." - ) - if %_CLASS_PATH_COUNT% gtr 1 ( - echo Warning: Multiple classpaths are found, scala only use the last one. 1>&2 - ) - if %_WITH_COMPILER%==1 ( - set "_CP_ARG=!_CP_ARG!%_PSEP%%_SCALA3_COMP%%_PSEP%%_TASTY_CORE%%_PSEP%%_SCALA3_INTF%%_PSEP%%_SCALA_ASM%%_PSEP%%_SCALA3_STAGING%%_PSEP%%_SCALA3_TASTY_INSPECTOR%" - ) - set _JAVA_ARGS=-classpath "!_CP_ARG!" %_JVM_OPTS% %_RESIDUAL_ARGS% - call "%_JAVACMD%" !_JAVA_ARGS! - if not !ERRORLEVEL!==0 ( set _EXITCODE=1& goto end ) -) else ( - echo Warning: Command option is not correct. 1>&2 -) +call :compilerJavaClasspathArgs + +call "%_JAVACMD%" %_JAVA_ARGS% "-Dscala.home=%_PROG_HOME%" -classpath "%_JVM_CP_ARGS%" dotty.tools.MainGenericRunner -classpath "%_JVM_CP_ARGS%" %_SCALA_ARGS% +if not %ERRORLEVEL%==0 ( set _EXITCODE=1& goto end ) goto end @@ -63,56 +30,63 @@ goto end @rem ## Subroutines :args -set _RESIDUAL_ARGS= -set _SCRIPT_ARGS= -set _EXECUTE_REPL=0 -set _EXECUTE_RUN=0 -set _EXECUTE_SCRIPT=0 -set _TARGET_SCRIPT= -set _WITH_COMPILER=0 -set _CLASS_PATH_COUNT=0 -set _CLASS_PATH= -set _JVM_OPTS= -set _JAVA_OPTS= -set _OPTIONS_INDICATOR=0 +set _JAVA_ARGS= +set _SCALA_ARGS= +set _SCALA_CPATH= :args_loop if "%~1"=="" goto args_done set "__ARG=%~1" -if "%__ARG%"=="-repl" ( - set _EXECUTE_REPL=1 -) else if "%__ARG%"=="-run" ( - set _EXECUTE_RUN=1 +if "%__ARG:~0,2%"=="-D" ( + @rem pass to scala as well: otherwise we lose it sometimes when we + @rem need it, e.g. communicating with a server compiler. + set _JAVA_ARGS=!_JAVA_ARGS! "%__ARG%" + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" +) else if "%__ARG:~0,2%"=="-J" ( + @rem as with -D, pass to scala even though it will almost + @rem never be used. + set _JAVA_ARGS=!_JAVA_ARGS! %__ARG:~2% + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" ) else if "%__ARG%"=="-classpath" ( - set "_CLASS_PATH=%~2" - set /a _CLASS_PATH_COUNT+=1 + set "_SCALA_CPATH=%~2" shift ) else if "%__ARG%"=="-cp" ( - set "_CLASS_PATH=%~2" - set /a _CLASS_PATH_COUNT+=1 + set "_SCALA_CPATH=%~2" shift -) else if "%__ARG%"=="-with-compiler" ( - set _WITH_COMPILER=1 -) else if "%__ARG:~0,2%"=="-J" ( - set _JVM_OPTS=!_JVM_OPTS! %__ARG:~2% - set _JAVA_OPTS=!_JAVA_OPTS! %__ARG% ) else ( - @rem _OPTIONS_INDICATOR != 0 if at least one parameter is not an option - if not "%__ARG:~0,1%"=="-" set /a _OPTIONS_INDICATOR+=1 - if %_EXECUTE_SCRIPT%==1 ( - set _SCRIPT_ARGS=%_SCRIPT_ARGS% %__ARG% - ) else if "%__ARG:~-6%"==".scala" ( - set _EXECUTE_SCRIPT=1 - set "_TARGET_SCRIPT=%__ARG%" - ) else ( - set _RESIDUAL_ARGS=%_RESIDUAL_ARGS% %__ARG% - ) + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" ) shift goto args_loop :args_done goto :eof +@rem output parameter: _JVM_CP_ARGS +:compilerJavaClasspathArgs +set __TOOLCHAIN= +set "__TOOLCHAIN=%__TOOLCHAIN%%_SCALA_LIB%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_SCALA3_LIB%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_SCALA_ASM%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_SBT_INTF%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_SCALA3_INTF%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_SCALA3_COMP%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_TASTY_CORE%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_SCALA3_STAGING%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_SCALA3_TASTY_INSPECTOR%%_PSEP%" + +@rem # jline +set "__TOOLCHAIN=%__TOOLCHAIN%%_JLINE_READER%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_JLINE_TERMINAL%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_JLINE_TERMINAL_JNA%%_PSEP%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_JNA%%_PSEP%" + +if defined _SCALA_CPATH ( + set "_JVM_CP_ARGS=%__TOOLCHAIN%%_SCALA_CPATH%" +) else ( + set "_JVM_CP_ARGS=%__TOOLCHAIN%" +) +goto :eof + @rem ######################################################################### @rem ## Cleanups diff --git a/dist/bin/scalac.bat b/dist/bin/scalac.bat index a94bdb5f88b8..454158c85666 100644 --- a/dist/bin/scalac.bat +++ b/dist/bin/scalac.bat @@ -6,44 +6,22 @@ setlocal enabledelayedexpansion set _EXITCODE=0 -set "_PROG_HOME=%~dp0" - -call "%_PROG_HOME%\common.bat" +for %%f in ("%~dp0.") do ( + set "_PROG_HOME=%%~dpf" + @rem get rid of the trailing slash + set "_PROG_HOME=!_PROG_HOME:~0,-1!" +) +call "%_PROG_HOME%\bin\common.bat" if not %_EXITCODE%==0 goto end -set _DEFAULT_JAVA_OPTS=-Xmx768m -Xms768m -@rem set _WITH_COMPILER=true - -set _COMPILER_MAIN=dotty.tools.dotc.Main -set _DECOMPILER_MAIN=dotty.tools.dotc.decompiler.Main -set _REPL_MAIN=dotty.tools.repl.Main -set _SCRIPTING_MAIN=dotty.tools.scripting.Main - call :args %* @rem ######################################################################### @rem ## Main -call :classpathArgs +call :compilerJavaClasspathArgs -set _SCRIPTING_STRING= -if "%_PROG_NAME%"=="%_SCRIPTING_MAIN%" ( - if not defined _TARGET_SCRIPT ( - echo Error: Missing Scala script file 1>&2 - set _EXITCODE=1 - goto end - ) - set _SCRIPTING_STRING=-script %_TARGET_SCRIPT% %_SCRIPTING_ARGS% -) - -if defined JAVA_OPTS ( set _JAVA_OPTS=%JAVA_OPTS% -) else ( set _JAVA_OPTS=%_DEFAULT_JAVA_OPTS% -) -for %%i in ("%_PROG_HOME%\..") do set "_SCALA_HOME=%%~fi" - -call "%_JAVACMD%" %_JAVA_OPTS% %_JAVA_DEBUG% %_JAVA_ARGS% %_JVM_CP_ARGS% ^ --Dscala.home="%_SCALA_HOME%" -Dscala.usejavacp=true ^ -%_PROG_NAME% %_SCALA_ARGS% %_RESIDUAL_ARGS% %_SCRIPTING_STRING% +call "%_JAVACMD%" %_JAVA_ARGS% -classpath "%_JVM_CP_ARGS%" "-Dscala.usejavacp=true" "-Dscala.home=%_PROG_HOME%" dotty.tools.MainGenericCompiler %_SCALA_ARGS% if not %ERRORLEVEL%==0 ( set _EXITCODE=1 goto end @@ -54,92 +32,59 @@ goto end @rem ## Subroutines :args -set _JAVA_DEBUG= -set _HELP= -set _VERBOSE= -set _QUIET= -set _COLORS= -set _PROG_NAME=%_COMPILER_MAIN% -set _SCALA_ARGS= set _JAVA_ARGS= -set _RESIDUAL_ARGS= -set _SCRIPTING_ARGS= -set _TARGET_SCRIPT= +set _SCALA_ARGS= +set _SCALA_CPATH= +@rem replace inner while loop used in bash script +set _CONSUME_REMAINING= :args_loop if "%~1"=="" goto args_done set "__ARG=%~1" -if defined _TARGET_SCRIPT ( - call :addScripting "%__ARG%" +if defined _CONSUME_REMAINING ( + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" + shift ) else if "%__ARG%"=="--" ( - @rem for arg; do addResidual "$arg"; done; set -- ;; -) else if "%__ARG%"=="-h" ( - set _HELP=true - call :addScala "-help" -) else if "%__ARG%"=="-help" ( - set _HELP=true - call :addScala "-help" -) else if "%__ARG%"=="-v" ( - set _VERBOSE=true - call :addScala "-verbose" -) else if "%__ARG%"=="-verbose" ( - set _VERBOSE=true - call :addScala "-verbose" -) else if "%__ARG%"=="-debug" ( set "_JAVA_DEBUG=%_DEBUG_STR%" -) else if "%__ARG%"=="-q" ( set _QUIET=true -) else if "%__ARG%"=="-quiet" ( set _QUIET=true -@rem Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222 -) else if "%__ARG%"=="-Oshort" ( - call :addJava "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" -) else if "%__ARG%"=="-repl" ( set _PROG_NAME=%_REPL_MAIN% + @rem pass all remaining arguments to scala, e.g. to avoid interpreting them here as -D or -J + set _CONSUME_REMAINING=1 + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" + shift ) else if "%__ARG%"=="-script" ( - set _PROG_NAME=%_SCRIPTING_MAIN% - if "%~2"=="" goto args_done - set "_TARGET_SCRIPT=%~2" + @rem pass all remaining arguments to scala, e.g. to avoid interpreting them here as -D or -J + set _CONSUME_REMAINING=1 + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" shift -) else if "%__ARG%"=="-compile" ( set _PROG_NAME=%_COMPILER_MAIN% -) else if "%__ARG%"=="-decompile" ( set _PROG_NAME=%_DECOMPILER_MAIN% -) else if "%__ARG%"=="-print-tasty" ( - set _PROG_NAME=%_DECOMPILER_MAIN% - call :addScala "-print-tasty" -) else if "%__ARG%"=="-run" ( set _PROG_NAME=%_REPL_MAIN% -) else if "%__ARG%"=="-colors" ( set _COLORS=true -) else if "%__ARG%"=="-no-colors" ( set _COLORS= -) else if "%__ARG%"=="-with-compiler" ( set "_JVM_CP_ARGS=%_PSEP%%_SCALA3_COMP%%_PSEP%%_TASTY_CORE%" -@rem break out -D and -J options and add them to JAVA_OPTS as well -@rem so they reach the JVM in time to do some good. The -D options -@rem will be available as system properties. -) else if "%__ARG:~0,2%"=="-D" ( call :addJava "%__ARG%" -) else if "%__ARG:~0,2%"=="-J" ( call :addJava "%__ARG:~2%" -) else ( call :addResidual "%__ARG%" +) else if "%__ARG%"=="-Oshort" ( + @rem optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222 + set _JAVA_ARGS=!_JAVA_ARGS! "-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1" + set _SCALA_ARGS=!_SCALA_ARGS! -Oshort + shift +) else if "%__ARG:~0,2%"=="-D" ( + @rem pass to scala as well: otherwise we lose it sometimes when we + @rem need it, e.g. communicating with a server compiler. + set _JAVA_ARGS=!_JAVA_ARGS! "%__ARG%" + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" +) else if "%__ARG:~0,2%"=="-J" ( + @rem as with -D, pass to scala even though it will almost + @rem never be used. + set _JAVA_ARGS=!_JAVA_ARGS! %__ARG:~2% + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" +) else if "%__ARG%"=="-classpath" ( + set "_SCALA_CPATH=%~2" + shift +) else if "%__ARG%"=="-cp" ( + set "_SCALA_CPATH=%~2" + shift +) else ( + set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%" ) shift goto args_loop :args_done goto :eof -@rem output parameter: _SCALA_ARGS -:addScala -set _SCALA_ARGS=%_SCALA_ARGS% %~1 -goto :eof - -@rem output parameter: _JAVA_ARGS -:addJava -set _JAVA_ARGS=%_JAVA_ARGS% %~1 -goto :eof - -@rem output parameter: _RESIDUAL_ARGS -:addResidual -set _RESIDUAL_ARGS=%_RESIDUAL_ARGS% %~1 -goto :eof - -@rem output parameter: _SCRIPTING_ARGS -:addScripting -set _SCRIPTING_ARGS=%_SCRIPTING_ARGS% %~1 -goto :eof - @rem output parameter: _JVM_CP_ARGS -:classpathArgs +:compilerJavaClasspathArgs @rem echo scala3-compiler: %_SCALA3_COMP% @rem echo scala3-interface: %_SCALA3_INTF% @rem echo scala3-library: %_SCALA3_LIB% @@ -162,9 +107,13 @@ set "__TOOLCHAIN=%__TOOLCHAIN%%_SCALA3_TASTY_INSPECTOR%%_PSEP%" set "__TOOLCHAIN=%__TOOLCHAIN%%_JLINE_READER%%_PSEP%" set "__TOOLCHAIN=%__TOOLCHAIN%%_JLINE_TERMINAL%%_PSEP%" set "__TOOLCHAIN=%__TOOLCHAIN%%_JLINE_TERMINAL_JNA%%_PSEP%" -set "__TOOLCHAIN=%__TOOLCHAIN%%_JNA%" +set "__TOOLCHAIN=%__TOOLCHAIN%%_JNA%%_PSEP%" -set _JVM_CP_ARGS=-classpath "%__TOOLCHAIN%" +if defined _SCALA_CPATH ( + set "_JVM_CP_ARGS=%__TOOLCHAIN%%_SCALA_CPATH%" +) else ( + set "_JVM_CP_ARGS=%__TOOLCHAIN%" +) goto :eof @rem ######################################################################### diff --git a/dist/bin/scaladoc.bat b/dist/bin/scaladoc.bat index e14cd519889f..bcc0d71788a3 100644 --- a/dist/bin/scaladoc.bat +++ b/dist/bin/scaladoc.bat @@ -6,9 +6,12 @@ setlocal enabledelayedexpansion set _EXITCODE=0 -set "_PROG_HOME=%~dp0" - -call "%_PROG_HOME%\common.bat" +for %%f in ("%~dp0.") do ( + set "_PROG_HOME=%%~dpf" + @rem get rid of the trailing slash + set "_PROG_HOME=!_PROG_HOME:~0,-1!" +) +call "%_PROG_HOME%\bin\common.bat" if not %_EXITCODE%==0 goto end set _DEFAULT_JAVA_OPTS=-Xmx768m -Xms768m @@ -98,7 +101,7 @@ goto :eof @rem output parameter: _CLASS_PATH :classpathArgs -for /f "delims=" %%f in ("%_PROG_HOME%\.") do set "_LIB_DIR=%%~dpflib" +set "_LIB_DIR=%_PROG_HOME%\lib" set _CLASS_PATH= @rem keep list in sync with bash script `bin\scaladoc` ! call :updateClasspath "scaladoc"