mirror of https://github.com/sbt/sbt.git
implement embedded interface
This commit is contained in:
parent
6b774286d1
commit
8869378573
|
|
@ -17,7 +17,7 @@ object ComponentCompiler
|
||||||
|
|
||||||
def interfaceProvider(manager: ComponentManager): CompilerInterfaceProvider = new CompilerInterfaceProvider
|
def interfaceProvider(manager: ComponentManager): CompilerInterfaceProvider = new CompilerInterfaceProvider
|
||||||
{
|
{
|
||||||
def apply(scalaInstance: ScalaInstance, log: Logger): File =
|
def apply(scalaInstance: xsbti.compile.ScalaInstance, log: Logger): File =
|
||||||
{
|
{
|
||||||
// this is the instance used to compile the interface component
|
// this is the instance used to compile the interface component
|
||||||
val componentCompiler = new ComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager)
|
val componentCompiler = new ComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager)
|
||||||
|
|
@ -32,7 +32,6 @@ object ComponentCompiler
|
||||||
class ComponentCompiler(compiler: RawCompiler, manager: ComponentManager)
|
class ComponentCompiler(compiler: RawCompiler, manager: ComponentManager)
|
||||||
{
|
{
|
||||||
import ComponentCompiler._
|
import ComponentCompiler._
|
||||||
import sbt.IO.{copy, createDirectory, zip, jars, unzip, withTemporaryDirectory}
|
|
||||||
def apply(id: String): File =
|
def apply(id: String): File =
|
||||||
try { getPrecompiled(id) }
|
try { getPrecompiled(id) }
|
||||||
catch { case _: InvalidComponent => getLocallyCompiled(id) }
|
catch { case _: InvalidComponent => getLocallyCompiled(id) }
|
||||||
|
|
@ -56,37 +55,11 @@ class ComponentCompiler(compiler: RawCompiler, manager: ComponentManager)
|
||||||
protected def compileAndInstall(id: String, binID: String)
|
protected def compileAndInstall(id: String, binID: String)
|
||||||
{
|
{
|
||||||
val srcID = id + srcExtension
|
val srcID = id + srcExtension
|
||||||
withTemporaryDirectory { binaryDirectory =>
|
IO.withTemporaryDirectory { binaryDirectory =>
|
||||||
val targetJar = new File(binaryDirectory, id + ".jar")
|
val targetJar = new File(binaryDirectory, id + ".jar")
|
||||||
compileSources(manager.files(srcID)(IfMissing.Fail), targetJar, id)
|
val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail)
|
||||||
|
AnalyzingCompiler.compileSources(manager.files(srcID)(IfMissing.Fail), targetJar, xsbtiJars, id, compiler, manager.log)
|
||||||
manager.define(binID, Seq(targetJar))
|
manager.define(binID, Seq(targetJar))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** Extract sources from source jars, compile them with the xsbti interfaces on the classpath, and package the compiled classes and
|
|
||||||
* any resources from the source jars into a final jar.*/
|
|
||||||
private def compileSources(sourceJars: Iterable[File], targetJar: File, id: String)
|
|
||||||
{
|
|
||||||
val isSource = (f: File) => isSourceName(f.getName)
|
|
||||||
def keepIfSource(files: Set[File]): Set[File] = if(files.exists(isSource)) files else Set()
|
|
||||||
|
|
||||||
withTemporaryDirectory { dir =>
|
|
||||||
val extractedSources = (Set[File]() /: sourceJars) { (extracted, sourceJar)=> extracted ++ keepIfSource(unzip(sourceJar, dir)) }
|
|
||||||
val (sourceFiles, resources) = extractedSources.partition(isSource)
|
|
||||||
withTemporaryDirectory { outputDirectory =>
|
|
||||||
val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail)
|
|
||||||
manager.log.info("'" + id + "' not yet compiled for Scala " + compiler.scalaInstance.actualVersion + ". Compiling...")
|
|
||||||
val start = System.currentTimeMillis
|
|
||||||
try
|
|
||||||
{
|
|
||||||
compiler(sourceFiles.toSeq, xsbtiJars.toSeq ++ sourceJars, outputDirectory, "-nowarn" :: Nil)
|
|
||||||
manager.log.info(" Compilation completed in " + (System.currentTimeMillis - start) / 1000.0 + " s")
|
|
||||||
}
|
|
||||||
catch { case e: xsbti.CompileFailed => throw new CompileFailed(e.arguments, "Error compiling sbt component '" + id + "'") }
|
|
||||||
import sbt.Path._
|
|
||||||
copy(resources x rebase(dir, outputDirectory))
|
|
||||||
zip((outputDirectory ***) x_! relativeTo(outputDirectory), targetJar)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private def isSourceName(name: String): Boolean = name.endsWith(".scala") || name.endsWith(".java")
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue