Skip to content

Commit

Permalink
Precompile -i files for script runner
Browse files Browse the repository at this point in the history
This enables `scala -howtorun:script -i t4033b.scala -- t4033.scala`
where the main script depends on utility code in the `-i` files.
  • Loading branch information
som-snytt authored and lrytz committed Sep 3, 2019
1 parent 8c9bafd commit 8670a09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/compiler/scala/tools/nsc/Global.scala
Expand Up @@ -38,7 +38,7 @@ import scala.tools.nsc.symtab.{Flags, SymbolTable, SymbolTrackers}
import scala.tools.nsc.transform._
import scala.tools.nsc.transform.patmat.PatternMatching
import scala.tools.nsc.typechecker._
import scala.tools.nsc.util.{ClassPath, returning}
import scala.tools.nsc.util.ClassPath

class Global(var currentSettings: Settings, reporter0: Reporter)
extends SymbolTable
Expand Down Expand Up @@ -1604,8 +1604,11 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
val snap = profiler.beforePhase(Global.InitPhase)

val sources: List[SourceFile] =
if (settings.script.isSetByUser && filenames.size > 1) returning(Nil)(_ => globalError("can only compile one script at a time"))
else filenames map getSourceFile
if (settings.script.isSetByUser && filenames.size > 1) {
globalError("can only compile one script at a time")
Nil
}
else filenames.map(getSourceFile)

profiler.afterPhase(Global.InitPhase, snap)
compileSources(sources)
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/scala/tools/nsc/ScriptRunner.scala
Expand Up @@ -57,12 +57,12 @@ trait ScriptRunner {

class DefaultScriptRunner(settings: GenericRunnerSettings) extends AbstractScriptRunner(settings) {
protected def doCompile(scriptFile: String) = {
// Setting settings.script.value informs the compiler this is not a self-contained compilation unit.
settings.script.value = mainClass
val reporter = new ConsoleReporter(settings)
val compiler = newGlobal(settings, reporter)
val run = new compiler.Run
run.compile(List(scriptFile))
if (settings.pastefiles.value.nonEmpty) new compiler.Run().compile(settings.pastefiles.value)
// Setting settings.script.value informs the compiler this is not a self-contained compilation unit.
settings.script.value = mainClass
new compiler.Run().compile(scriptFile :: Nil)
!reporter.hasErrors
}

Expand Down

0 comments on commit 8670a09

Please sign in to comment.