mirror of https://github.com/sbt/sbt.git
translate Uninitialized message to use 'display'
This commit is contained in:
parent
d9d4869e49
commit
65b341cdf0
|
|
@ -232,7 +232,7 @@ object Load
|
||||||
lazy val rootEval = lazyEval(loaded.units(loaded.root).unit)
|
lazy val rootEval = lazyEval(loaded.units(loaded.root).unit)
|
||||||
val settings = config.injectSettings ++ buildConfigurations(loaded, getRootProject(projects), rootEval)
|
val settings = config.injectSettings ++ buildConfigurations(loaded, getRootProject(projects), rootEval)
|
||||||
val delegates = config.delegates(loaded)
|
val delegates = config.delegates(loaded)
|
||||||
val data = Project.make(settings)(delegates)
|
val data = Project.makeSettings(settings, delegates)
|
||||||
val index = structureIndex(data)
|
val index = structureIndex(data)
|
||||||
val streams = mkStreams(projects, loaded.root, data)
|
val streams = mkStreams(projects, loaded.root, data)
|
||||||
(rootEval, new BuildStructure(projects, loaded.root, settings, data, index, streams, delegates))
|
(rootEval, new BuildStructure(projects, loaded.root, settings, data, index, streams, delegates))
|
||||||
|
|
@ -244,7 +244,7 @@ object Load
|
||||||
// Reevaluates settings after modifying them. Does not recompile or reload any build components.
|
// Reevaluates settings after modifying them. Does not recompile or reload any build components.
|
||||||
def reapply(newSettings: Seq[Setting[_]], structure: BuildStructure): BuildStructure =
|
def reapply(newSettings: Seq[Setting[_]], structure: BuildStructure): BuildStructure =
|
||||||
{
|
{
|
||||||
val newData = Project.make(newSettings)(structure.delegates)
|
val newData = Project.makeSettings(newSettings, structure.delegates)
|
||||||
val newIndex = structureIndex(newData)
|
val newIndex = structureIndex(newData)
|
||||||
val newStreams = mkStreams(structure.units, structure.root, newData)
|
val newStreams = mkStreams(structure.units, structure.root, newData)
|
||||||
new BuildStructure(units = structure.units, root = structure.root, settings = newSettings, data = newData, index = newIndex, streams = newStreams, delegates = structure.delegates)
|
new BuildStructure(units = structure.units, root = structure.root, settings = newSettings, data = newData, index = newIndex, streams = newStreams, delegates = structure.delegates)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ object Project extends Init[Scope]
|
||||||
val newAttrs = s.attributes.put(Watch.key, makeWatched(data, ref, project)).put(HistoryPath.key, historyPath)
|
val newAttrs = s.attributes.put(Watch.key, makeWatched(data, ref, project)).put(HistoryPath.key, historyPath)
|
||||||
s.copy(attributes = newAttrs)
|
s.copy(attributes = newAttrs)
|
||||||
}
|
}
|
||||||
|
def makeSettings(settings: Seq[Setting[_]], delegates: Scope => Seq[Scope]) = translateUninitialized( make(settings)(delegates) )
|
||||||
|
|
||||||
def makeWatched(data: Settings[Scope], ref: ProjectRef, project: Project): Watched =
|
def makeWatched(data: Settings[Scope], ref: ProjectRef, project: Project): Watched =
|
||||||
{
|
{
|
||||||
|
|
@ -85,6 +86,12 @@ object Project extends Init[Scope]
|
||||||
val f = mapScope(g)
|
val f = mapScope(g)
|
||||||
ss.map(_ mapKey f mapReferenced f)
|
ss.map(_ mapKey f mapReferenced f)
|
||||||
}
|
}
|
||||||
|
def translateUninitialized[T](f: => T): T =
|
||||||
|
try { f } catch { case u: Project.Uninitialized =>
|
||||||
|
val msg = "Uninitialized reference to " + display(u.key) + " from " + display(u.refKey)
|
||||||
|
throw new Uninitialized(u.key, u.refKey, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val SessionKey = AttributeKey[SessionSettings]("session-settings")
|
val SessionKey = AttributeKey[SessionSettings]("session-settings")
|
||||||
val StructureKey = AttributeKey[Load.BuildStructure]("build-structure")
|
val StructureKey = AttributeKey[Load.BuildStructure]("build-structure")
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ trait Init[Scope]
|
||||||
val scache = PMap.empty[ScopedKey, ScopedKey]
|
val scache = PMap.empty[ScopedKey, ScopedKey]
|
||||||
def resolve(search: Seq[Scope]): ScopedKey[T] =
|
def resolve(search: Seq[Scope]): ScopedKey[T] =
|
||||||
search match {
|
search match {
|
||||||
case Seq() => throw new Uninitialized(k)
|
case Seq() => throw Uninitialized(k, refKey)
|
||||||
case Seq(x, xs @ _*) =>
|
case Seq(x, xs @ _*) =>
|
||||||
val sk = ScopedKey(x, k.key)
|
val sk = ScopedKey(x, k.key)
|
||||||
scache.getOrUpdate(sk, if(defines(sMap, sk, refKey)) sk else resolve(xs))
|
scache.getOrUpdate(sk, if(defines(sMap, sk, refKey)) sk else resolve(xs))
|
||||||
|
|
@ -137,7 +137,9 @@ trait Init[Scope]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class Uninitialized(key: ScopedKey[_]) extends Exception("Update on uninitialized setting " + key.key.label + " (in " + key.scope + ")")
|
final class Uninitialized(val key: ScopedKey[_], val refKey: ScopedKey[_], msg: String) extends Exception(msg)
|
||||||
|
def Uninitialized(key: ScopedKey[_], refKey: ScopedKey[_]): Uninitialized =
|
||||||
|
new Uninitialized(key, refKey, "Reference to uninitialized setting " + key.key.label + " (in " + key.scope + ") from " + refKey.key.label +" (in " + refKey.scope + ")")
|
||||||
final class Compiled(val dependencies: Iterable[ScopedKey[_]], val eval: Settings[Scope] => Settings[Scope])
|
final class Compiled(val dependencies: Iterable[ScopedKey[_]], val eval: Settings[Scope] => Settings[Scope])
|
||||||
|
|
||||||
sealed trait Setting[T]
|
sealed trait Setting[T]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue