more release-worthy compile message and analysis toString

This commit is contained in:
Mark Harrah 2011-05-29 19:17:31 -04:00
parent bc9d57b417
commit a94247d1b6
6 changed files with 40 additions and 7 deletions

View File

@ -6,6 +6,7 @@ package inc
import xsbti.api.Source
import java.io.File
import sbt.Util.counted
trait Analysis
{
@ -20,12 +21,28 @@ trait Analysis
def addSource(src: File, api: Source, stamp: Stamp, internalDeps: Iterable[File]): Analysis
def addBinaryDep(src: File, dep: File, className: String, stamp: Stamp): Analysis
def addExternalDep(src: File, dep: String, api: Source): Analysis
def addProduct(src: File, product: File, stamp: Stamp): Analysis
def addProduct(src: File, product: File, stamp: Stamp): Analysis
override lazy val toString = Analysis.summary(this)
}
object Analysis
{
lazy val Empty: Analysis = new MAnalysis(Stamps.empty, APIs.empty, Relations.empty)
def summary(a: Analysis): String =
{
val (j, s) = a.apis.allInternalSources.partition(_.getName.endsWith(".java"))
val c = a.stamps.allProducts
val ext = a.apis.allExternals
val jars = a.relations.allBinaryDeps.filter(_.getName.endsWith(".jar"))
val sections =
counted("Scala source", "", "s", s.size) ++
counted("Java source", "", "s", j.size) ++
counted("class", "", "es", c.size) ++
counted("external source dependenc", "y", "ies", ext.size) ++
counted("binary dependenc", "y", "ies", jars.size)
sections.mkString("Analysis: ", ", ", "")
}
}
private class MAnalysis(val stamps: Stamps, val apis: APIs, val relations: Relations) extends Analysis
{

View File

@ -24,6 +24,7 @@ final class API(val global: Global, val callback: xsbti.AnalysisCallback) extend
{
import global._
def error(msg: String) = throw new RuntimeException(msg)
def debug(msg: String) = if(settings.verbose.value) inform(msg)
def newPhase(prev: Phase) = new ApiPhase(prev)
class ApiPhase(prev: Phase) extends Phase(prev)
@ -35,13 +36,13 @@ final class API(val global: Global, val callback: xsbti.AnalysisCallback) extend
val start = System.currentTimeMillis
currentRun.units.foreach(processUnit)
val stop = System.currentTimeMillis
println("API phase took : " + ((stop - start)/1000.0) + " s")
debug("API phase took : " + ((stop - start)/1000.0) + " s")
}
def processUnit(unit: CompilationUnit) = if(!unit.isJava) processScalaUnit(unit)
def processScalaUnit(unit: CompilationUnit)
{
val sourceFile = unit.source.file.file
println("Traversing " + sourceFile)
debug("Traversing " + sourceFile)
val traverser = new TopLevelHandler(sourceFile)
traverser.apply(unit.body)
val packages = traverser.packages.toArray[String].map(p => new xsbti.api.Package(p))

View File

@ -68,7 +68,7 @@ object Command
state => (simpleParser(simple)(state) /: arbs.map(_ parser state) ){ _ | _ }
}
private[this] def separateCommands(cmds: Seq[Command]): (Seq[SimpleCommand], Seq[ArbitraryCommand]) =
Collections.separate(cmds){ case s: SimpleCommand => Left(s); case a: ArbitraryCommand => Right(a) }
Util.separate(cmds){ case s: SimpleCommand => Left(s); case a: ArbitraryCommand => Right(a) }
private[this] def apply1[A,B,C](f: (A,B) => C, a: A): B => () => C =
b => () => f(a,b)

View File

@ -57,7 +57,7 @@ class AggressiveCompile(cacheDirectory: File)
IO.createDirectory(outputDirectory)
val incSrc = sources.filter(include)
val (javaSrcs, scalaSrcs) = incSrc partition javaOnly
println("Compiling:\n\t" + incSrc.mkString("\n\t"))
logInputs(log, javaSrcs.size, scalaSrcs.size)
def compileScala() =
if(!scalaSrcs.isEmpty)
{
@ -85,6 +85,14 @@ class AggressiveCompile(cacheDirectory: File)
}
IncrementalCompile(sourcesSet, entry, compile0, analysis, getAnalysis, outputDirectory)
}
private[this] def logInputs(log: Logger, javaCount: Int, scalaCount: Int)
{
val scalaMsg = Util.counted("Scala source", "", "s", scalaCount)
val javaMsg = Util.counted("Java source", "", "s", javaCount)
val combined = scalaMsg ++ javaMsg
if(!combined.isEmpty)
log.info(combined.mkString("Compiling ", " and ", "..."))
}
private def extract(previous: Option[(Analysis, CompileSetup)]): (Analysis, Option[CompileSetup]) =
previous match
{

View File

@ -3,7 +3,7 @@
*/
package sbt
object Collections
object Util
{
def separate[T,A,B](ps: Seq[T])(f: T => Either[A,B]): (Seq[A], Seq[B]) =
((Nil: Seq[A], Nil: Seq[B]) /: ps)( (xs, y) => prependEither(xs, f(y)) )
@ -14,4 +14,11 @@ object Collections
case Left(l) => (l +: acc._1, acc._2)
case Right(r) => (acc._1, r +: acc._2)
}
def counted(prefix: String, single: String, plural: String, count: Int): Option[String] =
count match
{
case 0 => None
case 1 => Some("1 " + prefix + single)
case x => Some(x.toString + " " + prefix + plural)
}
}

View File

@ -5,7 +5,7 @@ package sbt.complete
import Parser._
import sbt.Types.{left, right, some}
import sbt.Collections.separate
import sbt.Util.separate
sealed trait Parser[+T]
{