mirror of https://github.com/sbt/sbt.git
Cleanup mainSettingsProj
This commit is contained in:
parent
e48f6ade30
commit
ca71b4b902
|
|
@ -20,7 +20,7 @@ object Append {
|
|||
def appendValues(a: Seq[T], b: Seq[V]): Seq[T] = a ++ b
|
||||
def appendValue(a: Seq[T], b: V): Seq[T] = a :+ b
|
||||
}
|
||||
implicit def appendSeqImplicit[T, V <% T]: Sequence[Seq[T], Seq[V], V] = new Sequence[Seq[T], Seq[V], V] {
|
||||
implicit def appendSeqImplicit[T, V](implicit ev: V => T): Sequence[Seq[T], Seq[V], V] = new Sequence[Seq[T], Seq[V], V] {
|
||||
def appendValues(a: Seq[T], b: Seq[V]): Seq[T] = a ++ (b map { x => (x: T) })
|
||||
def appendValue(a: Seq[T], b: V): Seq[T] = a :+ (b: T)
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ object Append {
|
|||
def appendValues(a: List[T], b: List[V]): List[T] = a ::: b
|
||||
def appendValue(a: List[T], b: V): List[T] = a :+ b
|
||||
}
|
||||
implicit def appendListImplicit[T, V <% T]: Sequence[List[T], List[V], V] = new Sequence[List[T], List[V], V] {
|
||||
implicit def appendListImplicit[T, V](implicit ev: V => T): Sequence[List[T], List[V], V] = new Sequence[List[T], List[V], V] {
|
||||
def appendValues(a: List[T], b: List[V]): List[T] = a ::: (b map { x => (x: T) })
|
||||
def appendValue(a: List[T], b: V): List[T] = a :+ (b: T)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,20 +128,20 @@ object InputTask {
|
|||
{
|
||||
val seen = new java.util.IdentityHashMap[Task[_], Task[_]]
|
||||
lazy val f: Task ~> Task = new (Task ~> Task) {
|
||||
def apply[T](t: Task[T]): Task[T] =
|
||||
def apply[A](t: Task[A]): Task[A] =
|
||||
{
|
||||
val t0 = seen.get(t)
|
||||
if (t0 == null) {
|
||||
val newAction =
|
||||
if (t.info.get(marker).isDefined)
|
||||
Pure(() => value.asInstanceOf[T], inline = true)
|
||||
Pure(() => value.asInstanceOf[A], inline = true)
|
||||
else
|
||||
t.work.mapTask(f)
|
||||
val newTask = Task(t.info, newAction)
|
||||
seen.put(t, newTask)
|
||||
newTask
|
||||
} else
|
||||
t0.asInstanceOf[Task[T]]
|
||||
t0.asInstanceOf[Task[A]]
|
||||
}
|
||||
}
|
||||
f(task)
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ object Scope {
|
|||
case LocalProject(id) => ProjectRef(current, id)
|
||||
case RootProject(uri) => RootProject(resolveBuild(current, uri))
|
||||
case ProjectRef(uri, id) => ProjectRef(resolveBuild(current, uri), id)
|
||||
case ThisProject => RootProject(current) // Is this right? It was an inexhaustive match before..
|
||||
}
|
||||
def resolveBuild(current: URI, uri: URI): URI =
|
||||
if (!uri.isAbsolute && current.isOpaque && uri.getSchemeSpecificPart == ".")
|
||||
|
|
@ -96,6 +97,7 @@ object Scope {
|
|||
case RootProject(uri) =>
|
||||
val res = resolveBuild(current, uri); ProjectRef(res, rootProject(res))
|
||||
case ProjectRef(uri, id) => ProjectRef(resolveBuild(current, uri), id)
|
||||
case ThisProject => ProjectRef(current, rootProject(current)) // Is this right? It was an inexhaustive match before..
|
||||
}
|
||||
def resolveBuildRef(current: URI, ref: BuildReference): BuildRef =
|
||||
ref match {
|
||||
|
|
@ -126,36 +128,6 @@ object Scope {
|
|||
def projectPrefix(project: ScopeAxis[Reference], show: Reference => String = showProject): String = project.foldStrict(show, "*/", "./")
|
||||
def showProject = (ref: Reference) => Reference.display(ref) + "/"
|
||||
|
||||
@deprecated("No longer used", "0.13.6")
|
||||
def parseScopedKey(command: String): (Scope, String) =
|
||||
{
|
||||
val ScopedKeyRegex2 = """([{](.*?)[}])?((\w*)\/)?(([\w\*]+)\:)?(([\w\-]+)\:\:)?([\w\-]+)""".r
|
||||
val ScopedKeyRegex2(_, uriOrNull, _, projectIdOrNull, _, configOrNull, _, inTaskOrNull, key) = command
|
||||
val uriOpt = Option(uriOrNull) map { new URI(_) }
|
||||
val projectIdOpt = Option(projectIdOrNull)
|
||||
val configOpt = Option(configOrNull)
|
||||
val inTaskOpt = Option(inTaskOrNull)
|
||||
val DotURI = new URI(".")
|
||||
val GlobalStr = "*"
|
||||
val scope = (uriOpt, projectIdOpt, configOpt, inTaskOpt) match {
|
||||
case (None, None, Some(GlobalStr), None) => GlobalScope
|
||||
case _ =>
|
||||
val projScope = (uriOpt, projectIdOpt) match {
|
||||
case (Some(DotURI), Some("")) => Select(ThisBuild)
|
||||
case (Some(uri), Some("")) => Select(BuildRef(uri))
|
||||
case (Some(uri), Some(p)) => Select(ProjectRef(uri, p))
|
||||
case (None, Some(p)) => Select(LocalProject(p))
|
||||
case _ => This
|
||||
}
|
||||
val configScope = configOpt map { case c if c != GlobalStr => Select(ConfigKey(c)) } getOrElse This
|
||||
val inTaskScope = inTaskOpt map { t => Select(AttributeKey(t)) } getOrElse This
|
||||
Scope(projScope, configScope, inTaskScope, This)
|
||||
}
|
||||
(scope, transformTaskName(key))
|
||||
}
|
||||
@deprecated("No longer used", "0.13.6")
|
||||
val ScopedKeyRegex = """((\w+)\/)?((\w+)\:)?([\w\-]+)""".r
|
||||
|
||||
def transformTaskName(s: String) =
|
||||
{
|
||||
val parts = s.split("-+")
|
||||
|
|
|
|||
|
|
@ -125,17 +125,17 @@ object Scoped {
|
|||
* }}}
|
||||
*
|
||||
*/
|
||||
sealed trait ScopingSetting[Result] {
|
||||
def in(s: Scope): Result
|
||||
sealed trait ScopingSetting[ResultType] {
|
||||
def in(s: Scope): ResultType
|
||||
|
||||
def in(p: Reference): Result = in(Select(p), This, This)
|
||||
def in(t: Scoped): Result = in(This, This, Select(t.key))
|
||||
def in(c: ConfigKey): Result = in(This, Select(c), This)
|
||||
def in(c: ConfigKey, t: Scoped): Result = in(This, Select(c), Select(t.key))
|
||||
def in(p: Reference, c: ConfigKey): Result = in(Select(p), Select(c), This)
|
||||
def in(p: Reference, t: Scoped): Result = in(Select(p), This, Select(t.key))
|
||||
def in(p: Reference, c: ConfigKey, t: Scoped): Result = in(Select(p), Select(c), Select(t.key))
|
||||
def in(p: ScopeAxis[Reference], c: ScopeAxis[ConfigKey], t: ScopeAxis[AttributeKey[_]]): Result = in(Scope(p, c, t, This))
|
||||
def in(p: Reference): ResultType = in(Select(p), This, This)
|
||||
def in(t: Scoped): ResultType = in(This, This, Select(t.key))
|
||||
def in(c: ConfigKey): ResultType = in(This, Select(c), This)
|
||||
def in(c: ConfigKey, t: Scoped): ResultType = in(This, Select(c), Select(t.key))
|
||||
def in(p: Reference, c: ConfigKey): ResultType = in(Select(p), Select(c), This)
|
||||
def in(p: Reference, t: Scoped): ResultType = in(Select(p), This, Select(t.key))
|
||||
def in(p: Reference, c: ConfigKey, t: Scoped): ResultType = in(Select(p), Select(c), Select(t.key))
|
||||
def in(p: ScopeAxis[Reference], c: ScopeAxis[ConfigKey], t: ScopeAxis[AttributeKey[_]]): ResultType = in(Scope(p, c, t, This))
|
||||
}
|
||||
|
||||
def scopedSetting[T](s: Scope, k: AttributeKey[T]): SettingKey[T] = new SettingKey[T] { val scope = s; val key = k }
|
||||
|
|
|
|||
|
|
@ -58,9 +58,6 @@ object InputWrapper {
|
|||
private[std] def wrapPrevious[T: c.WeakTypeTag](c: Context)(ts: c.Expr[Any], pos: c.Position): c.Expr[Option[T]] =
|
||||
wrapImpl[Option[T], InputWrapper.type](c, InputWrapper, WrapPreviousName)(ts, pos)
|
||||
|
||||
// TODO 2.11 Remove this after dropping 2.10.x support.
|
||||
private object HasCompat { val compat = ??? }; import HasCompat._
|
||||
|
||||
/**
|
||||
* Wraps an arbitrary Tree in a call to the `<s>.<wrapName>` method of this module for later processing by an enclosing macro.
|
||||
* The resulting Tree is the manually constructed version of:
|
||||
|
|
@ -70,11 +67,11 @@ object InputWrapper {
|
|||
def wrapImpl[T: c.WeakTypeTag, S <: AnyRef with Singleton](c: Context, s: S, wrapName: String)(ts: c.Expr[Any], pos: c.Position)(implicit it: c.TypeTag[s.type]): c.Expr[T] =
|
||||
{
|
||||
import c.universe.{ Apply => ApplyTree, _ }
|
||||
import compat._
|
||||
import internal.decorators._
|
||||
val util = new ContextUtil[c.type](c)
|
||||
val iw = util.singleton(s)
|
||||
val tpe = c.weakTypeOf[T]
|
||||
val nme = newTermName(wrapName).encoded
|
||||
val nme = TermName(wrapName).encodedName
|
||||
val sel = Select(Ident(iw), nme)
|
||||
sel.setPos(pos) // need to set the position on Select, because that is where the compileTimeOnly check looks
|
||||
val tree = ApplyTree(TypeApply(sel, TypeTree(tpe) :: Nil), ts.tree :: Nil)
|
||||
|
|
@ -87,7 +84,7 @@ object InputWrapper {
|
|||
// call to `.value` was inside a the task macro and eliminated before the end of the typer phase.
|
||||
// But, if a "naked" call to `.value` left the typer, the superaccessors phase would freak out when
|
||||
// if hit the untyped trees, before we could get to refchecks and the desired @compileTimeOnly warning.
|
||||
val typedTree = c.typeCheck(tree)
|
||||
val typedTree = c.typecheck(tree)
|
||||
c.Expr[T](typedTree)
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +186,7 @@ object ParserInput {
|
|||
val e = c.Expr[Initialize[InputTask[T]]](p.tree)
|
||||
wrapInit[Task[T]](c)(reify { Def.toIParser(e.splice) }, pos)
|
||||
} else
|
||||
c.abort(pos, s"Internal sbt error. Unexpected type ${tpe.normalize} in parsedInputMacroImpl.")
|
||||
c.abort(pos, s"Internal sbt error. Unexpected type ${tpe.dealias} in parsedInputMacroImpl.")
|
||||
}
|
||||
|
||||
/** Implements `Parser[T].parsed` by wrapping the Parser with the ParserInput wrapper.*/
|
||||
|
|
@ -209,6 +206,6 @@ object ParserInput {
|
|||
} else if (tpe <:< c.weakTypeOf[Initialize[State => Parser[T]]])
|
||||
wrapInit[T](c)(p, pos)
|
||||
else
|
||||
c.abort(pos, s"Internal sbt error. Unexpected type ${tpe.normalize} in parsedMacroImpl")
|
||||
c.abort(pos, s"Internal sbt error. Unexpected type ${tpe.dealias} in parsedMacroImpl")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ private[sbt] object KeyMacro {
|
|||
{
|
||||
import c.universe.{ Apply => ApplyTree, _ }
|
||||
val methodName = c.macroApplication.symbol.name
|
||||
def processName(n: Name): String = n.decoded.trim // trim is not strictly correct, but macros don't expose the API necessary
|
||||
def processName(n: Name): String = n.decodedName.toString.trim // trim is not strictly correct, but macros don't expose the API necessary
|
||||
def enclosingVal(trees: List[c.Tree]): String =
|
||||
{
|
||||
trees match {
|
||||
|
|
@ -40,7 +40,7 @@ private[sbt] object KeyMacro {
|
|||
// lazy val x: X = <methodName> has this form for some reason (only when the explicit type is present, though)
|
||||
case Block(_, _) :: DefDef(mods, name, _, _, _, _) :: xs if mods.hasFlag(Flag.LAZY) => processName(name)
|
||||
case _ =>
|
||||
c.error(c.enclosingPosition, invalidEnclosingTree(methodName.decoded))
|
||||
c.error(c.enclosingPosition, invalidEnclosingTree(methodName.decodedName.toString))
|
||||
"<error>"
|
||||
}
|
||||
}
|
||||
|
|
@ -48,4 +48,4 @@ private[sbt] object KeyMacro {
|
|||
}
|
||||
def enclosingTrees(c: Context): Seq[c.Tree] =
|
||||
c.asInstanceOf[reflect.macros.runtime.Context].callsiteTyper.context.enclosingContextChain.map(_.tree.asInstanceOf[c.Tree])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import language.experimental.macros
|
|||
import scala.reflect._
|
||||
import reflect.macros._
|
||||
import reflect.internal.annotations.compileTimeOnly
|
||||
import scala.reflect.internal.util.UndefinedPosition
|
||||
|
||||
/** Instance for the monad/applicative functor for plain Tasks. */
|
||||
object TaskInstance extends MonadInstance {
|
||||
|
|
@ -195,37 +196,37 @@ object TaskMacro {
|
|||
|
||||
private[this] def appendMacroImpl(c: Context)(init: c.Tree, append: c.Tree)(newName: String): c.Tree =
|
||||
{
|
||||
import c.universe.{ Apply, ApplyTag, newTermName, Select, SelectTag, TypeApply, TypeApplyTag }
|
||||
import c.universe._
|
||||
c.macroApplication match {
|
||||
case Apply(Apply(TypeApply(Select(preT, nmeT), targs), _), a) =>
|
||||
Apply(Apply(TypeApply(Select(preT, newTermName(newName).encodedName), targs), init :: sourcePosition(c).tree :: Nil), a)
|
||||
Apply(Apply(TypeApply(Select(preT, TermName(newName).encodedName), targs), init :: sourcePosition(c).tree :: Nil), a)
|
||||
case x => ContextUtil.unexpectedTree(x)
|
||||
}
|
||||
}
|
||||
private[this] def removeMacroImpl(c: Context)(init: c.Tree, remove: c.Tree)(newName: String): c.Tree =
|
||||
{
|
||||
import c.universe.{ Apply, ApplyTag, newTermName, Select, SelectTag, TypeApply, TypeApplyTag }
|
||||
import c.universe._
|
||||
c.macroApplication match {
|
||||
case Apply(Apply(TypeApply(Select(preT, nmeT), targs), _), r) =>
|
||||
Apply(Apply(TypeApply(Select(preT, newTermName(newName).encodedName), targs), init :: sourcePosition(c).tree :: Nil), r)
|
||||
Apply(Apply(TypeApply(Select(preT, TermName(newName).encodedName), targs), init :: sourcePosition(c).tree :: Nil), r)
|
||||
case x => ContextUtil.unexpectedTree(x)
|
||||
}
|
||||
}
|
||||
private[this] def transformMacroImpl(c: Context)(init: c.Tree)(newName: String): c.Tree =
|
||||
{
|
||||
import c.universe.{ Apply, ApplyTag, newTermName, Select, SelectTag }
|
||||
import c.universe._
|
||||
val target =
|
||||
c.macroApplication match {
|
||||
case Apply(Select(prefix, _), _) => prefix
|
||||
case x => ContextUtil.unexpectedTree(x)
|
||||
}
|
||||
Apply.apply(Select(target, newTermName(newName).encodedName), init :: sourcePosition(c).tree :: Nil)
|
||||
Apply.apply(Select(target, TermName(newName).encodedName), init :: sourcePosition(c).tree :: Nil)
|
||||
}
|
||||
private[this] def sourcePosition(c: Context): c.Expr[SourcePosition] =
|
||||
{
|
||||
import c.universe.reify
|
||||
val pos = c.enclosingPosition
|
||||
if (pos.isDefined && pos.line >= 0 && pos.source != null) {
|
||||
if (!pos.isInstanceOf[UndefinedPosition] && pos.line >= 0 && pos.source != null) {
|
||||
val f = pos.source.file
|
||||
val name = constant[String](c, settingSource(c, f.path, f.name))
|
||||
val line = constant[Int](c, pos.line)
|
||||
|
|
@ -316,13 +317,10 @@ object TaskMacro {
|
|||
private[this] def iTaskMacro[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Task[T]] =
|
||||
Instance.contImpl[T, Id](c, TaskInstance, TaskConvert, MixedBuilder)(Left(t), Instance.idTransform)
|
||||
|
||||
// TODO 2.11 Remove this after dropping 2.10.x support.
|
||||
private object HasCompat { val compat = ??? }; import HasCompat._
|
||||
|
||||
private[this] def inputTaskDynMacro0[T: c.WeakTypeTag](c: Context)(t: c.Expr[Initialize[Task[T]]]): c.Expr[Initialize[InputTask[T]]] =
|
||||
{
|
||||
import c.universe.{ Apply => ApplyTree, _ }
|
||||
import compat._
|
||||
import internal.decorators._
|
||||
|
||||
val tag = implicitly[c.WeakTypeTag[T]]
|
||||
val util = ContextUtil[c.type](c)
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
package sbt
|
||||
|
||||
import org.specs2._
|
||||
import Scope.{ ThisScope, GlobalScope, parseScopedKey }
|
||||
import java.net.URI
|
||||
import sbt.internal.util.AttributeKey
|
||||
|
||||
/**
|
||||
* http://www.scala-sbt.org/0.13/tutorial/Scopes.html
|
||||
*/
|
||||
class ScopedKeySpec extends Specification {
|
||||
def is = s2"""
|
||||
|
||||
This is a specification to check the scoped key parsing.
|
||||
|
||||
fullClasspath should
|
||||
${beParsedAs("fullClasspath", ThisScope, "fullClasspath")}
|
||||
|
||||
test:fullClasspath should
|
||||
${beParsedAs("test:fullClasspath", ThisScope in ConfigKey("test"), "fullClasspath")}
|
||||
|
||||
*:fullClasspath
|
||||
${beParsedAs("*:fullClasspath", GlobalScope, "fullClasspath")}
|
||||
|
||||
aea33a/test:fullClasspath
|
||||
${beParsedAs("aea33a/test:fullClasspath", ThisScope in (LocalProject("aea33a"), ConfigKey("test")), "fullClasspath")}
|
||||
|
||||
doc::fullClasspath
|
||||
${beParsedAs("doc::fullClasspath", ThisScope in AttributeKey("doc"), "fullClasspath")}
|
||||
|
||||
{file:/hello/}aea33a/test:fullClasspath
|
||||
${beParsedAs("{file:/hello/}aea33a/test:fullClasspath", ThisScope in (ProjectRef(new URI("file:/hello/"), "aea33a"), ConfigKey("test")), "fullClasspath")}
|
||||
|
||||
{file:/hello/}/test:fullClasspath
|
||||
${beParsedAs("{file:/hello/}/test:fullClasspath", ThisScope in (BuildRef(new URI("file:/hello/")), ConfigKey("test")), "fullClasspath")}
|
||||
|
||||
{.}/test:fullClasspath
|
||||
${beParsedAs("{.}/test:fullClasspath", ThisScope in (ThisBuild, ConfigKey("test")), "fullClasspath")}
|
||||
|
||||
{file:/hello/}/compile:doc::fullClasspath
|
||||
${beParsedAs("{file:/hello/}/compile:doc::fullClasspath", ThisScope in (BuildRef(new URI("file:/hello/")), ConfigKey("compile"), AttributeKey("doc")), "fullClasspath")}
|
||||
"""
|
||||
|
||||
def beParsedAs(cmd: String, scope0: Scope, key0: String) =
|
||||
{
|
||||
val (scope, key) = parseScopedKey(cmd)
|
||||
(scope must_== scope0) and (key must_== key0)
|
||||
}
|
||||
}
|
||||
|
|
@ -37,8 +37,8 @@ object Assign {
|
|||
val dummyt = taskKey[complete.Parser[String]]("dummyt")
|
||||
val dummys = settingKey[complete.Parser[String]]("dummys")
|
||||
val dummy3 = settingKey[complete.Parser[(String, Int)]]("dummy3")
|
||||
val tsk: complete.Parser[Task[String]] = ???
|
||||
val itsk: Initialize[InputTask[Int]] = ???
|
||||
val tsk: complete.Parser[Task[String]] = DefaultParsers.failure("ignored")
|
||||
val itsk: Initialize[InputTask[Int]] = inputKey[Int]("ignored")
|
||||
val seqSetting = settingKey[Seq[String]]("seqSetting")
|
||||
val listSetting = settingKey[List[String]]("listSetting")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue