Remove warnings about configuration

Fixes #4293
Ref #4231, #4065

This fixes the regression on sbt 1.2.0 that displays a lot of warnings about configurations.

The warning was added in #4231 in an attempt to fix #4065. This actually highlights somewhat loose usage of configurations among the builds in the wild, and the limitation on the current slash syntax implementation.

I think we can remove this warning for now, and try to fix #4065 by making slash syntax more robust. In particular, we need to memorize the mapping between the configuration name and Scala identifier across the entire build, and use that in the shell.
This commit is contained in:
Eugene Yokota 2018-08-05 23:18:13 -04:00
parent 7c2ea0f374
commit 780ca366d8
7 changed files with 21 additions and 33 deletions

View File

@ -148,7 +148,7 @@ final case class Extracted(
): State = { ): State = {
val appendSettings = val appendSettings =
Load.transformSettings(Load.projectScope(currentRef), currentRef.build, rootProject, settings) Load.transformSettings(Load.projectScope(currentRef), currentRef.build, rootProject, settings)
val newStructure = Load.reapply(sessionSettings ++ appendSettings, structure, state.log) val newStructure = Load.reapply(sessionSettings ++ appendSettings, structure)
Project.setProject(session, newStructure, state) Project.setProject(session, newStructure, state)
} }
} }

View File

@ -472,7 +472,7 @@ object BuiltinCommands {
val loggerInject = LogManager.settingsLogger(s) val loggerInject = LogManager.settingsLogger(s)
val withLogger = newSession.appendRaw(loggerInject :: Nil) val withLogger = newSession.appendRaw(loggerInject :: Nil)
val show = Project.showContextKey2(newSession) val show = Project.showContextKey2(newSession)
val newStructure = Load.reapply(withLogger.mergeSettings, structure, s.log)(show) val newStructure = Load.reapply(withLogger.mergeSettings, structure)(show)
Project.setProject(newSession, newStructure, s) Project.setProject(newSession, newStructure, s)
} }

View File

@ -50,7 +50,7 @@ private[sbt] object PluginCross {
scalaVersion := scalaVersionSetting.value scalaVersion := scalaVersionSetting.value
) )
val cleared = session.mergeSettings.filterNot(crossExclude) val cleared = session.mergeSettings.filterNot(crossExclude)
val newStructure = Load.reapply(cleared ++ add, structure, state.log) val newStructure = Load.reapply(cleared ++ add, structure)
Project.setProject(session, newStructure, command :: state) Project.setProject(session, newStructure, command :: state)
} }
} }

View File

