mirror of https://github.com/sbt/sbt.git
def taskIf[A](a: A): Initialize[Task[A]]
Make `Def.taskIf` accept pure `A` type, as opposed to `Def.task { ... }`.
This commit is contained in:
parent
c6f62293f1
commit
45e8426d27
|
|
@ -235,7 +235,7 @@ object Def extends Init[Scope] with TaskMacroExtra with InitializeImplicits {
|
|||
def inputTask[T](t: T): Def.Initialize[InputTask[T]] = macro inputTaskMacroImpl[T]
|
||||
def inputTaskDyn[T](t: Def.Initialize[Task[T]]): Def.Initialize[InputTask[T]] =
|
||||
macro inputTaskDynMacroImpl[T]
|
||||
def taskIf[T](a: Def.Initialize[Task[T]]): Def.Initialize[Task[T]] = macro taskIfMacroImpl[T]
|
||||
def taskIf[T](a: T): Def.Initialize[Task[T]] = macro taskIfMacroImpl[T]
|
||||
|
||||
private[sbt] def selectITask[A, B](
|
||||
fab: Initialize[Task[Either[A, B]]],
|
||||
|
|
|
|||
|
|
@ -120,10 +120,10 @@ object TaskMacro {
|
|||
|
||||
def taskIfMacroImpl[A: c.WeakTypeTag](
|
||||
c: blackbox.Context
|
||||
)(a: c.Expr[Initialize[Task[A]]]): c.Expr[Initialize[Task[A]]] = {
|
||||
)(a: c.Expr[A]): c.Expr[Initialize[Task[A]]] = {
|
||||
import c.universe._
|
||||
def mkIfS(cond: Tree, thenp: Tree, elsep: Tree): Tree =
|
||||
q"""Def.ifS(Def.task($cond))($thenp)($elsep)"""
|
||||
q"""Def.ifS(Def.task($cond))(Def.task($thenp))(Def.task($elsep))"""
|
||||
a.tree match {
|
||||
case Block(stat, If(cond, thenp, elsep)) =>
|
||||
c.Expr[Initialize[Task[A]]](mkIfS(Block(stat, cond), thenp, elsep))
|
||||
|
|
|
|||
|
|
@ -2129,8 +2129,8 @@ object Defaults extends BuildCommon {
|
|||
|
||||
def dependencyResolutionTask: Def.Initialize[Task[DependencyResolution]] =
|
||||
Def.taskIf {
|
||||
if (useCoursier.value) Def.task { CoursierDependencyResolution(csrConfiguration.value) } else
|
||||
Def.task { IvyDependencyResolution(ivyConfiguration.value, CustomHttp.okhttpClient.value) }
|
||||
if (useCoursier.value) CoursierDependencyResolution(csrConfiguration.value)
|
||||
else IvyDependencyResolution(ivyConfiguration.value, CustomHttp.okhttpClient.value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2949,16 +2949,14 @@ object Classpaths {
|
|||
|
||||
def publishTask(config: TaskKey[PublishConfiguration]): Initialize[Task[Unit]] =
|
||||
Def.taskIf {
|
||||
if ((publish / skip).value)
|
||||
Def.task {
|
||||
val s = streams.value
|
||||
val ref = thisProjectRef.value
|
||||
s.log.debug(s"Skipping publish* for ${ref.project}")
|
||||
} else
|
||||
Def.task {
|
||||
val s = streams.value
|
||||
IvyActions.publish(ivyModule.value, config.value, s.log)
|
||||
}
|
||||
if ((publish / skip).value) {
|
||||
val s = streams.value
|
||||
val ref = thisProjectRef.value
|
||||
s.log.debug(s"Skipping publish* for ${ref.project}")
|
||||
} else {
|
||||
val s = streams.value
|
||||
IvyActions.publish(ivyModule.value, config.value, s.log)
|
||||
}
|
||||
} tag (Tags.Publish, Tags.Network)
|
||||
|
||||
val moduleIdJsonKeyFormat: sjsonnew.JsonKeyFormat[ModuleID] =
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ lazy val root = (project in file("."))
|
|||
trueAction := { IO.write(output.value, s"true\n", append = true) },
|
||||
falseAction := { IO.write(output.value, s"false\n", append = true) },
|
||||
foo := (Def.taskIf {
|
||||
if (condition.value) trueAction
|
||||
else falseAction
|
||||
if (condition.value) trueAction.value
|
||||
else falseAction.value
|
||||
}).value,
|
||||
TaskKey[Unit]("check") := {
|
||||
val lines = IO.read(output.value).linesIterator.toList
|
||||
|
|
|
|||
Loading…
Reference in New Issue