Skip to content

Commit 98d5f9d

Browse files
committed
address review comments
1 parent 9b195b7 commit 98d5f9d

File tree

5 files changed

+45
-37
lines changed

5 files changed

+45
-37
lines changed

compiler/src/dotty/tools/MainGenericCompiler.scala

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,14 @@ object MainGenericCompiler {
101101
process(tail, settings.withScalaArgs("-verbose"))
102102
case ("-q" | "-quiet") :: tail =>
103103
process(tail, settings.withQuiet)
104-
case "-Oshort" :: tail =>
105-
process(tail, settings.withJavaArgs("-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1"))
106104
case "-repl" :: tail =>
107105
process(tail, settings.withCompileMode(CompileMode.Repl))
108106
case "-script" :: targetScript :: tail =>
109107
process(Nil, settings
110108
.withCompileMode(CompileMode.Script)
111109
.withJavaProps("script.path" -> targetScript)
112110
.withTargetScript(targetScript)
113-
.withScriptArgs(tail.toList*))
111+
.withScriptArgs(tail*))
114112
case "-compile" :: tail =>
115113
process(tail, settings.withCompileMode(CompileMode.Compile))
116114
case "-decompile" :: tail =>
@@ -126,23 +124,18 @@ object MainGenericCompiler {
126124
case "-with-compiler" :: tail =>
127125
process(tail, settings.withCompiler)
128126
case ("-cp" | "-classpath" | "--class-path") :: cp :: tail =>
129-
val cpEntries = cp.split(classpathSeparator).toList
130-
val singleEntryClasspath: Boolean = cpEntries.sizeIs == 1
131-
val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic
132-
def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip")))
133-
val (tailargs, newEntries) = if singleEntryClasspath && validGlobbedJar(cpEntries.head) then
134-
// reassemble globbed wildcard classpath
135-
// globdir is wildcard directory for globbed jar files, reconstruct the intended classpath
136-
val cpJars = tail.takeWhile( f => validGlobbedJar(f) )
137-
val remainingArgs = tail.drop(cpJars.size)
138-
(remainingArgs, cpEntries ++ cpJars)
139-
else
140-
(tail, cpEntries)
141-
127+
val (tailargs, newEntries) = MainGenericRunner.processClasspath(cp, tail)
142128
process(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty)))
143-
case (o @ javaOption(stripped)) :: tail =>
129+
case "-Oshort" :: tail =>
130+
// Nothing is to be done here. Request that the user adds the relevant flags manually.
131+
// i.e this has no effect when MainGenericRunner is invoked programatically.
132+
val addTC="-XX:+TieredCompilation"
133+
val tStopAtLvl="-XX:TieredStopAtLevel=1"
134+
println(s"ignoring deprecated -Oshort flag, please add `-J$addTC` and `-J$tStopAtLvl` flags manually")
135+
process(tail, settings)
136+
case javaOption(stripped) :: tail =>
144137
process(tail, settings.withJavaArgs(stripped))
145-
case (javaPropOption(opt, value)) :: tail =>
138+
case javaPropOption(opt, value) :: tail =>
146139
process(tail, settings.withJavaProps(opt -> value))
147140
case arg :: tail =>
148141
process(tail, settings.withResidualArgs(arg))

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ object MainGenericRunner {
100100

101101
val classpathSeparator = File.pathSeparator
102102

103+
def processClasspath(cp: String, tail: List[String]): (List[String], List[String]) =
104+
val cpEntries = cp.split(classpathSeparator).toList
105+
val singleEntryClasspath: Boolean = cpEntries.take(2).size == 1
106+
val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic
107+
def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip")))
108+
if singleEntryClasspath && validGlobbedJar(cpEntries.head) then
109+
// reassemble globbed wildcard classpath
110+
// globdir is wildcard directory for globbed jar files, reconstruct the intended classpath
111+
val cpJars = tail.takeWhile( f => validGlobbedJar(f) )
112+
val remainingArgs = tail.drop(cpJars.size)
113+
(remainingArgs, cpEntries ++ cpJars)
114+
else
115+
(tail, cpEntries)
116+
103117
@sharable val javaOption = raw"""-J(.*)""".r
104118
@sharable val scalaOption = raw"""@.*""".r
105119
@sharable val colorOption = raw"""-color:.*""".r
@@ -110,21 +124,8 @@ object MainGenericRunner {
110124
case "-run" :: fqName :: tail =>
111125
process(tail, settings.withExecuteMode(ExecuteMode.Run).withTargetToRun(fqName))
112126
case ("-cp" | "-classpath" | "--class-path") :: cp :: tail =>
113-
val cpEntries = cp.split(classpathSeparator).toList
114-
val singleEntryClasspath: Boolean = cpEntries.take(2).size == 1
115-
val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic
116-
def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip")))
117-
val (tailargs, newEntries) = if singleEntryClasspath && validGlobbedJar(cpEntries.head) then
118-
// reassemble globbed wildcard classpath
119-
// globdir is wildcard directory for globbed jar files, reconstruct the intended classpath
120-
val cpJars = tail.takeWhile( f => validGlobbedJar(f) )
121-
val remainingArgs = tail.drop(cpJars.size)
122-
(remainingArgs, cpEntries ++ cpJars)
123-
else
124-
(tail, cpEntries)
125-
127+
val (tailargs, newEntries) = processClasspath(cp, tail)
126128
process(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty)))
127-
128129
case ("-version" | "--version") :: _ =>
129130
settings.copy(
130131
executeMode = ExecuteMode.Repl,
@@ -170,7 +171,7 @@ object MainGenericRunner {
170171
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
171172
process(tail, newSettings.withResidualArgs(arg))
172173
end process
173-
174+
174175
def main(args: Array[String]): Unit =
175176
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" ")).filter(_.nonEmpty)
176177
val allArgs = scalaOpts ++ args

