Skip to content

Commit 8104575

Browse files
committed
resolve Windows classpath regression in MainGenericRunner rather than dist/bin/scala
1 parent f1f8b7b commit 8104575

File tree

4 files changed

+25
-36
lines changed

4 files changed

+25
-36
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,17 @@ object MainGenericRunner {
105105
case "-run" :: fqName :: tail =>
106106
process(tail, settings.withExecuteMode(ExecuteMode.Run).withTargetToRun(fqName))
107107
case ("-cp" | "-classpath" | "--class-path") :: cp :: tail =>
108-
process(tail, settings.copy(classPath = settings.classPath.appended(cp)))
108+
val (tailargs, cpstr) = if classpathSeparator != ';' || cp.contains(classpathSeparator) then
109+
(tail, cp)
110+
else
111+
val globdir = cp.replace('\\', '/').replaceAll("/[^/]*$","")
112+
val jarfiles = cp :: tail
113+
val cpfiles = jarfiles.takeWhile( f => f.startsWith(globdir) && ((f.toLowerCase.endsWith(".jar") || f.endsWith(".zip"))) )
114+
val tailargs = jarfiles.drop(cpfiles.size)
115+
(tailargs, cpfiles.mkString(classpathSeparator))
116+
117+
process(tailargs, settings.copy(classPath = settings.classPath.appended(cpstr)))
118+
109119
case ("-version" | "--version") :: _ =>
110120
settings.copy(
111121
executeMode = ExecuteMode.Repl,
@@ -141,6 +151,13 @@ object MainGenericRunner {
141151
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
142152
process(tail, newSettings.withResidualArgs(arg))
143153

154+
// collect globbed classpath entries
155+
def collectGlobbedEntries(entries: List[String]): (List[String], List[String]) = {
156+
val cpfiles = entries.takeWhile( f => (f.toLowerCase.endsWith(".jar") || f.endsWith(".zip")) )
157+
val remainder = entries.drop(cpfiles.size)
158+
(cpfiles, remainder)
159+
}
160+
144161
def main(args: Array[String]): Unit =
145162
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" "))
146163
val allArgs = scalaOpts ++ args
@@ -155,7 +172,7 @@ object MainGenericRunner {
155172
repl.Main.main(properArgs.toArray)
156173

157174
case ExecuteMode.PossibleRun =>
158-
val newClasspath = (settings.classPath :+ ".").map(File(_).toURI.toURL)
175+
val newClasspath = (settings.classPath :+ ".").flatMap(_.split(classpathSeparator).filter(_.nonEmpty)).map(File(_).toURI.toURL)
159176
import dotty.tools.runner.RichClassLoader._
160177
val newClassLoader = ScalaClassLoader.fromURLsParallelCapable(newClasspath)
161178
val targetToRun = settings.possibleEntryPaths.to(LazyList).find { entryPath =>
@@ -177,8 +194,7 @@ object MainGenericRunner {
177194
cp.filterNot(c => compilerLibs.exists(c.contains))
178195
else
179196
cp
180-
val newClasspath = (settings.classPath ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL)
181-
197+
val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL)
182198
val res = ObjectRunner.runAndCatch(newClasspath, settings.targetToRun, settings.residualArgs).flatMap {
183199
case ex: ClassNotFoundException if ex.getMessage == settings.targetToRun =>
184200
val file = settings.targetToRun
@@ -192,7 +208,6 @@ object MainGenericRunner {
192208
errorFn("", res)
193209
case ExecuteMode.Script =>
194210
val targetScriptPath: String = settings.targetScript.toString.replace('\\', '/')
195-
System.setProperty("script.path", targetScriptPath)
196211
val properArgs =
197212
List("-classpath", settings.classPath.mkString(classpathSeparator)).filter(Function.const(settings.classPath.nonEmpty))
198213
++ settings.residualArgs

compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class CoursierScalaTests:
130130
val argsFile = new File(getClass.getResource("/run/myargs.txt").getPath)
131131
val output = CoursierScalaTests.csScalaCmd(s"@$argsFile", source.absPath)
132132
assertEquals(output.mkString("\n"), "Hello")
133+
argumentFile()
133134

134135
object CoursierScalaTests:
135136

compiler/test/dotty/tools/scripting/ClasspathTests.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ lazy val env:Map[String, String] = System.getenv.asScala.toMap
7676
// script output expected as "<tag>: <value>"
7777
def findTaggedLine(tag: String, lines: Seq[String]): String =
7878
lines.find { _.startsWith(tag) } match
79-
case None => sys.error(s"no $tag: found in script output")
79+
case None =>
80+
lines.foreach { System.err.printf("line[%s]\n", _) }
81+
sys.error(s"no $tag: found in script output")
8082
case Some(cwd) => cwd.dropWhile( _ != ' ').trim // discard tag
8183

8284
def exec(cmd: String *): Seq[String] = Process(cmd).lazyLines_!.toList

dist/bin/scala

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,10 @@ fi
2828

2929
source "$PROG_HOME/bin/common"
3030

31-
case `uname` in
32-
CYG*|MINGW*|MSYS*) PSEP=';' ;;
33-
*) PSEP=':' ;;
34-
esac
35-
36-
ARGS=()
37-
while [ $# -gt 0 ]; do
38-
case "$1" in
39-
-cp | -classpath) # partial fix for #10761
40-
# passed as two arguments, e.g. '-classpath' 'lib/*'
41-
ARGS+=($1)
42-
ARGS+=("$2${PSEP}")
43-
shift
44-
shift
45-
;;
46-
-cp*|-classpath*) # partial fix for #10761
47-
# passed as a single argument, e.g. '-classpath lib/*'
48-
# (hashbang line can glom args together)
49-
ARGS+=('-classpath')
50-
ARGS+=("\"${1#* *}${PSEP}\"")
51-
shift
52-
;;
53-
*)
54-
ARGS+=($1)
55-
shift
56-
;;
57-
esac
58-
done
59-
6031
# exec here would prevent onExit from being called, leaving terminal in unusable state
6132
compilerJavaClasspathArgs
6233
[ -z "${ConEmuPID-}" -o -n "${cygwin-}" ] && export MSYSTEM= PWD= # workaround for #12405
63-
eval "\"$JAVACMD\"" "-classpath \"$jvm_cp_args\"" "dotty.tools.MainGenericRunner" "-classpath \"$jvm_cp_args\"" "${ARGS[@]}"
34+
eval "\"$JAVACMD\"" "-classpath \"$jvm_cp_args\"" "dotty.tools.MainGenericRunner" "-classpath \"$jvm_cp_args\"" "$@"
6435
scala_exit_status=$?
6536

6637

0 commit comments

Comments
 (0)