-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #453 from eed3si9n/wip/213-compiler-bridge
"sbt '++ 2.13.0-M2!' compile" does not work with sbt 1.0.0
- Loading branch information
Showing
35 changed files
with
387 additions
and
34 deletions.
There are no files selected for viewing
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,43 @@ | ||
#!/bin/bash | ||
|
||
# This is a hack to validate the compilation of 2.13 compiler bridge without using sbt, | ||
# which was used for bootstrapping the initial compiler bridge. | ||
# In the future when Scala compiler breaks source compatibility, this script might come in handy. | ||
|
||
# $ export SCALA_X_HOME=/usr/local/Cellar/[email protected]/2.13.0-M2 | ||
|
||
if [[ -z "$SCALA_X_HOME" ]]; then | ||
echo "SCALA_X_HOME is not set!" 1>&2 | ||
echo "Run 'export SCALA_X_HOME=/usr/local/Cellar/[email protected]/2.13.0-M2' or equivalent." | ||
exit 1 | ||
fi | ||
|
||
mkdir -p target/compiler-bridge/ | ||
|
||
"$SCALA_X_HOME/bin/scalac" \ | ||
-nowarn \ | ||
-classpath $HOME/.ivy2/cache/org.scala-sbt/compiler-interface/jars/compiler-interface-1.0.3.jar:$HOME/.ivy2/cache/org.scala-sbt/util-interface/jars/util-interface-1.0.2.jar \ | ||
-d target/compiler-bridge/ \ | ||
internal/compiler-bridge/src/main/scala/xsbt/API.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/DelegatingReporter.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/InteractiveConsoleInterface.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/ScaladocInterface.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/Analyzer.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/InteractiveConsoleResponse.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/CallbackGlobal.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/JavaUtils.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/ClassName.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/ExtractUsedNames.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/LocalToNonLocalClass.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/Command.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/GlobalHelpers.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/LocateClassFile.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/CompilerInterface.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/InteractiveConsoleFactory.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/Log.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/InteractiveConsoleHelper.scala \ | ||
internal/compiler-bridge/src/main/scala/xsbt/Message.scala \ | ||
internal/compiler-bridge/src/main/scala_2.13/xsbt/Compat.scala \ | ||
internal/compiler-bridge/src/main/scala_2.13/xsbt/ConsoleInterface.scala |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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
File renamed without changes.
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
105 changes: 105 additions & 0 deletions
105
internal/compiler-bridge/src/main/scala_2.11-12/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.{ ILoop, IMain, InteractiveReader, NamedParam } | ||
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.quietBind(NamedParam.clazz(id, 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 | ||
} | ||
} |
Oops, something went wrong.