don't put scala-library.jar on the boot classpath unless it is on the classpath

This commit is contained in:
Mark Harrah 2012-05-21 22:23:44 -04:00
parent a099754109
commit 9ee30636b3
4 changed files with 18 additions and 11 deletions

View File

@ -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])(

View File

@ -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
{

View File

@ -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 =
{

View File

@ -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