Skip to content

Commit 12c8b17

Browse files
committed
t
1 parent af933c4 commit 12c8b17

10 files changed

+367
-256
lines changed

dist/bin/cli-common-platform.bat

Lines changed: 0 additions & 5 deletions
This file was deleted.

dist/bin/cli-common-platform.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# We need to escape % in the java command path, for some reason this doesn't work in common.bat
2+
$global:_JAVACMD = $global:_JAVACMD -replace '%', '%%'
3+
4+
$global:SCALA_CLI_CMD_WIN = "`"$global:_JAVACMD`" -jar `"$global:_PROG_HOME\bin\scala-cli.jar`""

dist/bin/common.bat

Lines changed: 0 additions & 43 deletions
This file was deleted.

dist/bin/common.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# #########################################################################
2+
# ## Code common to scalac.bat, scaladoc.bat and scala.bat
3+
4+
if ($env:JAVACMD) {
5+
$global:_JAVACMD = $env:JAVACMD
6+
} elseif ($env:JAVA_HOME) {
7+
$global:_JAVACMD = Join-Path $env:JAVA_HOME "bin\java.exe"
8+
} elseif ($env:JDK_HOME) {
9+
$global:_JAVACMD = Join-Path $env:JDK_HOME "bin\java.exe"
10+
} else {
11+
$javaPath = Get-Command java.exe -ErrorAction SilentlyContinue
12+
if ($javaPath) {
13+
$javaPathDir = Split-Path $javaPath -Parent
14+
if ($javaPathDir -notmatch "javapath") {
15+
$global:_JAVACMD = Join-Path $javaPathDir "java.exe"
16+
}
17+
}
18+
19+
if (-not $global:_JAVACMD) {
20+
$programFilesJava = Join-Path $env:ProgramFiles "Java"
21+
$javaHome = Get-ChildItem -Path $programFilesJava -Directory -Filter "jre*" | Select-Object -First 1
22+
if ($javaHome) {
23+
$global:_JAVA_HOME = $javaHome.FullName
24+
} else {
25+
$optPath = "C:\opt"
26+
$javaHome = Get-ChildItem -Path $optPath -Directory -Filter "jdk*" | Select-Object -First 1
27+
if ($javaHome) {
28+
$global:_JAVA_HOME = Join-Path $javaHome.FullName "jre"
29+
}
30+
}
31+
32+
if ($global:_JAVA_HOME) {
33+
$global:_JAVACMD = Join-Path $global:_JAVA_HOME "bin\java.exe"
34+
}
35+
}
36+
}
37+
38+
if (-not (Test-Path $global:_JAVACMD)) {
39+
Write-Error "Error: Java executable not found ($global:_JAVACMD)"
40+
$global:_EXITCODE = 1
41+
exit $global:_EXITCODE
42+
}
43+
44+
if (-not $global:_PROG_HOME) {
45+
Write-Error "Error: Variable _PROG_HOME undefined"
46+
$global:_EXITCODE = 1
47+
exit $global:_EXITCODE
48+
}
49+
50+
$global:_ETC_DIR = Join-Path $global:_PROG_HOME "etc"
51+
52+
$global:_PSEP = ";"

dist/bin/scala.bat

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,19 @@ for %%f in ("%~dp0.") do (
1111
@rem get rid of the trailing slash
1212
set "_PROG_HOME=!_PROG_HOME:~0,-1!"
1313
)
14-
call "%_PROG_HOME%\bin\common.bat"
15-
if not %_EXITCODE%==0 goto end
1614

1715
@rem #########################################################################
18-
@rem ## Main
16+
@rem ## Call the new PowerShell script with arguments
1917

