Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed May 20, 2022
1 parent be701d4 commit a117aff
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
29 changes: 11 additions & 18 deletions compiler/src/dotty/tools/MainGenericCompiler.scala
Expand Up @@ -101,16 +101,14 @@ 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 =>
process(Nil, settings
.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 =>
Expand All @@ -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))
Expand Down
31 changes: 16 additions & 15 deletions compiler/src/dotty/tools/MainGenericRunner.scala
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dist/bin/scala
Expand Up @@ -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*)
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions dist/bin/scalac
Expand Up @@ -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*)
Expand All @@ -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
Expand Down

0 comments on commit a117aff

Please sign in to comment.