Fix classpath issues in static launcher

The launcher defines a top classloader that willbe used by all
`ScalaInstance`s. Previously, this top classloader had a parent that
contained the scala library 2.10, which prevented the correct
compilation of the compiler bridge for scala 2.11.

Also, we no longer need the scala-reflect JAR.
This commit is contained in:
Martin Duhem 2016-04-06 15:10:15 +02:00
parent b8472668ff
commit 88dd987d5f
3 changed files with 7 additions and 14 deletions

View File

@ -15,7 +15,6 @@ final case class IvyBridgeProvider(ivyConfiguration: IvyConfiguration, module: M
/**
* Indicates that the compiler bridge sould be retrieved from the resources on classpath.
* @param sourceJarName The name of the JAR containing the bridge sources, to find in the resources.
* @param reflectJarName The name of the JAR corresponding to `scala-reflect.jar` in the standard scala distribution.
* @param sourceJarName The name of the JAR containing the bridge sources, to find in the resources.
*/
final case class ResourceBridgeProvider(sourceJarName: String, reflectJarName: String) extends CompilerBridgeProvider
final case class ResourceBridgeProvider(sourceJarName: String) extends CompilerBridgeProvider

View File

@ -37,8 +37,8 @@ object ComponentCompiler {
val componentCompiler = new IvyComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager, ivyConfiguration, sourcesModule, log)
log.debug("Getting " + sourcesModule + " from component compiler for Scala " + scalaInstance.version)
componentCompiler()
case ResourceBridgeProvider(sourceJarName, reflectJarName) =>
val componentCompiler = new ResourceComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager, sourceJarName, reflectJarName, log)
case ResourceBridgeProvider(sourceJarName) =>
val componentCompiler = new ResourceComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager, sourceJarName, log)
log.debug("Compiling bridge source from resources for Scala " + scalaInstance.version)
componentCompiler()
}
@ -90,11 +90,9 @@ class ComponentCompiler(compiler: RawCompiler, manager: ComponentManager) {
/**
* Compiles the compiler bridge using the source extracted from the resources on classpath.
*/
private[compiler] class ResourceComponentCompiler(compiler: RawCompiler, manager: ComponentManager, sourceJarName: String, reflectJarName: String, log: Logger) {
private[compiler] class ResourceComponentCompiler(compiler: RawCompiler, manager: ComponentManager, sourceJarName: String, log: Logger) {
import ComponentCompiler._
private val reflectID = "reflect"
def apply(): File = {
val binID = "bridge-from-resource" + binSeparator + compiler.scalaInstance.actualVersion + "__" + javaVersion
manager.file(binID)(new IfMissing.Define(true, compileAndInstall(binID)))
@ -128,11 +126,7 @@ private[compiler] class ResourceComponentCompiler(compiler: RawCompiler, manager
IO.withTemporaryDirectory { tempDirectory =>
val sourceJar = copyFromResources(tempDirectory, sourceJarName)
val reflectJar = copyFromResources(tempDirectory, reflectJarName)
// We need to have `scala-reflect.jar` on the classpath when compiling the compiler bridge.
// In `IvyComponentCompiler`, `scala-reflect.jar` is automatically pulled in as a dependency.
AnalyzingCompiler.compileSources(Seq(sourceJar), targetJar, xsbtiJars ++ Seq(reflectJar), "bridge-from-resources", compiler, log)
AnalyzingCompiler.compileSources(Seq(sourceJar), targetJar, xsbtiJars, "bridge-from-resources", compiler, log)
manager.define(binID, Seq(targetJar))
}

View File

@ -80,7 +80,7 @@ private class StaticLauncher(appProvider: StaticAppProvider, scalaProvider: Stat
}
override def app(id: xsbti.ApplicationID, version: String): xsbti.AppProvider = appProvider
override def topLoader(): ClassLoader = new URLClassLoader(Array.empty)
override def topLoader(): ClassLoader = new URLClassLoader(Array.empty, null)
override def globalLock(): xsbti.GlobalLock = new WeakGlobalLock
override def bootDirectory(): File = new File(sys props "user.home") / ".sbt" / "boot"