20-
call :setScalaOpts
21-
22-
call "%_PROG_HOME%\bin\cli-common-platform.bat"
23-
24-
@rem SCALA_CLI_CMD_WIN is an array, set in cli-common-platform.bat.
25-
@rem WE NEED TO PASS '--skip-cli-updates' for JVM launchers but we actually don't need it for native launchers
26-
call %SCALA_CLI_CMD_WIN% "--prog-name" "scala" "--skip-cli-updates" "--cli-default-scala-version" "%_SCALA_VERSION%" "-r" "%MVN_REPOSITORY%" %*
27-
28-
if not %ERRORLEVEL%==0 ( set _EXITCODE=1& goto end )
29-
30-
goto end
31-
32-
@rem #########################################################################
33-
@rem ## Subroutines
34-
35-
:setScalaOpts
36-
37-
@REM sfind the index of the first colon in _PROG_HOME
38-
set "index=0"
39-
set "char=!_PROG_HOME:~%index%,1!"
40-
:findColon
41-
if not "%char%"==":" (
42-
set /a "index+=1"
43-
set "char=!_PROG_HOME:~%index%,1!"
44-
goto :findColon
45-
)
46-
47-
set "_SCALA_VERSION="
48-
set "MVN_REPOSITORY=file:///%_PROG_HOME:\=/%/maven2"
49-
50-
@rem read for version:=_SCALA_VERSION in VERSION_FILE
51-
FOR /F "usebackq delims=" %%G IN ("%_PROG_HOME%\VERSION") DO (
52-
SET "line=%%G"
53-
IF "!line:~0,9!"=="version:=" (
54-
SET "_SCALA_VERSION=!line:~9!"
55-
GOTO :foundVersion
56-
)
18+
set "args=%*"
19+
call powershell.exe -ExecutionPolicy Bypass -File "%_PROG_HOME%\bin\scala.ps1" -ArgumentList "%args%"
20+
if not %ERRORLEVEL%==0 (
21+
set _EXITCODE=1
22+
goto end
5723
)
5824

59-
:foundVersion
60-
goto :eof
61-
6225
@rem #########################################################################
63-
@rem ## Cleanups
26+
@rem ## Main (if needed to continue batch processing after the PowerShell script)
6427

6528
:end
6629
exit /b %_EXITCODE%

dist/bin/scala.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Environment setup
2+
$global:_EXITCODE = 0
3+
4+
$scriptPath = $PSScriptRoot
5+
$global:_PROG_HOME = $scriptPath.TrimEnd('\')
6+
7+
. "$_PROG_HOME\bin\common.bat"
8+
if ($LASTEXITCODE -ne 0) { goto end }
9+
10+
# Main
11+
setScalaOpts
12+
13+
. "$_PROG_HOME\bin\cli-common-platform.ps1"
14+
15+
# SCALA_CLI_CMD_WIN is an array, set in cli-common-platform.bat.
16+
# WE NEED TO PASS '--skip-cli-updates' for JVM launchers but we actually don't need it for native launchers
17+
& $env:SCALA_CLI_CMD_WIN "--prog-name" "scala" "--skip-cli-updates" "--cli-default-scala-version" "$env:_SCALA_VERSION" "-r" "$env:MVN_REPOSITORY" $args
18+
19+
if ($LASTEXITCODE -ne 0) {
20+
$global:_EXITCODE = 1
21+
goto end
22+
}
23+
24+
goto end
25+
26+
# Subroutines
27+
28+
function setScalaOpts {
29+
# Find the index of the first colon in _PROG_HOME
30+
$index = $global:_PROG_HOME.IndexOf(':')
31+
if ($index -eq -1) { $index = 0 }
32+
33+
$global:_SCALA_VERSION = ""
34+
$global:MVN_REPOSITORY = "file:///$($global:_PROG_HOME -replace '\\', '/')/maven2"
35+
36+
# Read version from VERSION_FILE
37+
$versionFilePath = "$global:_PROG_HOME\VERSION"
38+
if (Test-Path $versionFilePath) {
39+
$lines = Get-Content $versionFilePath
40+
foreach ($line in $lines) {
41+
if ($line.StartsWith("version:=")) {
42+
$global:_SCALA_VERSION = $line.Substring(9)
43+
break
44+
}
45+
}
46+
}
47+
}
48+
49+
# Cleanups
50+
end
51+
exit $global:_EXITCODE

dist/bin/scalac.bat

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,95 +11,19 @@ for %%f in ("%~dp0.") do (
1111
@rem get rid of the trailing slash
1212
set "_PROG_HOME=!_PROG_HOME:~0,-1!"
1313
)
14-
call "%_PROG_HOME%\bin\common.bat"
15-
if not %_EXITCODE%==0 goto end
16-
17-
call :args %*
1814

1915
@rem #########################################################################
20-
@rem ## Main
21-
22-
call :compilerJavaClasspathArgs
23-
24-
@rem we need to escape % in the java command path, for some reason this doesnt work in common.bat
25-
set "_JAVACMD=!_JAVACMD:%%=%%%%!"
16+
@rem ## Call the new PowerShell script with arguments
2617

27-
call "%_JAVACMD%" %_JAVA_ARGS% -classpath "%_JVM_CP_ARGS%" "-Dscala.usejavacp=true" "-Dscala.expandjavacp=true" "-Dscala.home=%_PROG_HOME%" dotty.tools.MainGenericCompiler %_SCALA_ARGS%
18+
set "args=%*"
19+
call powershell.exe -ExecutionPolicy Bypass -File "%_PROG_HOME%\bin\scalac.ps1" -ArgumentList "%args%"
2820
if not %ERRORLEVEL%==0 (
2921
set _EXITCODE=1
3022
goto end
3123
)
32-
goto end
33-
34-
@rem #########################################################################
35-
@rem ## Subroutines
36-
37-
:args
38-
set _JAVA_ARGS=
39-
set _SCALA_ARGS=
40-
set _SCALA_CPATH=
41-
@rem replace inner while loop used in bash script
42-
set _CONSUME_REMAINING=
43-
44-
:args_loop
45-
if "%~1"=="" goto args_done
46-
set "__ARG=%~1"
47-
if defined _CONSUME_REMAINING (
48-
set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%"
49-
shift
50-
) else if "%__ARG%"=="--" (
51-
@rem pass all remaining arguments to scala, e.g. to avoid interpreting them here as -D or -J
52-
set _CONSUME_REMAINING=1
53-
set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%"
54-
shift
55-
) else if "%__ARG%"=="-script" (
56-
@rem pass all remaining arguments to scala, e.g. to avoid interpreting them here as -D or -J
57-
set _CONSUME_REMAINING=1
58-
set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%"
59-
shift
60-
) else if "%__ARG%"=="-Oshort" (
61-
@rem optimize for short-running applications, see https://github.com/scala/scala3/issues/222
62-
set _JAVA_ARGS=!_JAVA_ARGS! "-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1"
63-
set _SCALA_ARGS=!_SCALA_ARGS! -Oshort
64-
shift
65-
) else if "%__ARG:~0,2%"=="-D" (
66-
@rem pass to scala as well: otherwise we lose it sometimes when we
67-
@rem need it, e.g. communicating with a server compiler.
68-
set _JAVA_ARGS=!_JAVA_ARGS! "%__ARG%"
69-
set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%"
70-
) else if "%__ARG:~0,2%"=="-J" (
71-
@rem as with -D, pass to scala even though it will almost
72-
@rem never be used.
73-
set _JAVA_ARGS=!_JAVA_ARGS! %__ARG:~2%
74-
set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%"
75-
) else if "%__ARG%"=="-classpath" (
76-
set "_SCALA_CPATH=%~2"
77-
shift
78-
) else if "%__ARG%"=="-cp" (
79-
set "_SCALA_CPATH=%~2"
80-
shift
81-
) else (
82-
set _SCALA_ARGS=!_SCALA_ARGS! "%__ARG%"
83-
)
84-
shift
85-
goto args_loop
86-
:args_done
87-
goto :eof
88-
89-
@rem output parameter: _JVM_CP_ARGS
90-
:compilerJavaClasspathArgs
91-
set "__TOOLCHAIN=%_LIB_DIR%\scala.jar"
92-
set "__TOOLCHAIN=%__TOOLCHAIN%%_PSEP%%_LIB_DIR%\with_compiler.jar%"
93-
94-
if defined _SCALA_CPATH (
95-
set "_JVM_CP_ARGS=%__TOOLCHAIN%%_SCALA_CPATH%"
96-
) else (
97-
set "_JVM_CP_ARGS=%__TOOLCHAIN%"
98-
)
99-
goto :eof
10024

10125
@rem #########################################################################
102-
@rem ## Cleanups
26+
@rem ## Main (if needed to continue batch processing after the PowerShell script)
10327

10428
:end
10529
exit /b %_EXITCODE%

0 commit comments

Comments
 (0)