mirror of https://github.com/sbt/sbt.git
move explicit task/setting macros to Def, move to AbsTypeTag
This commit is contained in:
parent
3790d6656a
commit
0a642f2283
|
|
@ -723,29 +723,27 @@ object Classpaths
|
|||
internalDependencyClasspath <<= internalDependencies,
|
||||
unmanagedClasspath <<= unmanagedDependencies,
|
||||
products <<= makeProducts,
|
||||
productDirectories <<= compileInputs map (_.config.classesDirectory :: Nil),
|
||||
productDirectories := compileInputs.value.config.classesDirectory :: Nil,
|
||||
exportedProducts <<= exportProductsTask,
|
||||
classpathConfiguration <<= (internalConfigurationMap, configuration, classpathConfiguration.?, update.task) apply findClasspathConfig,
|
||||
managedClasspath <<= (classpathConfiguration, classpathTypes, update) map managedJars,
|
||||
classpathConfiguration := findClasspathConfig(internalConfigurationMap.value, configuration.value, classpathConfiguration.?.value, update.value),
|
||||
managedClasspath := managedJars(classpathConfiguration.value, classpathTypes.value, update.value),
|
||||
// remove when defaultExcludes and classpathFilter are removed
|
||||
excludeFilter in unmanagedJars <<= (defaultExcludes in unmanagedJars) or (excludeFilter in unmanagedJars),
|
||||
includeFilter in unmanagedJars <<= classpathFilter or (includeFilter in unmanagedJars),
|
||||
unmanagedJars <<= (configuration, unmanagedBase, includeFilter in unmanagedJars, excludeFilter in unmanagedJars) map { (config, base, filter, excl) =>
|
||||
(base * (filter -- excl) +++ (base / config.name).descendantsExcept(filter, excl)).classpath
|
||||
}
|
||||
unmanagedJars := findUnmanagedJars(configuration.value, unmanagedBase.value, includeFilter in unmanagedJars value, excludeFilter in unmanagedJars value)
|
||||
)
|
||||
def defaultPackageKeys = Seq(packageBin, packageSrc, packageDoc)
|
||||
lazy val defaultPackages: Seq[TaskKey[File]] =
|
||||
for(task <- defaultPackageKeys; conf <- Seq(Compile, Test)) yield (task in conf)
|
||||
lazy val defaultArtifactTasks: Seq[TaskKey[File]] = makePom +: defaultPackages
|
||||
|
||||
def findClasspathConfig(map: Configuration => Configuration, thisConfig: Configuration, delegate: Task[Option[Configuration]], up: Task[UpdateReport]): Task[Configuration] =
|
||||
(delegate, up) map { case (delegated, report) =>
|
||||
val defined = report.allConfigurations.toSet
|
||||
val search = map(thisConfig) +: (delegated.toList ++ Seq(Compile, Configurations.Default))
|
||||
def notFound = error("Configuration to use for managed classpath must be explicitly defined when default configurations are not present.")
|
||||
search find { defined contains _.name } getOrElse notFound
|
||||
}
|
||||
def findClasspathConfig(map: Configuration => Configuration, thisConfig: Configuration, delegated: Option[Configuration], report: UpdateReport): Configuration =
|
||||
{
|
||||
val defined = report.allConfigurations.toSet
|
||||
val search = map(thisConfig) +: (delegated.toList ++ Seq(Compile, Configurations.Default))
|
||||
def notFound = error("Configuration to use for managed classpath must be explicitly defined when default configurations are not present.")
|
||||
search find { defined contains _.name } getOrElse notFound
|
||||
}
|
||||
|
||||
def packaged(pkgTasks: Seq[TaskKey[File]]): Initialize[Task[Map[Artifact, File]]] =
|
||||
enabledOnly(packagedArtifact.task, pkgTasks) apply (_.join.map(_.toMap))
|
||||
|
|
@ -1169,6 +1167,10 @@ object Classpaths
|
|||
Attributed(file)(AttributeMap.empty.put(artifact.key, art).put(moduleID.key, module).put(configuration.key, config))
|
||||
} distinct;
|
||||
|
||||
def findUnmanagedJars(config: Configuration, base: File, filter: FileFilter, excl: FileFilter): Classpath =
|
||||
(base * (filter -- excl) +++ (base / config.name).descendantsExcept(filter, excl)).classpath
|
||||
|
||||
|
||||
def autoPlugins(report: UpdateReport): Seq[String] =
|
||||
{
|
||||
val pluginClasspath = report matching configurationFilter(CompilerPlugin.name)
|
||||
|
|
|
|||
|
|
@ -38,11 +38,18 @@ object Def extends Init[Scope]
|
|||
/** Lifts the result of a setting initialization into a Task. */
|
||||
def toITask[T](i: Initialize[T]): Initialize[Task[T]] = map(i)(std.TaskExtra.inlineTask)
|
||||
|
||||
import language.experimental.macros
|
||||
import std.TaskMacro.{MacroValue, taskDynMacroImpl, taskMacroImpl}
|
||||
import std.SettingMacro.{settingDynMacroImpl,settingMacroImpl}
|
||||
|
||||
def task[T](t: T): Def.Initialize[Task[T]] = macro taskMacroImpl[T]
|
||||
def taskDyn[T](t: Def.Initialize[Task[T]]): Def.Initialize[Task[T]] = macro taskDynMacroImpl[T]
|
||||
def setting[T](t: T): Def.Initialize[T] = macro settingMacroImpl[T]
|
||||
def settingDyn[T](t: Def.Initialize[T]): Def.Initialize[T] = macro settingDynMacroImpl[T]
|
||||
|
||||
// The following conversions enable the types Initialize[T], Initialize[Task[T]], and Task[T] to
|
||||
// be used in task and setting macros as inputs with an ultimate result of type T
|
||||
|
||||
import language.experimental.macros
|
||||
import std.TaskMacro.MacroValue
|
||||
implicit def macroValueI[T](in: Initialize[T]): MacroValue[T] = ???
|
||||
implicit def macroValueIT[T](in: Initialize[Task[T]]): MacroValue[T] = ???
|
||||
implicit def macroValueT[T](in: Task[T]): MacroValue[T] = ???
|
||||
|
|
|
|||
|
|
@ -15,16 +15,19 @@ object InitializeInstance extends MonadInstance
|
|||
}
|
||||
object InitializeConvert extends Convert
|
||||
{
|
||||
def apply[T: c.TypeTag](c: reflect.makro.Context)(in: c.Tree): c.Tree =
|
||||
if(in.tpe <:< c.typeOf[Initialize[Task[T]]] || in.tpe <:< c.typeOf[Task[T]])
|
||||
def apply[T: c.AbsTypeTag](c: reflect.makro.Context)(in: c.Tree): c.Tree =
|
||||
{
|
||||
val u = appmacro.ContextUtil[c.type](c)
|
||||
if(in.tpe <:< u.atypeOf[Initialize[Task[T]]] || in.tpe <:< u.atypeOf[Task[T]])
|
||||
c.abort(in.pos, "A setting cannot depend on a task")
|
||||
else if(in.tpe <:< c.typeOf[Initialize[T]])
|
||||
else if(in.tpe <:< u.atypeOf[Initialize[T]])
|
||||
{
|
||||
val i = c.Expr[Initialize[T]](in)
|
||||
c.universe.reify( i.splice ).tree
|
||||
}
|
||||
else
|
||||
c.abort(in.pos, "Unknown input type: " + in.tpe)
|
||||
}
|
||||
}
|
||||
|
||||
import language.experimental.macros
|
||||
|
|
@ -33,11 +36,9 @@ object InitializeConvert extends Convert
|
|||
|
||||
object SettingMacro
|
||||
{
|
||||
def setting[T](t: T): Initialize[T] = macro settingMacroImpl[T]
|
||||
def settingMacroImpl[T: c.TypeTag](c: Context)(t: c.Expr[T]): c.Expr[Initialize[T]] =
|
||||
def settingMacroImpl[T: c.AbsTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Initialize[T]] =
|
||||
Instance.contImpl[T](c, InitializeInstance, InitializeConvert, MixedBuilder)(Left(t))
|
||||
|
||||
def settingDyn[T](t: Initialize[T]): Initialize[T] = macro settingDynMacroImpl[T]
|
||||
def settingDynMacroImpl[T: c.TypeTag](c: Context)(t: c.Expr[Initialize[T]]): c.Expr[Initialize[T]] =
|
||||
def settingDynMacroImpl[T: c.AbsTypeTag](c: Context)(t: c.Expr[Initialize[T]]): c.Expr[Initialize[T]] =
|
||||
Instance.contImpl[T](c, InitializeInstance, InitializeConvert, MixedBuilder)(Right(t))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,21 +42,24 @@ object FullInstance extends Instance.Composed[Initialize, Task](InitializeInstan
|
|||
/** Converts an input `Tree` of type `Initialize[T]`, `Initialize[Task[T]]`, or `Task[T]` into a `Tree` of type `Initialize[Task[T]]`.*/
|
||||
object FullConvert extends Convert
|
||||
{
|
||||
def apply[T: c.TypeTag](c: Context)(in: c.Tree): c.Tree =
|
||||
if(in.tpe <:< c.typeOf[Initialize[Task[T]]])
|
||||
def apply[T: c.AbsTypeTag](c: Context)(in: c.Tree): c.Tree =
|
||||
{
|
||||
val util = appmacro.ContextUtil[c.type](c)
|
||||
if(in.tpe <:< util.atypeOf[Initialize[Task[T]]])
|
||||
in
|
||||
else if(in.tpe <:< c.typeOf[Initialize[T]])
|
||||
else if(in.tpe <:< util.atypeOf[Initialize[T]])
|
||||
{
|
||||
val i = c.Expr[Initialize[T]](in)
|
||||
c.universe.reify( Def.toITask(i.splice) ).tree
|
||||
}
|
||||
else if(in.tpe <:< c.typeOf[Task[T]])
|
||||
else if(in.tpe <:< util.atypeOf[Task[T]])
|
||||
{
|
||||
val i = c.Expr[Task[T]](in)
|
||||
c.universe.reify( Def.valueStrict[Task[T]](i.splice) ).tree
|
||||
}
|
||||
else
|
||||
c.abort(in.pos, "Unknown input type: " + in.tpe)
|
||||
}
|
||||
}
|
||||
|
||||
object TaskMacro
|
||||
|
|
@ -65,51 +68,49 @@ object TaskMacro
|
|||
final val Append1InitName = "<+="
|
||||
final val AppendNInitName = "<++="
|
||||
|
||||
def task[T](t: T): Initialize[Task[T]] = macro taskMacroImpl[T]
|
||||
def taskMacroImpl[T: c.TypeTag](c: Context)(t: c.Expr[T]): c.Expr[Initialize[Task[T]]] =
|
||||
def taskMacroImpl[T: c.AbsTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Initialize[Task[T]]] =
|
||||
Instance.contImpl[T](c, FullInstance, FullConvert, MixedBuilder)(Left(t))
|
||||
|
||||
def taskDyn[T](t: Initialize[Task[T]]): Initialize[Task[T]] = macro taskDynMacroImpl[T]
|
||||
def taskDynMacroImpl[T: c.TypeTag](c: Context)(t: c.Expr[Initialize[Task[T]]]): c.Expr[Initialize[Task[T]]] =
|
||||
def taskDynMacroImpl[T: c.AbsTypeTag](c: Context)(t: c.Expr[Initialize[Task[T]]]): c.Expr[Initialize[Task[T]]] =
|
||||
Instance.contImpl[T](c, FullInstance, FullConvert, MixedBuilder)(Right(t))
|
||||
|
||||
/** Implementation of := macro for settings. */
|
||||
def settingAssignMacroImpl[T: c.TypeTag](c: Context)(v: c.Expr[T]): c.Expr[Setting[T]] =
|
||||
def settingAssignMacroImpl[T: c.AbsTypeTag](c: Context)(v: c.Expr[T]): c.Expr[Setting[T]] =
|
||||
{
|
||||
val init = SettingMacro.settingMacroImpl[T](c)(v)
|
||||
val assign = transformMacroImpl(c)( init.tree )( AssignInitName )
|
||||
c.Expr[Setting[T]]( assign )
|
||||
}
|
||||
/** Implementation of := macro for tasks. */
|
||||
def taskAssignMacroImpl[T: c.TypeTag](c: Context)(v: c.Expr[T]): c.Expr[Setting[Task[T]]] =
|
||||
def taskAssignMacroImpl[T: c.AbsTypeTag](c: Context)(v: c.Expr[T]): c.Expr[Setting[Task[T]]] =
|
||||
{
|
||||
val init = taskMacroImpl[T](c)(v)
|
||||
val assign = transformMacroImpl(c)( init.tree )( AssignInitName )
|
||||
c.Expr[Setting[Task[T]]]( assign )
|
||||
}
|
||||
/** Implementation of += macro for tasks. */
|
||||
def taskAppend1Impl[T: c.TypeTag, U: c.TypeTag](c: Context)(v: c.Expr[U])(a: c.Expr[Append.Value[T, U]]): c.Expr[Setting[Task[T]]] =
|
||||
def taskAppend1Impl[T: c.AbsTypeTag, U: c.AbsTypeTag](c: Context)(v: c.Expr[U])(a: c.Expr[Append.Value[T, U]]): c.Expr[Setting[Task[T]]] =
|
||||
{
|
||||
val init = taskMacroImpl[U](c)(v)
|
||||
val assign = appendMacroImpl(c)( init.tree, a.tree )( Append1InitName )
|
||||
c.Expr[Setting[Task[T]]]( assign )
|
||||
}
|
||||
/** Implementation of += macro for settings. */
|
||||
def settingAppend1Impl[T: c.TypeTag, U: c.TypeTag](c: Context)(v: c.Expr[U])(a: c.Expr[Append.Value[T, U]]): c.Expr[Setting[T]] =
|
||||
def settingAppend1Impl[T: c.AbsTypeTag, U: c.AbsTypeTag](c: Context)(v: c.Expr[U])(a: c.Expr[Append.Value[T, U]]): c.Expr[Setting[T]] =
|
||||
{
|
||||
val init = SettingMacro.settingMacroImpl[U](c)(v)
|
||||
val assign = appendMacroImpl(c)( init.tree, a.tree )( Append1InitName )
|
||||
c.Expr[Setting[T]]( assign )
|
||||
}
|
||||
/** Implementation of ++= macro for tasks. */
|
||||
def taskAppendNImpl[T: c.TypeTag, U: c.TypeTag](c: Context)(vs: c.Expr[U])(a: c.Expr[Append.Values[T, U]]): c.Expr[Setting[Task[T]]] =
|
||||
def taskAppendNImpl[T: c.AbsTypeTag, U: c.AbsTypeTag](c: Context)(vs: c.Expr[U])(a: c.Expr[Append.Values[T, U]]): c.Expr[Setting[Task[T]]] =
|
||||
{
|
||||
val init = taskMacroImpl[U](c)(vs)
|
||||
val assign = appendMacroImpl(c)( init.tree, a.tree )( AppendNInitName )
|
||||
c.Expr[Setting[Task[T]]]( assign )
|
||||
}
|
||||
/** Implementation of ++= macro for settings. */
|
||||
def settingAppendNImpl[T: c.TypeTag, U: c.TypeTag](c: Context)(vs: c.Expr[U])(a: c.Expr[Append.Values[T, U]]): c.Expr[Setting[T]] =
|
||||
def settingAppendNImpl[T: c.AbsTypeTag, U: c.AbsTypeTag](c: Context)(vs: c.Expr[U])(a: c.Expr[Append.Values[T, U]]): c.Expr[Setting[T]] =
|
||||
{
|
||||
val init = SettingMacro.settingMacroImpl[U](c)(vs)
|
||||
val assign = appendMacroImpl(c)( init.tree, a.tree )( AppendNInitName )
|
||||
|
|
@ -141,7 +142,7 @@ object TaskMacro
|
|||
def value: T = macro std.TaskMacro.valueMacroImpl[T]
|
||||
}
|
||||
|
||||
def valueMacroImpl[T: c.TypeTag](c: Context): c.Expr[T] =
|
||||
def valueMacroImpl[T: c.AbsTypeTag](c: Context): c.Expr[T] =
|
||||
{
|
||||
import c.universe._
|
||||
c.macroApplication match {
|
||||
|
|
@ -149,7 +150,7 @@ object TaskMacro
|
|||
case x => unexpectedTree(x)
|
||||
}
|
||||
}
|
||||
private[this] def wrap[T: c.TypeTag](c: Context)(t: c.Tree): c.Expr[T] =
|
||||
private[this] def wrap[T: c.AbsTypeTag](c: Context)(t: c.Tree): c.Expr[T] =
|
||||
{
|
||||
val ts = c.Expr[Any](t)
|
||||
c.universe.reify { InputWrapper.wrap[T](ts.splice) }
|
||||
|
|
@ -160,20 +161,23 @@ object TaskMacro
|
|||
* This is not used for the main task/setting macros, but could be used when manipulating plain Tasks.*/
|
||||
object TaskConvert extends Convert
|
||||
{
|
||||
def apply[T: c.TypeTag](c: Context)(in: c.Tree): c.Tree =
|
||||
if(in.tpe <:< c.typeOf[Task[T]])
|
||||
def apply[T: c.AbsTypeTag](c: Context)(in: c.Tree): c.Tree =
|
||||
{
|
||||
val u = appmacro.ContextUtil[c.type](c)
|
||||
if(in.tpe <:< u.atypeOf[Task[T]])
|
||||
in
|
||||
else
|
||||
c.abort(in.pos, "Unknown input type: " + in.tpe)
|
||||
}
|
||||
}
|
||||
|
||||
object PlainTaskMacro
|
||||
{
|
||||
def task[T](t: T): Task[T] = macro taskImpl[T]
|
||||
def taskImpl[T: c.TypeTag](c: Context)(t: c.Expr[T]): c.Expr[Task[T]] =
|
||||
def taskImpl[T: c.AbsTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Task[T]] =
|
||||
Instance.contImpl[T](c, TaskInstance, TaskConvert, MixedBuilder)(Left(t))
|
||||
|
||||
def taskDyn[T](t: Task[T]): Task[T] = macro taskDynImpl[T]
|
||||
def taskDynImpl[T: c.TypeTag](c: Context)(t: c.Expr[Task[T]]): c.Expr[Task[T]] =
|
||||
def taskDynImpl[T: c.AbsTypeTag](c: Context)(t: c.Expr[Task[T]]): c.Expr[Task[T]] =
|
||||
Instance.contImpl[T](c, TaskInstance, TaskConvert, MixedBuilder)(Right(t))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,15 +18,17 @@ final class ContextUtil[C <: Context](val ctx: C)
|
|||
{
|
||||
import ctx.universe.{Apply=>ApplyTree,_}
|
||||
|
||||
val alistType = ctx.typeOf[AList[KList]]
|
||||
val alist: Symbol = alistType.typeSymbol.companionSymbol
|
||||
val alistTC: Type = alistType.typeConstructor
|
||||
lazy val alistType = ctx.typeOf[AList[KList]]
|
||||
lazy val alist: Symbol = alistType.typeSymbol.companionSymbol
|
||||
lazy val alistTC: Type = alistType.typeConstructor
|
||||
|
||||
/** Modifiers for a local val.*/
|
||||
val localModifiers = Modifiers(NoFlags)
|
||||
lazy val localModifiers = Modifiers(NoFlags)
|
||||
|
||||
def getPos(sym: Symbol) = if(sym eq null) NoPosition else sym.pos
|
||||
|
||||
def atypeOf[T](implicit att: AbsTypeTag[T]): Type = att.tpe
|
||||
|
||||
/** Constructs a unique term name with the given prefix within this Context.
|
||||
* (The current implementation uses Context.fresh, which increments*/
|
||||
def freshTermName(prefix: String) = newTermName(ctx.fresh("$" + prefix))
|
||||
|
|
@ -58,7 +60,7 @@ final class ContextUtil[C <: Context](val ctx: C)
|
|||
owner.asInstanceOf[global.Symbol].newSyntheticTypeParam(prefix, 0L).asInstanceOf[ctx.universe.TypeSymbol]
|
||||
}
|
||||
/** The type representing the type constructor `[X] X` */
|
||||
val idTC: Type =
|
||||
lazy val idTC: Type =
|
||||
{
|
||||
val tvar = newTypeVariable(NoSymbol)
|
||||
polyType(tvar :: Nil, refVar(tvar))
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ trait Instance
|
|||
}
|
||||
trait Convert
|
||||
{
|
||||
def apply[T: c.TypeTag](c: scala.reflect.makro.Context)(in: c.Tree): c.Tree
|
||||
def apply[T: c.AbsTypeTag](c: scala.reflect.makro.Context)(in: c.Tree): c.Tree
|
||||
}
|
||||
trait MonadInstance extends Instance
|
||||
{
|
||||
|
|
@ -80,18 +80,19 @@ object Instance
|
|||
* If this is for multi-input flatMap (app followed by flatMap),
|
||||
* this should be the argument wrapped in Right.
|
||||
*/
|
||||
def contImpl[T: c.TypeTag](c: Context, i: Instance with Singleton, convert: Convert, builder: TupleBuilder)(t: Either[c.Expr[T], c.Expr[i.M[T]]])(
|
||||
implicit tt: c.TypeTag[T], mt: c.TypeTag[i.M[T]], it: c.TypeTag[i.type]): c.Expr[i.M[T]] =
|
||||
def contImpl[T](c: Context, i: Instance with Singleton, convert: Convert, builder: TupleBuilder)(t: Either[c.Expr[T], c.Expr[i.M[T]]])(
|
||||
implicit tt: c.AbsTypeTag[T], it: c.TypeTag[i.type]): c.Expr[i.M[T]] =
|
||||
{
|
||||
import c.universe.{Apply=>ApplyTree,_}
|
||||
|
||||
val util = ContextUtil[c.type](c)
|
||||
val mTC: Type = util.extractTC(i, InstanceTCName)
|
||||
val mttpe: Type = appliedType(mTC, tt.tpe :: Nil).normalize
|
||||
|
||||
// the tree for the macro argument
|
||||
val (tree, treeType) = t match {
|
||||
case Left(l) => (l.tree, tt.tpe.normalize)
|
||||
case Right(r) => (r.tree, mt.tpe.normalize)
|
||||
case Right(r) => (r.tree, mttpe)
|
||||
}
|
||||
|
||||
val instanceSym = util.singleton(i)
|
||||
|
|
@ -202,7 +203,7 @@ object Instance
|
|||
tree match
|
||||
{
|
||||
case ApplyTree(TypeApply(fun, t :: Nil), qual :: Nil) if isWrapper(fun) =>
|
||||
val tag = c.TypeTag(t.tpe)
|
||||
val tag = c.AbsTypeTag(t.tpe)
|
||||
addType(t.tpe, convert(c)(qual)(tag) )
|
||||
case _ => super.transform(tree)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue