From a254341b6f977276aaca25d9cb9263e9b408ea5d Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 22 Dec 2018 02:20:31 +0000 Subject: [PATCH 1/4] Remove dead guessedConfigIdents code --- .../main/scala/sbt/internal/KeyIndex.scala | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/main/src/main/scala/sbt/internal/KeyIndex.scala b/main/src/main/scala/sbt/internal/KeyIndex.scala index cb050c45b..c78b544d1 100644 --- a/main/src/main/scala/sbt/internal/KeyIndex.scala +++ b/main/src/main/scala/sbt/internal/KeyIndex.scala @@ -65,7 +65,6 @@ object KeyIndex { case Some(idx) => idx.fromConfigIdent(proj)(configIdent) case _ => Scope.unguessConfigIdent(configIdent) } - private[sbt] def guessedConfigIdents = concat(_.guessedConfigIdents) def tasks(proj: Option[ResolvedReference], conf: Option[String]) = concat(_.tasks(proj, conf)) def tasks(proj: Option[ResolvedReference], conf: Option[String], key: String) = concat(_.tasks(proj, conf, key)) @@ -114,7 +113,6 @@ trait KeyIndex { ): Set[String] private[sbt] def configIdents(project: Option[ResolvedReference]): Set[String] private[sbt] def fromConfigIdent(proj: Option[ResolvedReference])(configIdent: String): String - private[sbt] def guessedConfigIdents: Set[(Option[ProjectReference], String, String)] } trait ExtendableKeyIndex extends KeyIndex { def add(scoped: ScopedKey[_]): ExtendableKeyIndex @@ -229,25 +227,6 @@ private[sbt] final class KeyIndex0(val data: BuildIndex) extends ExtendableKeyIn private[sbt] def fromConfigIdent(proj: Option[ResolvedReference])(configIdent: String): String = confIndex(proj).fromConfigIdent(configIdent) - private[sbt] def guessedConfigIdents: Set[(Option[ProjectReference], String, String)] = { - val guesses = for { - (build, projIndex) <- data.data - (project, confIndex) <- projIndex.data - (config, data) <- confIndex.data - if data.ident.isEmpty && !Scope.configIdents.contains(config) - } yield (projRef(build, project), config, Scope.guessConfigIdent(config)) - guesses.toSet - } - - private def projRef(build: Option[URI], project: Option[String]): Option[ProjectReference] = { - (build, project) match { - case (Some(uri), Some(proj)) => Some(ProjectRef(uri, proj)) - case (Some(uri), None) => Some(RootProject(uri)) - case (None, Some(proj)) => Some(LocalProject(proj)) - case (None, None) => None - } - } - def tasks(proj: Option[ResolvedReference], conf: Option[String]): Set[AttributeKey[_]] = keyIndex(proj, conf).tasks def tasks( From 6988b2289a357c23f1d877425cda3045f24a1327 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 22 Dec 2018 02:22:07 +0000 Subject: [PATCH 2/4] Cleanup some formatting/wrapping --- main/src/main/scala/sbt/internal/Act.scala | 4 +--- main/src/main/scala/sbt/internal/KeyIndex.scala | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/main/src/main/scala/sbt/internal/Act.scala b/main/src/main/scala/sbt/internal/Act.scala index 18dbb8d55..1da6ce938 100644 --- a/main/src/main/scala/sbt/internal/Act.scala +++ b/main/src/main/scala/sbt/internal/Act.scala @@ -210,9 +210,7 @@ object Act { | ((ZeroString ^^^ ParsedZero) <~ sep) | ((ZeroIdent ^^^ ParsedZero) <~ sep) | (value(examples(ID, confs, "configuration")) <~ oldSep) - | (value(examples(CapitalizedID, idents, "configuration ident") map { - fromIdent(_) - }) <~ sep) + | (value(examples(CapitalizedID, idents, "configuration ident") map fromIdent) <~ sep) ) ?? Omitted } diff --git a/main/src/main/scala/sbt/internal/KeyIndex.scala b/main/src/main/scala/sbt/internal/KeyIndex.scala index c78b544d1..5cf5ddd29 100644 --- a/main/src/main/scala/sbt/internal/KeyIndex.scala +++ b/main/src/main/scala/sbt/internal/KeyIndex.scala @@ -59,9 +59,7 @@ object KeyIndex { def configs(proj: Option[ResolvedReference]) = concat(_.configs(proj)) private[sbt] def configIdents(proj: Option[ResolvedReference]) = concat(_.configIdents(proj)) private[sbt] def fromConfigIdent(proj: Option[ResolvedReference])(configIdent: String): String = - (indices find { idx => - idx.exists(proj) - }) match { + indices.find(idx => idx.exists(proj)) match { case Some(idx) => idx.fromConfigIdent(proj)(configIdent) case _ => Scope.unguessConfigIdent(configIdent) } From 3d924978c22ffb360b6ddd69dd6144927fcb0e5e Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 22 Dec 2018 16:26:55 +0000 Subject: [PATCH 3/4] Add some matcher messaging to ParserSpec --- main/src/test/scala/ParserSpec.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main/src/test/scala/ParserSpec.scala b/main/src/test/scala/ParserSpec.scala index a46ea26f4..147abc6db 100644 --- a/main/src/test/scala/ParserSpec.scala +++ b/main/src/test/scala/ParserSpec.scala @@ -7,6 +7,7 @@ import java.net.URI +import org.scalatest.matchers.MatchResult import org.scalatest.prop.PropertyChecks import org.scalatest.{ Matchers, PropSpec } import sbt.Def._ @@ -71,7 +72,14 @@ class ParserSpec extends PropSpec with PropertyChecks with Matchers { val structure = TestBuild.structure(env, settings, build.allProjects.head._1) val string = displayMasked(scopedKey, ScopeMask()) val parser = makeParser(structure) - val result = DefaultParsers.result(parser, string).left.map(_().toString) - result shouldBe Right(scopedKey) + string should { left => + val result = DefaultParsers.result(parser, left) + val resultStr = result.fold(_ => "", _.toString) + MatchResult( + result == Right(scopedKey), + s"$left parsed back to $resultStr rather than $scopedKey", + s"$left parsed back to $scopedKey", + ) + } } } From 30dca6b8186a9721afe337d92155e1c50e14fc20 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 22 Dec 2018 17:03:34 +0000 Subject: [PATCH 4/4] Cleanup ConfigIndex --- .../main/scala/sbt/internal/KeyIndex.scala | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/main/src/main/scala/sbt/internal/KeyIndex.scala b/main/src/main/scala/sbt/internal/KeyIndex.scala index 5cf5ddd29..3e9071391 100644 --- a/main/src/main/scala/sbt/internal/KeyIndex.scala +++ b/main/src/main/scala/sbt/internal/KeyIndex.scala @@ -41,11 +41,8 @@ object KeyIndex { } yield { val data = ids map { id => val configs = configurations.getOrElse(id, Seq()) - val namedConfigs = configs.map { config => - (config.name, ConfigData(Some(config.id), emptyAKeyIndex)) - }.toMap - val inverse = namedConfigs.map((ConfigIndex.invert _).tupled) - Option(id) -> new ConfigIndex(namedConfigs, inverse, emptyAKeyIndex) + val configIdentToName = configs.map(config => config.id -> config.name).toMap + Option(id) -> new ConfigIndex(Map.empty, configIdentToName, emptyAKeyIndex) } Option(uri) -> new ProjectIndex(data.toMap) } @@ -131,12 +128,13 @@ private[sbt] case class IdentifiableConfig(name: String, ident: Option[String]) private[sbt] case class ConfigData(ident: Option[String], keys: AKeyIndex) /* - * data contains the mapping between a configuration name and its ident and keys. + * data contains the mapping between a configuration name and its keys. + * configIdentToName contains the mapping between a configuration ident and its name * noConfigKeys contains the keys without a configuration. */ private[sbt] final class ConfigIndex( - val data: Map[String, ConfigData], - val inverse: Map[String, String], + val data: Map[String, AKeyIndex], + val configIdentToName: Map[String, String], val noConfigKeys: AKeyIndex ) { def add( @@ -155,22 +153,21 @@ private[sbt] final class ConfigIndex( task: Option[AttributeKey[_]], key: AttributeKey[_] ): ConfigIndex = { - val oldConfigData = data.getOrElse(config.name, ConfigData(None, emptyAKeyIndex)) - val newConfigData = ConfigData( - ident = oldConfigData.ident.orElse(config.ident), - keys = oldConfigData.keys.add(task, key) + val keyIndex = data.getOrElse(config.name, emptyAKeyIndex) + val configIdent = config.ident.getOrElse(Scope.guessConfigIdent(config.name)) + new ConfigIndex( + data.updated(config.name, keyIndex.add(task, key)), + configIdentToName.updated(configIdent, config.name), + noConfigKeys ) - val newData = data.updated(config.name, newConfigData) - val newInverse = (inverse.updated _).tupled(ConfigIndex.invert(config.name, newConfigData)) - new ConfigIndex(newData, newInverse, noConfigKeys) } def addKeyWithoutConfig(task: Option[AttributeKey[_]], key: AttributeKey[_]): ConfigIndex = { - new ConfigIndex(data, inverse, noConfigKeys.add(task, key)) + new ConfigIndex(data, configIdentToName, noConfigKeys.add(task, key)) } def keyIndex(conf: Option[String]): AKeyIndex = conf match { - case Some(c) => data.get(c).map(_.keys).getOrElse(emptyAKeyIndex) + case Some(c) => data.get(c).getOrElse(emptyAKeyIndex) case None => noConfigKeys } @@ -179,14 +176,9 @@ private[sbt] final class ConfigIndex( // guess Configuration name from an identifier. // There's a guessing involved because we could have scoped key that Project is not aware of. private[sbt] def fromConfigIdent(ident: String): String = - inverse.getOrElse(ident, Scope.unguessConfigIdent(ident)) -} -private[sbt] object ConfigIndex { - def invert(name: String, data: ConfigData): (String, String) = data match { - case ConfigData(Some(ident), _) => ident -> name - case ConfigData(None, _) => Scope.guessConfigIdent(name) -> name - } + configIdentToName.getOrElse(ident, Scope.unguessConfigIdent(ident)) } +private[sbt] object ConfigIndex private[sbt] final class ProjectIndex(val data: Map[Option[String], ConfigIndex]) { def add( id: Option[String],