From 9ee30636b3617f74c9ec593ce80f18892e37cd1f Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Mon, 21 May 2012 22:23:44 -0400 Subject: [PATCH] don't put scala-library.jar on the boot classpath unless it is on the classpath --- compile/AnalyzingCompiler.scala | 2 +- compile/CompilerArguments.scala | 23 ++++++++++++++------- compile/integration/AggressiveCompile.scala | 2 +- compile/src/test/scala/CompileTest.scala | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/compile/AnalyzingCompiler.scala b/compile/AnalyzingCompiler.scala index bae5a3b31..26b4475cf 100644 --- a/compile/AnalyzingCompiler.scala +++ b/compile/AnalyzingCompiler.scala @@ -58,7 +58,7 @@ final class AnalyzingCompiler(val scalaInstance: xsbti.compile.ScalaInstance, va { val arguments = new CompilerArguments(scalaInstance, cp) val classpathString = CompilerArguments.absString(arguments.finishClasspath(classpath)) - val bootClasspath = if(cp.autoBoot) arguments.createBootClasspath else "" + val bootClasspath = if(cp.autoBoot) arguments.createBootClasspathFor(classpath) else "" val (names, values) = bindings.unzip call("xsbt.ConsoleInterface", "run", log)( classOf[Array[String]], classOf[String], classOf[String], classOf[String], classOf[String], classOf[ClassLoader], classOf[Array[String]], classOf[Array[Any]], classOf[xLogger])( diff --git a/compile/CompilerArguments.scala b/compile/CompilerArguments.scala index b023d3727..ea9703dd8 100644 --- a/compile/CompilerArguments.scala +++ b/compile/CompilerArguments.scala @@ -25,7 +25,7 @@ final class CompilerArguments(scalaInstance: xsbti.compile.ScalaInstance, cp: xs val dummy = "dummy_" + Integer.toHexString(util.Random.nextInt) val classpathOption = Seq("-classpath", if(cpWithCompiler.isEmpty) dummy else absString(cpWithCompiler)) val outputOption = Seq("-d", outputDirectory.getAbsolutePath) - options ++ outputOption ++ bootClasspathOption ++ classpathOption ++ abs(sources) + options ++ outputOption ++ bootClasspathOption(hasLibrary(classpath)) ++ classpathOption ++ abs(sources) } def finishClasspath(classpath: Seq[File]): Seq[File] = filterLibrary(classpath) ++ include(cp.compiler, scalaInstance.compilerJar) ++ include(cp.extra, scalaInstance.otherJars : _*) @@ -36,11 +36,13 @@ final class CompilerArguments(scalaInstance: xsbti.compile.ScalaInstance, cp: xs val scalaHome = System.getProperty("scala.home") assert((scalaHome eq null) || scalaHome.isEmpty, "'scala.home' should not be set (was " + scalaHome + ")") } - /** Add the correct Scala library jar to the boot classpath.*/ - def createBootClasspath = + def createBootClasspathFor(classpath: Seq[File]) = createBootClasspath(hasLibrary(classpath)) + + /** Add the correct Scala library jar to the boot classpath if `addLibrary` is true.*/ + def createBootClasspath(addLibrary: Boolean) = { val originalBoot = System.getProperty("sun.boot.class.path", "") - if(cp.bootLibrary) + if(addLibrary) { val newBootPrefix = if(originalBoot.isEmpty) "" else originalBoot + File.pathSeparator newBootPrefix + scalaInstance.libraryJar.getAbsolutePath @@ -48,10 +50,15 @@ final class CompilerArguments(scalaInstance: xsbti.compile.ScalaInstance, cp: xs else originalBoot } - def filterLibrary(classpath: Seq[File]) = - if(cp.filterLibrary) classpath.filterNot(_.getName contains ArtifactInfo.ScalaLibraryID) else classpath - def bootClasspathOption = if(cp.autoBoot) Seq(BootClasspathOption, createBootClasspath) else Nil - def bootClasspath = if(cp.autoBoot) IO.parseClasspath(createBootClasspath) else Nil + def filterLibrary(classpath: Seq[File]) = if(cp.filterLibrary) classpath filterNot isScalaLibrary else classpath + def hasLibrary(classpath: Seq[File]) = classpath exists isScalaLibrary + private[this] val isScalaLibrary: File => Boolean = file => { + val name = file.getName + (name contains ArtifactInfo.ScalaLibraryID) || file.getName == scalaInstance.libraryJar.getName + } + def bootClasspathOption(addLibrary: Boolean) = if(cp.autoBoot) Seq(BootClasspathOption, createBootClasspath(addLibrary)) else Nil + def bootClasspath(addLibrary: Boolean) = if(cp.autoBoot) IO.parseClasspath(createBootClasspath(addLibrary)) else Nil + def bootClasspathFor(classpath: Seq[File]) = bootClasspath(hasLibrary(classpath)) } object CompilerArguments { diff --git a/compile/integration/AggressiveCompile.scala b/compile/integration/AggressiveCompile.scala index dbd1baa7a..03d728353 100644 --- a/compile/integration/AggressiveCompile.scala +++ b/compile/integration/AggressiveCompile.scala @@ -32,7 +32,7 @@ class AggressiveCompile(cacheFile: File) } def withBootclasspath(args: CompilerArguments, classpath: Seq[File]): Seq[File] = - args.bootClasspath ++ args.finishClasspath(classpath) + args.bootClasspathFor(classpath) ++ args.finishClasspath(classpath) def compile1(sources: Seq[File], classpath: Seq[File], setup: CompileSetup, store: AnalysisStore, analysis: File => Option[Analysis], definesClass: DefinesClass, compiler: AnalyzingCompiler, javac: xsbti.compile.JavaCompiler, maxErrors: Int, skip: Boolean, cache: GlobalsCache)(implicit log: Logger): Analysis = { diff --git a/compile/src/test/scala/CompileTest.scala b/compile/src/test/scala/CompileTest.scala index a1d46d29d..c5ab75db2 100644 --- a/compile/src/test/scala/CompileTest.scala +++ b/compile/src/test/scala/CompileTest.scala @@ -70,7 +70,7 @@ object CompileTest extends Specification val noCompiler = compiler(true, false) val fullExplicit = compiler(false, false) - val fullBoot = "-bootclasspath" :: fullExplicit.compilerArguments.createBootClasspath :: Nil + val fullBoot = "-bootclasspath" :: fullExplicit.compilerArguments.createBootClasspath(true) :: Nil val withCompiler = noCompiler.scalaInstance.compilerJar :: Nil val withLibrary = noCompiler.scalaInstance.libraryJar :: Nil val withLibraryCompiler = withLibrary ++ withCompiler