@ -267,7 +267,7 @@ private[sbt] object Load {
} }
Project.checkTargets(data) foreach sys.error Project.checkTargets(data) foreach sys.error
val index = timed("Load.apply: structureIndex", log) { val index = timed("Load.apply: structureIndex", log) {
structureIndex(data, settings, loaded.extra(data), projects, log) structureIndex(data, settings, loaded.extra(data), projects)
} }
val streams = timed("Load.apply: mkStreams", log) { mkStreams(projects, loaded.root, data) } val streams = timed("Load.apply: mkStreams", log) { mkStreams(projects, loaded.root, data) }
val bs = new BuildStructure( val bs = new BuildStructure(
@ -321,8 +321,7 @@ private[sbt] object Load {
data: Settings[Scope], data: Settings[Scope],
settings: Seq[Setting[_]], settings: Seq[Setting[_]],
extra: KeyIndex => BuildUtil[_], extra: KeyIndex => BuildUtil[_],
projects: Map[URI, LoadedBuildUnit], projects: Map[URI, LoadedBuildUnit]
log: Logger
): StructureIndex = { ): StructureIndex = {
val keys = Index.allKeys(settings) val keys = Index.allKeys(settings)
val attributeKeys = Index.attributeKeys(data) ++ keys.map(_.key) val attributeKeys = Index.attributeKeys(data) ++ keys.map(_.key)
@ -331,7 +330,6 @@ private[sbt] object Load {
val configsMap: Map[String, Seq[Configuration]] = val configsMap: Map[String, Seq[Configuration]] =
projects.values.flatMap(bu => bu.defined map { case (k, v) => (k, v.configurations) }).toMap projects.values.flatMap(bu => bu.defined map { case (k, v) => (k, v.configurations) }).toMap
val keyIndex = KeyIndex(scopedKeys.toVector, projectsMap, configsMap) val keyIndex = KeyIndex(scopedKeys.toVector, projectsMap, configsMap)
checkConfigurations(keyIndex, log)
val aggIndex = KeyIndex.aggregate(scopedKeys.toVector, extra(keyIndex), projectsMap, configsMap) val aggIndex = KeyIndex.aggregate(scopedKeys.toVector, extra(keyIndex), projectsMap, configsMap)
new StructureIndex( new StructureIndex(
Index.stringToKeyMap(attributeKeys), Index.stringToKeyMap(attributeKeys),
@ -342,33 +340,14 @@ private[sbt] object Load {
) )
} }
private def checkConfigurations(keyIndex: KeyIndex, log: Logger): Unit = {
keyIndex.guessedConfigIdents
.collect {
// Filter out any global configurations since we don't have a way of fixing them.
// Chances are this is only going to be the Test configuration which will have guessed correctly.
case (Some(projectRef), config, guess) =>
(Reference.display(projectRef), config, guess)
}
.foreach {
case (project, config, guess) =>
log.warn(
s"""The project $project references an unknown configuration "$config" and was guessed to be "$guess"."""
)
log.warn("This configuration should be explicitly added to the project.")
}
}
// 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( def reapply(newSettings: Seq[Setting[_]], structure: BuildStructure)(
newSettings: Seq[Setting[_]], implicit display: Show[ScopedKey[_]]
structure: BuildStructure, ): BuildStructure = {
log: Logger
)(implicit display: Show[ScopedKey[_]]): BuildStructure = {
val transformed = finalTransforms(newSettings) val transformed = finalTransforms(newSettings)
val newData = Def.make(transformed)(structure.delegates, structure.scopeLocal, display) val newData = Def.make(transformed)(structure.delegates, structure.scopeLocal, display)
def extra(index: KeyIndex) = BuildUtil(structure.root, structure.units, index, newData) def extra(index: KeyIndex) = BuildUtil(structure.root, structure.units, index, newData)
val newIndex = structureIndex(newData, transformed, extra, structure.units, log) val newIndex = structureIndex(newData, transformed, extra, structure.units)
val newStreams = mkStreams(structure.units, structure.root, newData) val newStreams = mkStreams(structure.units, structure.root, newData)
new BuildStructure( new BuildStructure(
units = structure.units, units = structure.units,
@ -382,6 +361,15 @@ private[sbt] object Load {
) )
} }
@deprecated("No longer used. For binary compatibility", "1.2.1")
def reapply(
newSettings: Seq[Setting[_]],
structure: BuildStructure,
log: Logger
)(implicit display: Show[ScopedKey[_]]): BuildStructure = {
reapply(newSettings, structure)
}
def buildConfigurations( def buildConfigurations(
loaded: LoadedBuild, loaded: LoadedBuild,
rootProject: URI => String, rootProject: URI => String,

View File

@ -65,7 +65,7 @@ object Script {
scriptSettings ++ embeddedSettings scriptSettings ++ embeddedSettings
) )
val newStructure = Load.reapply(session.original ++ append, structure, state.log) val newStructure = Load.reapply(session.original ++ append, structure)
val arguments = state.remainingCommands.drop(1).map(e => s""""${e.commandLine}"""") val arguments = state.remainingCommands.drop(1).map(e => s""""${e.commandLine}"""")
val newState = arguments.mkString("run ", " ", "") :: state.copy(remainingCommands = Nil) val newState = arguments.mkString("run ", " ", "") :: state.copy(remainingCommands = Nil)
Project.setProject(session, newStructure, newState) Project.setProject(session, newStructure, newState)

View File

@ -104,7 +104,7 @@ object FakeState {
val extra: KeyIndex => BuildUtil[_] = (keyIndex) => val extra: KeyIndex => BuildUtil[_] = (keyIndex) =>
BuildUtil(base.toURI, Map.empty, keyIndex, data) BuildUtil(base.toURI, Map.empty, keyIndex, data)
val structureIndex: StructureIndex = val structureIndex: StructureIndex =
Load.structureIndex(data, settings, extra, Map.empty, Logger.Null) Load.structureIndex(data, settings, extra, Map.empty)
val streams: (State) => BuildStreams.Streams = null val streams: (State) => BuildStreams.Streams = null
val loadedDefinitions: LoadedDefinitions = new LoadedDefinitions( val loadedDefinitions: LoadedDefinitions = new LoadedDefinitions(

View File

@ -174,7 +174,7 @@ object SettingQueryTest extends org.specs2.mutable.Specification {
val data: Settings[Scope] = Def.make(settings)(delegates, scopeLocal, display) val data: Settings[Scope] = Def.make(settings)(delegates, scopeLocal, display)
val extra: KeyIndex => BuildUtil[_] = index => BuildUtil(baseUri, units, index, data) val extra: KeyIndex => BuildUtil[_] = index => BuildUtil(baseUri, units, index, data)
val index: StructureIndex = structureIndex(data, settings, extra, units, Logger.Null) val index: StructureIndex = structureIndex(data, settings, extra, units)
val streams: State => Streams = mkStreams(units, baseUri, data) val streams: State => Streams = mkStreams(units, baseUri, data)
val structure: BuildStructure = val structure: BuildStructure =