2010-01-06 01:50:43 +01:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2010 Mark Harrah
|
|
|
|
|
*/
|
2010-06-27 15:18:35 +02:00
|
|
|
package sbt
|
2010-01-06 01:50:43 +01:00
|
|
|
|
2010-07-15 01:24:50 +02:00
|
|
|
import sbt.compile.{AnalyzingCompiler, JavaCompiler}
|
2010-07-17 18:07:41 +02:00
|
|
|
import sbt.build.AggressiveCompile
|
2010-01-06 01:50:43 +01:00
|
|
|
import java.io.File
|
2010-06-27 15:18:35 +02:00
|
|
|
import System.{currentTimeMillis => now}
|
|
|
|
|
import Path._
|
|
|
|
|
import GlobFilter._
|
2010-01-06 01:50:43 +01:00
|
|
|
|
|
|
|
|
class AggressiveCompiler extends xsbti.AppMain
|
|
|
|
|
{
|
|
|
|
|
final def run(configuration: xsbti.AppConfiguration): xsbti.MainResult =
|
|
|
|
|
{
|
|
|
|
|
val args = configuration.arguments.map(_.trim).toList
|
2010-07-02 12:57:03 +02:00
|
|
|
val command = readLine("Press enter to compile... ").trim()
|
2010-06-27 15:18:35 +02:00
|
|
|
val start = now
|
2010-07-02 12:57:03 +02:00
|
|
|
val success = run(command, args, configuration.baseDirectory, configuration.provider)
|
2010-06-27 15:18:35 +02:00
|
|
|
println("Compiled in " + ((now - start) / 1000.0) + " s")
|
2010-01-06 01:50:43 +01:00
|
|
|
run(configuration)
|
|
|
|
|
}
|
2010-07-02 12:57:03 +02:00
|
|
|
def run(command: String, args: List[String], cwd: Path, app: xsbti.AppProvider): Boolean =
|
2010-01-06 01:50:43 +01:00
|
|
|
{
|
|
|
|
|
val launcher = app.scalaProvider.launcher
|
2010-07-05 18:53:37 +02:00
|
|
|
val sources = cwd ** ("*.scala" | "*.java")
|
2010-06-27 15:18:35 +02:00
|
|
|
val target = cwd / "target"
|
2010-07-15 01:24:50 +02:00
|
|
|
val javaBaseDirs = cwd :: Nil
|
2010-06-27 15:18:35 +02:00
|
|
|
val outputDirectory = target / "classes"
|
|
|
|
|
val classpath = outputDirectory +++ (cwd * "*.jar") +++(cwd * (-"project")).descendentsExcept( "*.jar", "project" || HiddenFileFilter)
|
|
|
|
|
val cacheDirectory = target / "cache"
|
|
|
|
|
val options = args.tail.toSeq
|
2010-09-04 14:19:58 +02:00
|
|
|
val log = ConsoleLogger()
|
2010-06-27 15:18:35 +02:00
|
|
|
val componentManager = new ComponentManager(launcher.globalLock, app.components, log)
|
|
|
|
|
val compiler = new AnalyzingCompiler(ScalaInstance(args.head, launcher), componentManager, log)
|
2010-07-15 01:24:50 +02:00
|
|
|
val javac = JavaCompiler.directOrFork(compiler.cp, compiler.scalaInstance)( (args: Seq[String], log: Logger) => Process("javac", args) ! log )
|
2010-06-27 15:18:35 +02:00
|
|
|
|
|
|
|
|
val agg = new AggressiveCompile(cacheDirectory)
|
2010-07-02 12:57:03 +02:00
|
|
|
try
|
|
|
|
|
{
|
2010-07-15 01:24:50 +02:00
|
|
|
val analysis = agg(compiler, javac, sources.get.toSeq, classpath.get.toSeq, outputDirectory, javaBaseDirs, options)(log)
|
2010-07-02 12:57:03 +02:00
|
|
|
processResult(analysis, command)
|
|
|
|
|
true
|
|
|
|
|
}
|
2010-06-27 15:18:35 +02:00
|
|
|
catch { case e: Exception => handleException(e); false }
|
2010-01-06 01:50:43 +01:00
|
|
|
}
|
|
|
|
|
def handleException(e: Throwable) =
|
|
|
|
|
{
|
|
|
|
|
if(!e.isInstanceOf[xsbti.CompileFailed])
|
|
|
|
|
{
|
|
|
|
|
e.printStackTrace
|
|
|
|
|
System.err.println(e.toString)
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-02 12:57:03 +02:00
|
|
|
def processResult(analysis: inc.Analysis, command: String)
|
|
|
|
|
{
|
|
|
|
|
if(command.isEmpty) ()
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
xsbt.api.ParseType.parseType(command) match
|
|
|
|
|
{
|
|
|
|
|
case Left(err) => println("Error parsing type: " + err)
|
|
|
|
|
case Right(tpe) => analysis.apis.internal.values.foreach(processAPI)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
def processAPI(api: xsbti.api.Source)
|
|
|
|
|
{
|
|
|
|
|
val d = new inc.Discovery(Set("scala.Enumeration", "scala.AnyRef", "scala.ScalaObject"), Set("scala.deprecated", "scala.annotation.tailrec"))
|
|
|
|
|
println(d(api.definitions).map { case (a, b) => (a.name, b) } )
|
|
|
|
|
}
|
2010-01-06 01:50:43 +01:00
|
|
|
}
|