Merge pull request #71 from eed3si9n/wip/eventlogging

event logging
This commit is contained in:
Dale Wijnand 2017-02-08 16:37:10 +00:00
commit c81b8de966
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
6 changed files with 26 additions and 18 deletions

View File

@ -95,7 +95,7 @@ abstract class EvaluateSettings[Scope] {
keyString
private[this] def keyString =
(static.toSeq.flatMap { case (key, value) => if (value eq this) init.showFullKey(key) :: Nil else Nil }).headOption getOrElse "non-static"
(static.toSeq.flatMap { case (key, value) => if (value eq this) init.showFullKey.show(key) :: Nil else Nil }).headOption getOrElse "non-static"
final def get: T = synchronized {
assert(value != null, toString + " not evaluated")

View File

@ -6,6 +6,7 @@ package sbt.internal.util
import scala.language.existentials
import Types._
import sbt.util.Show
sealed trait Settings[Scope] {
def data: Map[Scope, AttributeMap]
@ -119,7 +120,7 @@ trait Init[Scope] {
def mapScope(f: Scope => Scope): MapScoped = new MapScoped {
def apply[T](k: ScopedKey[T]): ScopedKey[T] = k.copy(scope = f(k.scope))
}
private final class InvalidReference(val key: ScopedKey[_]) extends RuntimeException("Internal settings error: invalid reference to " + showFullKey(key))
private final class InvalidReference(val key: ScopedKey[_]) extends RuntimeException("Internal settings error: invalid reference to " + showFullKey.show(key))
private[this] def applyDefaults(ss: Seq[Setting[_]]): Seq[Setting[_]] =
{
@ -215,11 +216,11 @@ trait Init[Scope] {
{
val guessed = guessIntendedScope(validKeys, delegates, u.referencedKey)
val derived = u.defining.isDerived
val refString = display(u.defining.key)
val refString = display.show(u.defining.key)
val sourceString = if (derived) "" else parenPosString(u.defining)
val guessedString = if (derived) "" else guessed.map(g => "\n Did you mean " + display(g) + " ?").toList.mkString
val guessedString = if (derived) "" else guessed.map(g => "\n Did you mean " + display.show(g) + " ?").toList.mkString
val derivedString = if (derived) ", which is a derived setting that needs this key to be defined in this scope." else ""
display(u.referencedKey) + " from " + refString + sourceString + derivedString + guessedString
display.show(u.referencedKey) + " from " + refString + sourceString + derivedString + guessedString
}
private[this] def parenPosString(s: Setting[_]): String =
s.positionString match { case None => ""; case Some(s) => " (" + s + ")" }
@ -255,7 +256,7 @@ trait Init[Scope] {
new Uninitialized(keys, prefix + suffix + " to undefined setting" + suffix + ": " + keysString + "\n ")
}
final class Compiled[T](val key: ScopedKey[T], val dependencies: Iterable[ScopedKey[_]], val settings: Seq[Setting[T]]) {
override def toString = showFullKey(key)
override def toString = showFullKey.show(key)
}
final class Flattened(val key: ScopedKey[_], val dependencies: Iterable[ScopedKey[_]])

View File

@ -1,8 +0,0 @@
package sbt.internal.util
trait Show[T] {
def apply(t: T): String
}
object Show {
def apply[T](f: T => String): Show[T] = new Show[T] { def apply(t: T): String = f(t) }
}

View File

@ -0,0 +1,12 @@
package sbt.util
trait Show[A] {
def show(a: A): String
}
object Show {
def apply[A](f: A => String): Show[A] = new Show[A] { def show(a: A): String = f(a) }
def fromToString[A]: Show[A] = new Show[A] {
def show(a: A): String = a.toString
}
}

View File

@ -1,4 +1,4 @@
package sbt.internal.util
package sbt.util
trait ShowLines[A] {
def showLines(a: A): Seq[String]

View File

@ -1,5 +1,7 @@
package sbt.internal.util
import sbt.util.Show
/** Define our settings system */
// A basic scope indexed by an integer.
@ -12,9 +14,10 @@ final case class Scope(nestIndex: Int, idAtIndex: Int = 0)
// That would be a general pain.)
case class SettingsExample() extends Init[Scope] {
// Provides a way of showing a Scope+AttributeKey[_]
val showFullKey: Show[ScopedKey[_]] = new Show[ScopedKey[_]] {
def apply(key: ScopedKey[_]) = s"${key.scope.nestIndex}(${key.scope.idAtIndex})/${key.key.label}"
}
val showFullKey: Show[ScopedKey[_]] = Show[ScopedKey[_]]((key: ScopedKey[_]) =>
{
s"${key.scope.nestIndex}(${key.scope.idAtIndex})/${key.key.label}"
})
// A sample delegation function that delegates to a Scope with a lower index.
val delegates: Scope => Seq[Scope] = {