Adds conflict check at the end to enforce exclusion requirements.

This commit is contained in:
Eugene Yokota 2014-03-21 01:06:00 -04:00
parent c7dc499fe4
commit e95935a7db
4 changed files with 54 additions and 4 deletions

View File

@ -160,12 +160,19 @@ object Plugins extends PluginsFunctions
log.debug(s"deducing auto plugins based on known facts ${knowlege0.toString} and clauses ${clauses.toString}")
Logic.reduce(clauses, (flattenConvert(requestedPlugins) ++ convertAll(alwaysEnabled)).toSet) match {
case Left(problem) => throw AutoPluginException(problem)
case Right(results0) =>
log.debug(s" :: deduced result: ${results0}")
val plugins = results0.ordered map { a =>
case Right(results) =>
log.debug(s" :: deduced result: ${results}")
val selectedAtoms: List[Atom] = results.ordered
val selectedPlugins = selectedAtoms map { a =>
byAtomMap.getOrElse(a, throw AutoPluginException(s"${a} was not found in atom map."))
}
val retval = topologicalSort(plugins, log)
val forbidden: Set[AutoPlugin] = (selectedPlugins flatMap { Plugins.asExclusions }).toSet
val c = selectedPlugins.toSet & forbidden
if (!c.isEmpty) {
val listString = (c map {_.label}).mkString(", ")
throw AutoPluginException(s"Contradiction in selected plugins. These plguins were both included and excluded: ${listString}")
}
val retval = topologicalSort(selectedPlugins, log)
log.debug(s" :: sorted deduced result: ${retval.toString}")
retval
}
@ -245,6 +252,9 @@ object Plugins extends PluginsFunctions
private[sbt] def asRequirements(ap: AutoPlugin): List[AutoPlugin] = flatten(ap.requires).toList collect {
case x: AutoPlugin => x
}
private[sbt] def asExclusions(ap: AutoPlugin): List[AutoPlugin] = flatten(ap.requires).toList collect {
case Exclude(x) => x
}
private[this] def flattenConvert(n: Plugins): Seq[Literal] = n match {
case And(ns) => convertAll(ns)
case b: Basic => convertBasic(b) :: Nil

View File

@ -0,0 +1,4 @@
// with S selected, Q is loaded automatically, which in turn selects R
lazy val projA = project.addPlugins(S)
check := ()

View File

@ -0,0 +1,35 @@
import sbt._
object AI extends AutoImport
{
trait EmptyAutoPlugin extends AutoPlugin {
def requires = empty
def trigger = noTrigger
}
object A extends EmptyAutoPlugin
object B extends EmptyAutoPlugin
lazy val check = settingKey[Unit]("Verifies settings are as they should be.")
}
import AI._
object Q extends AutoPlugin
{
def requires: Plugins = A && B
def trigger = allRequirements
}
object R extends AutoPlugin
{
def requires = Q
def trigger = allRequirements
}
// This is an opt-in plugin with a requirement
// Unless explicitly loaded by the build user, this will not be activated.
object S extends AutoPlugin
{
def requires = Q && !R
def trigger = noTrigger
}

View File

@ -0,0 +1 @@
-> check