Alter the DSL slightly to use explicit DslEntry types for settings.

* Create new DSLEntry type for settings so we can categorize what we parse
* Use DSLEntry to help solve the Setting[_] vs. Seq[Setting[_]] implicit fun.
* Hack away any non-Setting[_] DSLEntry for now.
* Add test in build.sbt to make sure the new DSL works.
This commit is contained in:
Josh Suereth 2014-04-15 17:49:50 -04:00
parent d198ea4099
commit 746583e718
5 changed files with 43 additions and 4 deletions

View File

@ -68,7 +68,8 @@ object BuildUtil {
deps(proj)(_.aggregate)
}
}
def baseImports: Seq[String] = "import sbt._, Keys._" :: Nil
def baseImports: Seq[String] = "import sbt._, Keys._, dsl._" :: Nil
def getImports(unit: BuildUnit): Seq[String] = unit.plugins.detected.imports

View File

@ -122,8 +122,8 @@ object EvaluateConfigurations {
* The name of the class we cast DSL "setting" (vs. definition) lines to.
*/
val SettingsDefinitionName = {
val _ = classOf[sbt.Def.SettingsDefinition] // this line exists to try to provide a compile-time error when the following line needs to be changed
"sbt.Def.SettingsDefinition"
val _ = classOf[sbt.internals.DslEntry] // this line exists to try to provide a compile-time error when the following line needs to be changed
"sbt.internals.DslEntry"
}
/**
* This actually compiles a scala expression which represents a Seq[Setting[_]], although the
@ -147,7 +147,10 @@ object EvaluateConfigurations {
}
loader => {
val pos = RangePosition(name, range shift 1)
result.getValue(loader).asInstanceOf[SettingsDefinition].settings map (_ withPos pos)
(result.getValue(loader).asInstanceOf[internals.DslEntry] match {
case internals.DslSetting(value) => value.settings
case _ => Nil
}) map (_ withPos pos)
}
}
private[this] def isSpace = (c: Char) => Character isWhitespace c

View File

@ -0,0 +1,13 @@
package sbt
import internals.{
DslEntry,
DslSetting,
DslEnablePlugins,
DslDisablePlugins
}
package object dsl {
def enablePlugins(ps: AutoPlugin*): DslEntry = DslEnablePlugins(ps)
def disablePlugins(ps: AutoPlugin*): DslEntry = DslDisablePlugins(ps)
}

View File

@ -0,0 +1,20 @@
package sbt
package internals
import Def._
/** This reprsents a `Setting` expression configured by the sbt DSL. */
sealed trait DslEntry
object DslEntry {
implicit def fromSettingsDef(inc: SettingsDefinition): DslEntry =
DslSetting(inc)
implicit def fromSettingsDef(inc: Seq[Setting[_]]): DslEntry =
DslSetting(inc)
}
/** this represents an actually Setting[_] or Seq[Setting[_]] configured by the sbt DSL. */
case class DslSetting(settings: SettingsDefinition) extends DslEntry
/** this represents an `enablePlugins()` in the sbt DSL */
case class DslEnablePlugins(plugins: Seq[AutoPlugin]) extends DslEntry
/** this represents an `disablePlugins()` in the sbt DSL */
case class DslDisablePlugins(plugins: Seq[AutoPlugin]) extends DslEntry

View File

@ -13,6 +13,8 @@ lazy val projD = project
// with S selected, Q is loaded automatically, which in turn selects R
lazy val projE = project.enablePlugins(S)
disablePlugins(plugins.IvyPlugin)
check := {
val adel = (del in projA).?.value // should be None
same(adel, None, "del in projA")