From 65b341cdf04c163b16ecee379b28b79d0a007e6c Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Mon, 31 Jan 2011 18:16:25 -0500 Subject: [PATCH] translate Uninitialized message to use 'display' --- main/Build.scala | 4 ++-- main/Project.scala | 7 +++++++ util/collection/Settings.scala | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/main/Build.scala b/main/Build.scala index 63ec83556..6cabf2110 100644 --- a/main/Build.scala +++ b/main/Build.scala @@ -232,7 +232,7 @@ object Load lazy val rootEval = lazyEval(loaded.units(loaded.root).unit) val settings = config.injectSettings ++ buildConfigurations(loaded, getRootProject(projects), rootEval) val delegates = config.delegates(loaded) - val data = Project.make(settings)(delegates) + val data = Project.makeSettings(settings, delegates) val index = structureIndex(data) val streams = mkStreams(projects, loaded.root, data) (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. 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 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) diff --git a/main/Project.scala b/main/Project.scala index 632178c80..60d6ad717 100644 --- a/main/Project.scala +++ b/main/Project.scala @@ -63,6 +63,7 @@ object Project extends Init[Scope] val newAttrs = s.attributes.put(Watch.key, makeWatched(data, ref, project)).put(HistoryPath.key, historyPath) 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 = { @@ -85,6 +86,12 @@ object Project extends Init[Scope] val f = mapScope(g) 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 StructureKey = AttributeKey[Load.BuildStructure]("build-structure") diff --git a/util/collection/Settings.scala b/util/collection/Settings.scala index 6ef6964c8..a7a58526b 100644 --- a/util/collection/Settings.scala +++ b/util/collection/Settings.scala @@ -111,7 +111,7 @@ trait Init[Scope] val scache = PMap.empty[ScopedKey, ScopedKey] def resolve(search: Seq[Scope]): ScopedKey[T] = search match { - case Seq() => throw new Uninitialized(k) + case Seq() => throw Uninitialized(k, refKey) case Seq(x, xs @ _*) => val sk = ScopedKey(x, k.key) 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]) sealed trait Setting[T]