dist/bin/scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ while [[ $# -gt 0 ]]; do
3333
-D*)
3434
# pass to scala as well: otherwise we lose it sometimes when we
3535
# need it, e.g. communicating with a server compiler.
36+
# respect user-supplied -Dscala.usejavacp
3637
addJava "$1"
3738
addScala "$1"
38-
# respect user-supplied -Dscala.usejavacp
3939
shift
4040
;;
4141
-J*)
@@ -47,7 +47,7 @@ while [[ $# -gt 0 ]]; do
4747
;;
4848
-classpath*)
4949
if [ "$1" != "${1##* }" ]; then
50-
# hashbang-combined args "-classpath 'lib/*'"
50+
# -classpath and its value have been supplied in a single string e.g. "-classpath 'lib/*'"
5151
A=$1 ; shift # consume $1 before adding its substrings back
5252
set -- $A "$@" # split $1 on whitespace and put it back
5353
else

dist/bin/scalac

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,24 @@ source "$PROG_HOME/bin/common"
3232

3333
while [[ $# -gt 0 ]]; do
3434
case "$1" in
35+
--)
36+
# pass all remaining arguments to scala, e.g. to avoid interpreting them here as -D or -J
37+
while [[ $# -gt 0 ]]; do addScala "$1" && shift ; done
38+
;;
39+
-script)
40+
# pass all remaining arguments to scala, e.g. to avoid interpreting them here as -D or -J
41+
while [[ $# -gt 0 ]]; do addScala "$1" && shift ; done
42+
;;
43+
# Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222
44+
-Oshort)
45+
addScala "-Oshort" && \
46+
addJava "-XX:+TieredCompilation" && addJava "-XX:TieredStopAtLevel=1" && shift ;;
3547
-D*)
3648
# pass to scala as well: otherwise we lose it sometimes when we
3749
# need it, e.g. communicating with a server compiler.
50+
# respect user-supplied -Dscala.usejavacp
3851
addJava "$1"
3952
addScala "$1"
40-
# respect user-supplied -Dscala.usejavacp
4153
shift
4254
;;
4355
-J*)
@@ -49,7 +61,7 @@ while [[ $# -gt 0 ]]; do
4961
;;
5062
-classpath*)
5163
if [ "$1" != "${1##* }" ]; then
52-
# hashbang-combined args "-classpath 'lib/*'"
64+
# -classpath and its value have been supplied in a single string e.g. "-classpath 'lib/*'"
5365
A=$1 ; shift # consume $1 before adding its substrings back
5466
set -- $A "$@" # split $1 on whitespace and put it back
5567
else

project/Build.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ object Build {
248248
(Compile / resourceDirectory) := baseDirectory.value / "resources",
249249
(Test / resourceDirectory) := baseDirectory.value / "test-resources",
250250

251+
disableDocSetting,
252+
251253
// Prevent sbt from rewriting our dependencies
252254
scalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(false))),
253255

0 commit comments

Comments
 (0)