-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"sbt '++ 2.13.0-M2!' compile" does not work with sbt 1.0.0
* add new compiler bridge
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
internal/compiler-bridge/src/main/scala_2.13+/xsbt/ConsoleInterface.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright 2011 - 2017, Lightbend, Inc. | ||
* Copyright 2008 - 2010, Mark Harrah | ||
* This software is released under the terms written in LICENSE. | ||
*/ | ||
|
||
package xsbt | ||
|
||
import xsbti.Logger | ||
import scala.tools.nsc.interpreter.shell.{ ILoop, IMain, InteractiveReader } | ||
import scala.tools.nsc.reporters.Reporter | ||
import scala.tools.nsc.{ GenericRunnerCommand, Settings } | ||
|
||
class ConsoleInterface { | ||
def commandArguments( | ||
args: Array[String], | ||
bootClasspathString: String, | ||
classpathString: String, | ||
log: Logger | ||
): Array[String] = | ||
MakeSettings.sync(args, bootClasspathString, classpathString, log).recreateArgs.toArray[String] | ||
|
||
def run( | ||
args: Array[String], | ||
bootClasspathString: String, | ||
classpathString: String, | ||
initialCommands: String, | ||
cleanupCommands: String, | ||
loader: ClassLoader, | ||
bindNames: Array[String], | ||
bindValues: Array[Any], | ||
log: Logger | ||
): Unit = { | ||
lazy val interpreterSettings = MakeSettings.sync(args.toList, log) | ||
val compilerSettings = MakeSettings.sync(args, bootClasspathString, classpathString, log) | ||
|
||
log.info(Message("Starting scala interpreter...")) | ||
log.info(Message("")) | ||
|
||
val loop = new ILoop { | ||
override def createInterpreter() = { | ||
if (loader ne null) { | ||
in = InteractiveReader.apply() | ||
intp = new IMain(settings) { | ||
override protected def parentClassLoader = | ||
if (loader eq null) super.parentClassLoader else loader | ||
|
||
override protected def newCompiler(settings: Settings, reporter: Reporter) = | ||
super.newCompiler(compilerSettings, reporter) | ||
} | ||
intp.setContextClassLoader() | ||
} else | ||
super.createInterpreter() | ||
|
||
for ((id, value) <- bindNames zip bindValues) | ||
intp.beQuietDuring(intp.bind(id, value.asInstanceOf[AnyRef].getClass.getName, value)) | ||
|
||
if (!initialCommands.isEmpty) | ||
intp.interpret(initialCommands) | ||
|
||
() | ||
} | ||
|
||
override def closeInterpreter(): Unit = { | ||
if (!cleanupCommands.isEmpty) | ||
intp.interpret(cleanupCommands) | ||
super.closeInterpreter() | ||
} | ||
} | ||
|
||
loop.process(if (loader eq null) compilerSettings else interpreterSettings) | ||
|
||
() | ||
} | ||
} | ||
|
||
object MakeSettings { | ||
def apply(args: List[String], log: Logger): Settings = { | ||
val command = new GenericRunnerCommand(args, message => log.error(Message(message))) | ||
if (command.ok) | ||
command.settings | ||
else | ||
throw new InterfaceCompileFailed(Array(), Array(), command.usageMsg) | ||
} | ||
|
||
def sync( | ||
args: Array[String], | ||
bootClasspathString: String, | ||
classpathString: String, | ||
log: Logger | ||
): Settings = { | ||
val compilerSettings = sync(args.toList, log) | ||
if (!bootClasspathString.isEmpty) | ||
compilerSettings.bootclasspath.value = bootClasspathString | ||
compilerSettings.classpath.value = classpathString | ||
compilerSettings | ||
} | ||
|
||
def sync(options: List[String], log: Logger): Settings = { | ||
val settings = apply(options, log) | ||
settings.Yreplsync.value = true | ||
settings | ||
} | ||
} |