From 88dd987d5f6ea8ba011ab690055910c3bc1cc9c2 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Wed, 6 Apr 2016 15:10:15 +0200 Subject: [PATCH] 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. --- .../sbt/compiler/CompilerBridgeProvider.scala | 5 ++--- .../scala/sbt/compiler/ComponentCompiler.scala | 14 ++++---------- sbt/src/main/scala/Main.scala | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/compile/ivy/src/main/scala/sbt/compiler/CompilerBridgeProvider.scala b/compile/ivy/src/main/scala/sbt/compiler/CompilerBridgeProvider.scala index 3e84d4bc0..993a31ed4 100644 --- a/compile/ivy/src/main/scala/sbt/compiler/CompilerBridgeProvider.scala +++ b/compile/ivy/src/main/scala/sbt/compiler/CompilerBridgeProvider.scala @@ -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 \ No newline at end of file +final case class ResourceBridgeProvider(sourceJarName: String) extends CompilerBridgeProvider \ No newline at end of file diff --git a/compile/ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala b/compile/ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala index 3b6f3dfcf..541d8f7b3 100644 --- a/compile/ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala +++ b/compile/ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala @@ -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)) } diff --git a/sbt/src/main/scala/Main.scala b/sbt/src/main/scala/Main.scala index cf45221ef..fcf8e715b 100644 --- a/sbt/src/main/scala/Main.scala +++ b/sbt/src/main/scala/Main.scala @@ -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"