Skip to content

Commit bca59cc

Browse files
committed
SI-9396 Runner computes path only once
Change the classpath URL list in the runner settings to a lazy val. Also clean up PathResolver's use of settings.classpath so that the default is defined in one place, namely in settings, where it can also be overridden. The previous definition in both places was the same, namely, `sys.env.getOrElse("CLASSPATH", ".")`, but the history of the code path is fraught.
1 parent a6261ef commit bca59cc

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

src/compiler/scala/tools/nsc/GenericRunnerSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.net.URL
99
import scala.tools.util.PathResolverFactory
1010

1111
class GenericRunnerSettings(error: String => Unit) extends Settings(error) {
12-
def classpathURLs: Seq[URL] = PathResolverFactory.create(this).resultAsURLs
12+
lazy val classpathURLs: Seq[URL] = PathResolverFactory.create(this).resultAsURLs
1313

1414
val howtorun =
1515
ChoiceSetting(

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ trait ScalaSettings extends AbsScalaSettings
2222
/** Set of settings */
2323
protected[scala] lazy val allSettings = mutable.HashSet[Setting]()
2424

25-
/** Against my better judgment, giving in to martin here and allowing
26-
* CLASSPATH to be used automatically. So for the user-specified part
27-
* of the classpath:
28-
*
29-
* - If -classpath or -cp is given, it is that
30-
* - Otherwise, if CLASSPATH is set, it is that
31-
* - If neither of those, then "." is used.
25+
/** The user class path, specified by `-classpath` or `-cp`,
26+
* defaults to the value of CLASSPATH env var if it is set, as in Java,
27+
* or else to `"."` for the current user directory.
3228
*/
3329
protected def defaultClasspath = sys.env.getOrElse("CLASSPATH", ".")
3430

src/compiler/scala/tools/util/PathResolver.scala

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,7 @@ abstract class PathResolverBase[BaseClassPathType <: ClassFileLookup[AbstractFil
254254
* TODO: we should refactor this as a separate -bootstrap option to have a clean implementation, no? */
255255
def sourcePath = if (!settings.isScaladoc) cmdLineOrElse("sourcepath", Defaults.scalaSourcePath) else ""
256256

257-
/** Against my better judgment, giving in to martin here and allowing
258-
* CLASSPATH to be used automatically. So for the user-specified part
259-
* of the classpath:
260-
*
261-
* - If -classpath or -cp is given, it is that
262-
* - Otherwise, if CLASSPATH is set, it is that
263-
* - If neither of those, then "." is used.
264-
*/
265-
def userClassPath =
266-
if (!settings.classpath.isDefault) settings.classpath.value
267-
else sys.env.getOrElse("CLASSPATH", ".")
257+
def userClassPath = settings.classpath.value // default is specified by settings and can be overridden there
268258

269259
import classPathFactory._
270260

0 commit comments

Comments
 (0)