Skip to content

Commit eda3104

Browse files
committed
refine globbed classpath test to distinguish jars from dirs
1 parent 275deea commit eda3104

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,20 @@ 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-
val globdir = cp.replaceAll("[\\\\/][^\\\\/]*$", "") // slash/backslash agnostic
109-
val (tailargs, cpstr) = if globdir.nonEmpty && !cp.contains(classpathSeparator) then
108+
val cpEntries = cp.split(classpathSeparator).toList
109+
val singleEntryClasspath: Boolean = cpEntries.nonEmpty && cpEntries.drop(1).isEmpty
110+
val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic
111+
def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip")))
112+
val (tailargs, newEntries) = if singleEntryClasspath && validGlobbedJar(cpEntries.head) then
113+
// reassemble globbed wildcard classpath
110114
// globdir is wildcard directory for globbed jar files, reconstruct the intended classpath
111-
val jarfiles = cp :: tail
112-
val cpfiles = jarfiles.takeWhile( f => f.startsWith(globdir) && ((f.toLowerCase.endsWith(".jar") || f.endsWith(".zip"))) )
113-
val tailargs = jarfiles.drop(cpfiles.size)
114-
(tailargs, cpfiles.mkString(classpathSeparator))
115+
val cpJars = tail.takeWhile( f => validGlobbedJar(f) )
116+
val remainingArgs = tail.drop(cpJars.size)
117+
(remainingArgs, cpEntries ++ cpJars)
115118
else
116-
(tail, cp)
117-
118-
process(tailargs, settings.copy(classPath = settings.classPath ++ cpstr.split(classpathSeparator).filter(_.nonEmpty)))
119+
(tail, cpEntries)
120+
121+
process(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty)))
119122

120123
case ("-version" | "--version") :: _ =>
121124
settings.copy(
@@ -240,4 +243,22 @@ object MainGenericRunner {
240243
e.foreach(_.printStackTrace())
241244
!isFailure
242245
}
246+
247+
def display(settings: Settings)= Seq(
248+
s"verbose: ${settings.verbose}",
249+
s"classPath: ${settings.classPath.mkString("\n ","\n ","")}",
250+
s"executeMode: ${settings.executeMode}",
251+
s"exitCode: ${settings.exitCode}",
252+
s"javaArgs: ${settings.javaArgs}",
253+
s"scalaArgs: ${settings.scalaArgs}",
254+
s"residualArgs: ${settings.residualArgs}",
255+
s"possibleEntryPaths: ${settings.possibleEntryPaths}",
256+
s"scriptArgs: ${settings.scriptArgs}",
257+
s"targetScript: ${settings.targetScript}",
258+
s"targetToRun: ${settings.targetToRun}",
259+
s"save: ${settings.save}",
260+
s"modeShouldBePossibleRun: ${settings.modeShouldBePossibleRun}",
261+
s"modeShouldBeRun: ${settings.modeShouldBeRun}",
262+
s"compiler: ${settings.compiler}",
263+
)
243264
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ class BashScriptsTests:
9797
printf("===> verify SCALA_OPTS='@argsfile' is properly handled by `dist/bin/scala`\n")
9898
val envPairs = List(("SCALA_OPTS", s"@$argsfile"))
9999
val (validTest, exitCode, stdout, stderr) = bashCommand(scriptFile.absPath, envPairs)
100+
printf("stdout: %s\n", stdout.mkString("\n","\n",""))
100101
if validTest then
101-
val expected = s"${workingDirectory.toString}"
102-
val List(line1: String, line2: String) = stdout.take(2)
103-
printf("line1 [%s]\n", line1)
104-
val valid = line2.dropWhile( _ != ' ').trim.startsWith(expected)
102+
val expected = s"${workingDirectory.norm}"
103+
val output = stdout.find( _.trim.startsWith("cwd") ).getOrElse("").dropWhile(_!=' ').trim
104+
printf("output [%s]\n", output)
105+
printf("expected[%s]\n", expected)
106+
val valid = output.startsWith(expected)
105107
if valid then printf(s"\n===> success: classpath begins with %s, as reported by [%s]\n", workingDirectory, scriptFile.getName)
106108
assert(valid, s"script ${scriptFile.absPath} did not report valid java.class.path first entry")
107109

0 commit comments

Comments
 (0)