mirror of https://github.com/sbt/sbt.git
Append macros
This commit is contained in:
parent
9c1e8abb91
commit
a1e50f8a2e
|
|
@ -148,23 +148,23 @@ sealed abstract class TaskKey[A1]
|
|||
def in(scope: Scope): TaskKey[A1] =
|
||||
Scoped.scopedTask(Scope.replaceThis(this.scope)(scope), this.key)
|
||||
|
||||
// def +=[U](v: U)(implicit a: Append.Value[T, U]): Setting[Task[T]] =
|
||||
// macro std.TaskMacro.taskAppend1Impl[T, U]
|
||||
inline def +=[A2](inline v: A2)(using Append.Value[A1, A2]): Setting[Task[A1]] =
|
||||
${ TaskMacro.taskAppend1Impl[A1, A2]('this, 'v) }
|
||||
|
||||
// def ++=[U](vs: U)(implicit a: Append.Values[T, U]): Setting[Task[T]] =
|
||||
// macro std.TaskMacro.taskAppendNImpl[T, U]
|
||||
inline def ++=[A2](inline vs: A2)(using Append.Values[A1, A2]): Setting[Task[A1]] =
|
||||
${ TaskMacro.taskAppendNImpl[A1, A2]('this, 'vs) }
|
||||
|
||||
// def <+=[V](v: Initialize[Task[V]])(implicit a: Append.Value[T, V]): Setting[Task[T]] =
|
||||
// macro std.TaskMacro.fakeTaskAppend1Position[T, V]
|
||||
inline def <+=[A2](inline v: Initialize[Task[A2]]): Setting[Task[A1]] =
|
||||
${ TaskMacro.fakeTaskAppend1Position[A1, A2]('v) }
|
||||
|
||||
// def <++=[V](vs: Initialize[Task[V]])(implicit a: Append.Values[T, V]): Setting[Task[T]] =
|
||||
// macro std.TaskMacro.fakeTaskAppendNPosition[T, V]
|
||||
inline def <++=[A2](inline vs: Initialize[Task[A2]]): Setting[Task[A1]] =
|
||||
${ TaskMacro.fakeTaskAppendNPosition[A1, A2]('vs) }
|
||||
|
||||
// final def -=[U](v: U)(implicit r: Remove.Value[T, U]): Setting[Task[T]] =
|
||||
// macro std.TaskMacro.taskRemove1Impl[T, U]
|
||||
final inline def -=[A2](v: A2)(using r: Remove.Value[A1, A2]): Setting[Task[A1]] =
|
||||
${ TaskMacro.taskRemove1Impl[A1, A2]('this, 'v) }
|
||||
|
||||
// final def --=[U](vs: U)(implicit r: Remove.Values[T, U]): Setting[Task[T]] =
|
||||
// macro std.TaskMacro.taskRemoveNImpl[T, U]
|
||||
final inline def --=[A2](vs: A2)(using r: Remove.Values[A1, A2]): Setting[Task[A1]] =
|
||||
${ TaskMacro.taskRemoveNImpl[A1, A2]('this, 'vs) }
|
||||
|
||||
def append1[V](v: Initialize[Task[V]], source: SourcePosition)(implicit
|
||||
a: Append.Value[A1, V]
|
||||
|
|
@ -372,8 +372,8 @@ object Scoped:
|
|||
inline def :=(inline v: A1): Setting[Task[A1]] =
|
||||
${ TaskMacro.taskAssignMacroImpl[A1]('self, 'v) }
|
||||
|
||||
// def <<=(app: Initialize[Task[S]]): Setting[Task[S]] =
|
||||
// macro std.TaskMacro.fakeItaskAssignPosition[S]
|
||||
inline def <<=(inline app: Initialize[Task[A1]]): Setting[Task[A1]] =
|
||||
${ TaskMacro.fakeItaskAssignPosition[A1]('app) }
|
||||
|
||||
/** In addition to creating Def.setting(...), this captures the source position. */
|
||||
inline def set(inline app: Initialize[Task[A1]]): Setting[Task[A1]] =
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ object TaskMacro:
|
|||
@deprecated("unused", "") v: Expr[Initialize[Task[A2]]]
|
||||
)(using
|
||||
qctx: Quotes
|
||||
): Expr[Setting[Task[A2]]] =
|
||||
): Expr[Setting[Task[A1]]] =
|
||||
import qctx.reflect.*
|
||||
report.errorAndAbort(TaskMacro.append1Migration)
|
||||
|
||||
|
|
@ -241,16 +241,21 @@ object TaskMacro:
|
|||
val assign = transformMacroImpl(c)(init.tree)(AssignInitName)
|
||||
c.Expr[Setting[InputTask[A1]]](assign)
|
||||
}
|
||||
*/
|
||||
|
||||
/** Implementation of += macro for tasks. */
|
||||
def taskAppend1Impl[A1: Type, U: Type](using
|
||||
def taskAppend1Impl[A1: Type, A2: Type](rec: Expr[TaskKey[A1]], v: Expr[A2])(using
|
||||
qctx: Quotes
|
||||
)(v: c.Expr[U])(a: c.Expr[Append.Value[A1, U]]): c.Expr[Setting[Task[A1]]] = {
|
||||
val init = taskMacroImpl[U](c)(v)
|
||||
val append = appendMacroImpl(c)(init.tree, a.tree)(Append1InitName)
|
||||
c.Expr[Setting[Task[A1]]](append)
|
||||
}
|
||||
*/
|
||||
): Expr[Setting[Task[A1]]] =
|
||||
import qctx.reflect.*
|
||||
Expr.summon[Append.Value[A1, A2]] match
|
||||
case Some(ev) =>
|
||||
val init = taskMacroImpl[A2](v)
|
||||
'{
|
||||
$rec.append1[A2]($init, $sourcePosition)(using $ev)
|
||||
}
|
||||
case _ =>
|
||||
report.errorAndAbort(s"Append.Value[${Type.of[A1]}, ${Type.of[A2]}] missing")
|
||||
|
||||
/** Implementation of += macro for settings. */
|
||||
def settingAppend1Impl[A1: Type, A2: Type](rec: Expr[SettingKey[A1]], v: Expr[A2])(using
|
||||
|
|
@ -278,16 +283,18 @@ object TaskMacro:
|
|||
}
|
||||
case _ => report.errorAndAbort(s"Append.Value[${Type.of[A1]}, ${Type.of[A2]}] missing")
|
||||
|
||||
/*
|
||||
/** Implementation of ++= macro for tasks. */
|
||||
def taskAppendNImpl[A1: Type, U: Type](
|
||||
c: blackbox.Context
|
||||
)(vs: c.Expr[U])(a: c.Expr[Append.Values[A1, U]]): c.Expr[Setting[Task[A1]]] = {
|
||||
val init = taskMacroImpl[U](c)(vs)
|
||||
val append = appendMacroImpl(c)(init.tree, a.tree)(AppendNInitName)
|
||||
c.Expr[Setting[Task[A1]]](append)
|
||||
}
|
||||
*/
|
||||
def taskAppendNImpl[A1: Type, A2: Type](rec: Expr[TaskKey[A1]], vs: Expr[A2])(using
|
||||
qctx: Quotes
|
||||
): Expr[Setting[Task[A1]]] =
|
||||
import qctx.reflect.*
|
||||
Expr.summon[Append.Values[A1, A2]] match
|
||||
case Some(ev) =>
|
||||
val init = taskMacroImpl[A2](vs)
|
||||
'{
|
||||
$rec.appendN($init, $sourcePosition)(using $ev)
|
||||
}
|
||||
case _ => report.errorAndAbort(s"Append.Values[${Type.of[A1]}, ${Type.of[A2]}] missing")
|
||||
|
||||
/** Implementation of ++= macro for settings. */
|
||||
def settingAppendNImpl[A1: Type, A2: Type](rec: Expr[SettingKey[A1]], vs: Expr[A2])(using
|
||||
|
|
@ -302,16 +309,18 @@ object TaskMacro:
|
|||
}
|
||||
case _ => report.errorAndAbort(s"Append.Values[${Type.of[A1]}, ${Type.of[A2]}] missing")
|
||||
|
||||
/*
|
||||
/** Implementation of -= macro for tasks. */
|
||||
def taskRemove1Impl[A1: Type, U: Type](using
|
||||
def taskRemove1Impl[A1: Type, A2: Type](rec: Expr[TaskKey[A1]], v: Expr[A2])(using
|
||||
qctx: Quotes
|
||||
)(v: c.Expr[U])(r: c.Expr[Remove.Value[A1, U]]): c.Expr[Setting[Task[A1]]] = {
|
||||
val init = taskMacroImpl[U](c)(v)
|
||||
val remove = removeMacroImpl(c)(init.tree, r.tree)(Remove1InitName)
|
||||
c.Expr[Setting[Task[A1]]](remove)
|
||||
}
|
||||
*/
|
||||
): Expr[Setting[Task[A1]]] =
|
||||
import qctx.reflect.*
|
||||
Expr.summon[Remove.Value[A1, A2]] match
|
||||
case Some(ev) =>
|
||||
val init = taskMacroImpl[A2](v)
|
||||
'{
|
||||
$rec.remove1[A2]($init, $sourcePosition)(using $ev)
|
||||
}
|
||||
case _ => report.errorAndAbort(s"Remove.Value[${Type.of[A1]}, ${Type.of[A2]}] missing")
|
||||
|
||||
/** Implementation of -= macro for settings. */
|
||||
def settingRemove1Impl[A1: Type, A2: Type](rec: Expr[SettingKey[A1]], v: Expr[A2])(using
|
||||
|
|
@ -326,16 +335,18 @@ object TaskMacro:
|
|||
}
|
||||
case _ => report.errorAndAbort(s"Remove.Value[${Type.of[A1]}, ${Type.of[A2]}] missing")
|
||||
|
||||
/*
|
||||
/** Implementation of --= macro for tasks. */
|
||||
def taskRemoveNImpl[A1: Type, U: Type](using
|
||||
def taskRemoveNImpl[A1: Type, A2: Type](rec: Expr[TaskKey[A1]], vs: Expr[A2])(using
|
||||
qctx: Quotes
|
||||
)(vs: c.Expr[U])(r: c.Expr[Remove.Values[A1, U]]): c.Expr[Setting[Task[A1]]] = {
|
||||
val init = taskMacroImpl[U](c)(vs)
|
||||
val remove = removeMacroImpl(c)(init.tree, r.tree)(RemoveNInitName)
|
||||
c.Expr[Setting[Task[A1]]](remove)
|
||||
}
|
||||
*/
|
||||
): Expr[Setting[Task[A1]]] =
|
||||
import qctx.reflect.*
|
||||
Expr.summon[Remove.Values[A1, A2]] match
|
||||
case Some(ev) =>
|
||||
val init = taskMacroImpl[A2](vs)
|
||||
'{
|
||||
$rec.removeN[A2]($init, $sourcePosition)(using $ev)
|
||||
}
|
||||
case _ => report.errorAndAbort(s"Remove.Values[${Type.of[A1]}, ${Type.of[A2]}] missing")
|
||||
|
||||
/** Implementation of --= macro for settings. */
|
||||
def settingRemoveNImpl[A1: Type, A2: Type](rec: Expr[SettingKey[A1]], vs: Expr[A2])(using
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ object Assign {
|
|||
val seqSetting = settingKey[Seq[String]]("seqSetting")
|
||||
val listSetting = settingKey[List[String]]("listSetting")
|
||||
|
||||
val listTask = taskKey[List[String]]("listTask")
|
||||
|
||||
/* def azy = sk.value
|
||||
|
||||
def azy2 = appmacro.Debug.checkWild(Def.task{ sk.value.size })
|
||||
|
|
@ -134,4 +136,7 @@ object Assign {
|
|||
listSetting += "test4"
|
||||
|
||||
listSetting ~= { (xs) => xs }
|
||||
|
||||
listTask := List("test1")
|
||||
listTask += "test2"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue