2009-08-17 16:51:43 +02:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2008, 2009 Mark Harrah
|
|
|
|
|
*/
|
|
|
|
|
package xsbt
|
|
|
|
|
|
2009-09-04 05:40:47 +02:00
|
|
|
import xsbti.{AnalysisCallback,Logger}
|
|
|
|
|
import scala.tools.nsc.{Phase, SubComponent}
|
2009-08-17 16:51:43 +02:00
|
|
|
|
|
|
|
|
class CompilerInterface
|
|
|
|
|
{
|
|
|
|
|
def run(args: Array[String], callback: AnalysisCallback, maximumErrors: Int, log: Logger)
|
|
|
|
|
{
|
2009-09-05 18:19:34 +02:00
|
|
|
def debug(msg: => String) = log.debug(Message(msg))
|
2009-10-03 15:39:16 +02:00
|
|
|
import scala.tools.nsc.{CompilerCommand, Global, Settings}
|
2009-09-05 18:19:34 +02:00
|
|
|
|
|
|
|
|
debug("Interfacing (CompilerInterface) with Scala compiler " + scala.tools.nsc.Properties.versionString)
|
|
|
|
|
|
2009-08-17 16:51:43 +02:00
|
|
|
val reporter = new LoggerReporter(maximumErrors, log)
|
|
|
|
|
val settings = new Settings(reporter.error)
|
|
|
|
|
val command = new CompilerCommand(args.toList, settings, error, false)
|
2009-09-04 05:40:47 +02:00
|
|
|
|
2009-09-05 18:19:34 +02:00
|
|
|
val phasesSet = new scala.collection.mutable.HashSet[Any] // 2.7 compatibility
|
2009-09-04 05:40:47 +02:00
|
|
|
object compiler extends Global(command.settings, reporter)
|
2009-08-17 16:51:43 +02:00
|
|
|
{
|
2009-09-04 05:40:47 +02:00
|
|
|
object sbtAnalyzer extends
|
|
|
|
|
{
|
|
|
|
|
val global: compiler.type = compiler
|
|
|
|
|
val phaseName = Analyzer.name
|
|
|
|
|
val runsAfter = List("jvm")
|
2009-09-05 18:19:34 +02:00
|
|
|
override val runsBefore = List("terminal")
|
2009-09-04 05:40:47 +02:00
|
|
|
val runsRightAfter = None
|
|
|
|
|
}
|
2009-09-05 18:19:34 +02:00
|
|
|
with SubComponent with Compat27
|
2009-09-04 05:40:47 +02:00
|
|
|
{
|
|
|
|
|
val analyzer = new Analyzer(global, callback)
|
|
|
|
|
def newPhase(prev: Phase) = analyzer.newPhase(prev)
|
|
|
|
|
def name = phaseName
|
|
|
|
|
}
|
2009-10-03 15:39:16 +02:00
|
|
|
override def computePhaseDescriptors = // done this way for compatibility between 2.7 and 2.8
|
2009-09-04 05:40:47 +02:00
|
|
|
{
|
|
|
|
|
phasesSet += sbtAnalyzer
|
2009-10-03 15:39:16 +02:00
|
|
|
val superd = super.computePhaseDescriptors
|
2009-10-10 01:12:14 +02:00
|
|
|
if(superd.contains(sbtAnalyzer)) superd else ( superd ++ List(sbtAnalyzer) ).toList
|
2009-09-05 18:19:34 +02:00
|
|
|
}
|
|
|
|
|
trait Compat27 { val runsBefore: List[String] = Nil }
|
2009-08-17 16:51:43 +02:00
|
|
|
}
|
|
|
|
|
if(!reporter.hasErrors)
|
|
|
|
|
{
|
|
|
|
|
val run = new compiler.Run
|
2009-09-05 18:19:34 +02:00
|
|
|
debug(args.mkString("Calling compiler with arguments (CompilerInterface):\n\t", "\n\t", ""))
|
2009-08-17 16:51:43 +02:00
|
|
|
run compile command.files
|
|
|
|
|
}
|
2009-09-05 18:19:34 +02:00
|
|
|
reporter.printSummary()
|
|
|
|
|
if(reporter.hasErrors)
|
|
|
|
|
{
|
|
|
|
|
debug("Compilation failed (CompilerInterface)")
|
2009-10-03 15:39:16 +02:00
|
|
|
throw new InterfaceCompileFailed(args, "Analyzed compilation failed")
|
2009-09-05 18:19:34 +02:00
|
|
|
}
|
2009-08-17 16:51:43 +02:00
|
|
|
}
|
2009-10-03 15:39:16 +02:00
|
|
|
}
|
|
|
|
|
class InterfaceCompileFailed(val arguments: Array[String], override val toString: String) extends xsbti.CompileFailed
|