diff --git a/compiler/src/dotty/tools/MainGenericCompiler.scala b/compiler/src/dotty/tools/MainGenericCompiler.scala index 0297cfd42a49..aa924a237f73 100644 --- a/compiler/src/dotty/tools/MainGenericCompiler.scala +++ b/compiler/src/dotty/tools/MainGenericCompiler.scala @@ -101,8 +101,6 @@ object MainGenericCompiler { process(tail, settings.withScalaArgs("-verbose")) case ("-q" | "-quiet") :: tail => process(tail, settings.withQuiet) - case "-Oshort" :: tail => - process(tail, settings.withJavaArgs("-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1")) case "-repl" :: tail => process(tail, settings.withCompileMode(CompileMode.Repl)) case "-script" :: targetScript :: tail => @@ -110,7 +108,7 @@ object MainGenericCompiler { .withCompileMode(CompileMode.Script) .withJavaProps("script.path" -> targetScript) .withTargetScript(targetScript) - .withScriptArgs(tail.toList*)) + .withScriptArgs(tail*)) case "-compile" :: tail => process(tail, settings.withCompileMode(CompileMode.Compile)) case "-decompile" :: tail => @@ -126,23 +124,18 @@ object MainGenericCompiler { case "-with-compiler" :: tail => process(tail, settings.withCompiler) case ("-cp" | "-classpath" | "--class-path") :: cp :: tail => - val cpEntries = cp.split(classpathSeparator).toList - val singleEntryClasspath: Boolean = cpEntries.sizeIs == 1 - val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic - def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip"))) - val (tailargs, newEntries) = if singleEntryClasspath && validGlobbedJar(cpEntries.head) then - // reassemble globbed wildcard classpath - // globdir is wildcard directory for globbed jar files, reconstruct the intended classpath - val cpJars = tail.takeWhile( f => validGlobbedJar(f) ) - val remainingArgs = tail.drop(cpJars.size) - (remainingArgs, cpEntries ++ cpJars) - else - (tail, cpEntries) - + val (tailargs, newEntries) = MainGenericRunner.processClasspath(cp, tail) process(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty))) - case (o @ javaOption(stripped)) :: tail => + case "-Oshort" :: tail => + // Nothing is to be done here. Request that the user adds the relevant flags manually. + // i.e this has no effect when MainGenericRunner is invoked programatically. + val addTC="-XX:+TieredCompilation" + val tStopAtLvl="-XX:TieredStopAtLevel=1" + println(s"ignoring deprecated -Oshort flag, please add `-J$addTC` and `-J$tStopAtLvl` flags manually") + process(tail, settings) + case javaOption(stripped) :: tail => process(tail, settings.withJavaArgs(stripped)) - case (javaPropOption(opt, value)) :: tail => + case javaPropOption(opt, value) :: tail => process(tail, settings.withJavaProps(opt -> value)) case arg :: tail => process(tail, settings.withResidualArgs(arg)) diff --git a/compiler/src/dotty/tools/MainGenericRunner.scala b/compiler/src/dotty/tools/MainGenericRunner.scala index dca7178c52f5..1dcab2d92a96 100644 --- a/compiler/src/dotty/tools/MainGenericRunner.scala +++ b/compiler/src/dotty/tools/MainGenericRunner.scala @@ -100,6 +100,20 @@ object MainGenericRunner { val classpathSeparator = File.pathSeparator + def processClasspath(cp: String, tail: List[String]): (List[String], List[String]) = + val cpEntries = cp.split(classpathSeparator).toList + val singleEntryClasspath: Boolean = cpEntries.take(2).size == 1 + val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic + def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip"))) + if singleEntryClasspath && validGlobbedJar(cpEntries.head) then + // reassemble globbed wildcard classpath + // globdir is wildcard directory for globbed jar files, reconstruct the intended classpath + val cpJars = tail.takeWhile( f => validGlobbedJar(f) ) + val remainingArgs = tail.drop(cpJars.size) + (remainingArgs, cpEntries ++ cpJars) + else + (tail, cpEntries) + @sharable val javaOption = raw"""-J(.*)""".r @sharable val scalaOption = raw"""@.*""".r @sharable val colorOption = raw"""-color:.*""".r @@ -110,21 +124,8 @@ object MainGenericRunner { case "-run" :: fqName :: tail => process(tail, settings.withExecuteMode(ExecuteMode.Run).withTargetToRun(fqName)) case ("-cp" | "-classpath" | "--class-path") :: cp :: tail => - val cpEntries = cp.split(classpathSeparator).toList - val singleEntryClasspath: Boolean = cpEntries.take(2).size == 1 - val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic - def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip"))) - val (tailargs, newEntries) = if singleEntryClasspath && validGlobbedJar(cpEntries.head) then - // reassemble globbed wildcard classpath - // globdir is wildcard directory for globbed jar files, reconstruct the intended classpath - val cpJars = tail.takeWhile( f => validGlobbedJar(f) ) - val remainingArgs = tail.drop(cpJars.size) - (remainingArgs, cpEntries ++ cpJars) - else - (tail, cpEntries) - + val (tailargs, newEntries) = processClasspath(cp, tail) process(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty))) - case ("-version" | "--version") :: _ => settings.copy( executeMode = ExecuteMode.Repl, @@ -170,7 +171,7 @@ object MainGenericRunner { val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun process(tail, newSettings.withResidualArgs(arg)) end process - + def main(args: Array[String]): Unit = val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" ")).filter(_.nonEmpty) val allArgs = scalaOpts ++ args diff --git a/dist/bin/scala b/dist/bin/scala index b3116b2706b3..d99fb24308d0 100755 --- a/dist/bin/scala +++ b/dist/bin/scala @@ -33,9 +33,9 @@ while [[ $# -gt 0 ]]; do -D*) # pass to scala as well: otherwise we lose it sometimes when we # need it, e.g. communicating with a server compiler. + # respect user-supplied -Dscala.usejavacp addJava "$1" addScala "$1" - # respect user-supplied -Dscala.usejavacp shift ;; -J*) @@ -47,7 +47,7 @@ while [[ $# -gt 0 ]]; do ;; -classpath*) if [ "$1" != "${1##* }" ]; then - # hashbang-combined args "-classpath 'lib/*'" + # -classpath and its value have been supplied in a single string e.g. "-classpath 'lib/*'" A=$1 ; shift # consume $1 before adding its substrings back set -- $A "$@" # split $1 on whitespace and put it back else diff --git a/dist/bin/scalac b/dist/bin/scalac index d490d3d48c12..11da4fdedc34 100644 --- a/dist/bin/scalac +++ b/dist/bin/scalac @@ -32,12 +32,24 @@ source "$PROG_HOME/bin/common" while [[ $# -gt 0 ]]; do case "$1" in + --) + # pass all remaining arguments to scala, e.g. to avoid interpreting them here as -D or -J + while [[ $# -gt 0 ]]; do addScala "$1" && shift ; done + ;; + -script) + # pass all remaining arguments to scala, e.g. to avoid interpreting them here as -D or -J + while [[ $# -gt 0 ]]; do addScala "$1" && shift ; done + ;; + # Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222 + -Oshort) + addScala "-Oshort" && \ + addJava "-XX:+TieredCompilation" && addJava "-XX:TieredStopAtLevel=1" && shift ;; -D*) # pass to scala as well: otherwise we lose it sometimes when we # need it, e.g. communicating with a server compiler. + # respect user-supplied -Dscala.usejavacp addJava "$1" addScala "$1" - # respect user-supplied -Dscala.usejavacp shift ;; -J*) @@ -49,7 +61,7 @@ while [[ $# -gt 0 ]]; do ;; -classpath*) if [ "$1" != "${1##* }" ]; then - # hashbang-combined args "-classpath 'lib/*'" + # -classpath and its value have been supplied in a single string e.g. "-classpath 'lib/*'" A=$1 ; shift # consume $1 before adding its substrings back set -- $A "$@" # split $1 on whitespace and put it back else