mirror of https://github.com/sbt/sbt.git
* move autoBootClasspath, compilerOnClasspath options into ClasspathOptions data structure and add 'extra' option
* put ScalaInstance.extraJars on classpath for ComponentCompiler
This commit is contained in:
parent
d01c0f4157
commit
61fefc0f66
|
|
@ -9,26 +9,26 @@ package xsbt
|
|||
* provided by scalaInstance. This class requires a ComponentManager in order to obtain the interface code to scalac and
|
||||
* the analysis plugin. Because these call Scala code for a different Scala version than the one used for this class, they must
|
||||
* be compiled for the version of Scala being used.*/
|
||||
class AnalyzingCompiler(val scalaInstance: ScalaInstance, val manager: ComponentManager, val autoBootClasspath: Boolean, val compilerOnClasspath: Boolean, log: CompileLogger) extends NotNull
|
||||
class AnalyzingCompiler(val scalaInstance: ScalaInstance, val manager: ComponentManager, val cp: ClasspathOptions, log: CompileLogger) extends NotNull
|
||||
{
|
||||
def this(scalaInstance: ScalaInstance, manager: ComponentManager, log: CompileLogger) = this(scalaInstance, manager, true, true, log)
|
||||
def this(scalaInstance: ScalaInstance, manager: ComponentManager, log: CompileLogger) = this(scalaInstance, manager, ClasspathOptions.auto, log)
|
||||
def apply(sources: Set[File], classpath: Set[File], outputDirectory: File, options: Seq[String], callback: AnalysisCallback, maximumErrors: Int, log: CompileLogger)
|
||||
{
|
||||
val arguments = (new CompilerArguments(scalaInstance, autoBootClasspath, compilerOnClasspath))(sources, classpath, outputDirectory, options)
|
||||
val arguments = (new CompilerArguments(scalaInstance, cp))(sources, classpath, outputDirectory, options)
|
||||
call("xsbt.CompilerInterface", log)(
|
||||
classOf[Array[String]], classOf[AnalysisCallback], classOf[Int], classOf[xLogger] ) (
|
||||
arguments.toArray[String] : Array[String], callback, maximumErrors: java.lang.Integer, log )
|
||||
}
|
||||
def doc(sources: Set[File], classpath: Set[File], outputDirectory: File, options: Seq[String], maximumErrors: Int, log: CompileLogger): Unit =
|
||||
{
|
||||
val arguments = (new CompilerArguments(scalaInstance, autoBootClasspath, compilerOnClasspath))(sources, classpath, outputDirectory, options)
|
||||
val arguments = (new CompilerArguments(scalaInstance, cp))(sources, classpath, outputDirectory, options)
|
||||
call("xsbt.ScaladocInterface", log) (classOf[Array[String]], classOf[Int], classOf[xLogger]) (arguments.toArray[String] : Array[String], maximumErrors: java.lang.Integer, log)
|
||||
}
|
||||
def console(classpath: Set[File], options: Seq[String], initialCommands: String, log: CompileLogger): Unit =
|
||||
{
|
||||
val arguments = new CompilerArguments(scalaInstance, autoBootClasspath, compilerOnClasspath)
|
||||
val arguments = new CompilerArguments(scalaInstance, cp)
|
||||
val classpathString = CompilerArguments.absString(arguments.finishClasspath(classpath))
|
||||
val bootClasspath = if(autoBootClasspath) arguments.createBootClasspath else ""
|
||||
val bootClasspath = if(cp.autoBoot) arguments.createBootClasspath else ""
|
||||
call("xsbt.ConsoleInterface", log) (classOf[Array[String]], classOf[String], classOf[String], classOf[String], classOf[xLogger]) (options.toArray[String]: Array[String], bootClasspath, classpathString, initialCommands, log)
|
||||
}
|
||||
def force(log: CompileLogger): Unit = getInterfaceJar(log)
|
||||
|
|
@ -54,7 +54,7 @@ class AnalyzingCompiler(val scalaInstance: ScalaInstance, val manager: Component
|
|||
log.debug("Getting " + ComponentCompiler.compilerInterfaceID + " from component compiler for Scala " + scalaInstance.version)
|
||||
componentCompiler(ComponentCompiler.compilerInterfaceID)
|
||||
}
|
||||
def newComponentCompiler(log: CompileLogger) = new ComponentCompiler(new RawCompiler(scalaInstance, true, true, log), manager)
|
||||
def newComponentCompiler(log: CompileLogger) = new ComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager)
|
||||
protected def createDualLoader(scalaLoader: ClassLoader, sbtLoader: ClassLoader): ClassLoader =
|
||||
{
|
||||
val xsbtiFilter = (name: String) => name.startsWith("xsbti.")
|
||||
|
|
|
|||
|
|
@ -8,19 +8,20 @@ package xsbt
|
|||
* order to add these jars to the boot classpath. The 'scala.home' property must be unset because Scala
|
||||
* puts jars in that directory on the bootclasspath. Because we use multiple Scala versions,
|
||||
* this would lead to compiling against the wrong library jar.*/
|
||||
class CompilerArguments(scalaInstance: ScalaInstance, autoBootClasspath: Boolean, compilerOnClasspath: Boolean)
|
||||
class CompilerArguments(scalaInstance: ScalaInstance, cp: ClasspathOptions) extends NotNull
|
||||
{
|
||||
def apply(sources: Set[File], classpath: Set[File], outputDirectory: File, options: Seq[String]): Seq[String] =
|
||||
{
|
||||
checkScalaHomeUnset()
|
||||
val bootClasspathOption = if(autoBootClasspath) Seq("-bootclasspath", createBootClasspath) else Nil
|
||||
val bootClasspathOption = if(cp.autoBoot) Seq("-bootclasspath", createBootClasspath) else Nil
|
||||
val cpWithCompiler = finishClasspath(classpath)
|
||||
val classpathOption = Seq("-cp", absString(cpWithCompiler) )
|
||||
val outputOption = Seq("-d", outputDirectory.getAbsolutePath)
|
||||
options ++ outputOption ++ bootClasspathOption ++ classpathOption ++ abs(sources)
|
||||
}
|
||||
def finishClasspath(classpath: Set[File]): Set[File] =
|
||||
classpath ++ (if(compilerOnClasspath) scalaInstance.compilerJar :: Nil else Nil)
|
||||
classpath ++ include(cp.compiler, scalaInstance.compilerJar) ++ include(cp.extra, scalaInstance.extraJars : _*)
|
||||
private def include(flag: Boolean, jars: File*) = if(flag) jars else Nil
|
||||
protected def abs(files: Set[File]) = files.map(_.getAbsolutePath)
|
||||
protected def checkScalaHomeUnset()
|
||||
{
|
||||
|
|
@ -35,6 +36,12 @@ class CompilerArguments(scalaInstance: ScalaInstance, autoBootClasspath: Boolean
|
|||
newBootPrefix + scalaInstance.libraryJar.getAbsolutePath
|
||||
}
|
||||
}
|
||||
class ClasspathOptions(val autoBoot: Boolean, val compiler: Boolean, val extra: Boolean) extends NotNull
|
||||
object ClasspathOptions
|
||||
{
|
||||
def manual = new ClasspathOptions(false, false, false)
|
||||
def auto = new ClasspathOptions(true, true, true)
|
||||
}
|
||||
object CompilerArguments
|
||||
{
|
||||
def abs(files: Seq[File]): Seq[String] = files.map(_.getAbsolutePath)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package xsbt
|
|||
* is used, for example, to compile the interface/plugin code.
|
||||
* If `explicitClasspath` is true, the bootclasspath and classpath are not augmented. If it is false,
|
||||
* the scala-library.jar from `scalaInstance` is put on bootclasspath and the scala-compiler jar goes on the classpath.*/
|
||||
class RawCompiler(val scalaInstance: ScalaInstance, autoBootClasspath: Boolean, compilerOnClasspath: Boolean, log: CompileLogger)
|
||||
class RawCompiler(val scalaInstance: ScalaInstance, cp: ClasspathOptions, log: CompileLogger)
|
||||
{
|
||||
def apply(sources: Set[File], classpath: Set[File], outputDirectory: File, options: Seq[String])
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ class RawCompiler(val scalaInstance: ScalaInstance, autoBootClasspath: Boolean,
|
|||
process.invoke(null, toJavaArray(arguments))
|
||||
checkForFailure(mainClass, arguments.toArray)
|
||||
}
|
||||
def compilerArguments = new CompilerArguments(scalaInstance, autoBootClasspath, compilerOnClasspath)
|
||||
def compilerArguments = new CompilerArguments(scalaInstance, cp)
|
||||
protected def checkForFailure(mainClass: Class[_], args: Array[String])
|
||||
{
|
||||
val reporter = mainClass.getMethod("reporter").invoke(null)
|
||||
|
|
|
|||
|
|
@ -77,8 +77,9 @@ final class Compile(maximumErrors: Int, compiler: AnalyzingCompiler, analysisCal
|
|||
}
|
||||
protected def processJava(sources: Set[File], classpath: Set[File], outputDirectory: File, options: Seq[String], log: Logger)
|
||||
{
|
||||
val augmentedClasspath = if(compiler.autoBootClasspath) classpath + compiler.scalaInstance.libraryJar else classpath
|
||||
val arguments = (new CompilerArguments(compiler.scalaInstance, false, compiler.compilerOnClasspath))(sources, augmentedClasspath, outputDirectory, options)
|
||||
val augmentedClasspath = if(compiler.cp.autoBoot) classpath + compiler.scalaInstance.libraryJar else classpath
|
||||
val cp = new xsbt.ClasspathOptions(false, compiler.cp.compiler, false)
|
||||
val arguments = (new CompilerArguments(compiler.scalaInstance, cp))(sources, augmentedClasspath, outputDirectory, options)
|
||||
log.debug("running javac with arguments:\n\t" + arguments.mkString("\n\t"))
|
||||
val code: Int =
|
||||
try { directJavac(arguments, log) }
|
||||
|
|
|
|||
Loading…
Reference in New Issue