Add toTaskable to Init/+Task, for tuple syntax

This commit is contained in:
Dale Wijnand 2020-02-16 21:09:14 +00:00
parent 722022ae97
commit 23702b6432
2 changed files with 36 additions and 1 deletions

View File

@ -19,7 +19,7 @@ import Util._
import sbt.util.Show
/** A concrete settings system that uses `sbt.Scope` for the scope type. */
object Def extends Init[Scope] with TaskMacroExtra {
object Def extends Init[Scope] with TaskMacroExtra with InitializeImplicits {
type Classpath = Seq[Attributed[File]]
def settings(ss: SettingsDefinition*): Seq[Setting[_]] = ss.flatMap(_.settings)
@ -261,6 +261,14 @@ object Def extends Init[Scope] with TaskMacroExtra {
def taskKey[T](description: String): TaskKey[T] = macro std.KeyMacro.taskKeyImpl[T]
def inputKey[T](description: String): InputKey[T] = macro std.KeyMacro.inputKeyImpl[T]
class InitOps[T](private val x: Initialize[T]) extends AnyVal {
def toTaskable: Taskable[T] = x
}
class InitTaskOps[T](private val x: Initialize[Task[T]]) extends AnyVal {
def toTaskable: Taskable[T] = x
}
private[sbt] def dummy[T: Manifest](name: String, description: String): (TaskKey[T], Task[T]) =
(TaskKey[T](name, description, DTask), dummyTask(name))
@ -303,3 +311,12 @@ trait TaskMacroExtra {
@deprecated("unused", "") in: State => Parser[T]
): std.ParserInput[T] = ???
}
sealed trait InitializeImplicits0 { self: Def.type =>
implicit def initOps[T](x: Def.Initialize[T]): Def.InitOps[T] = new Def.InitOps(x)
}
sealed trait InitializeImplicits extends InitializeImplicits0 { self: Def.type =>
implicit def initTaskOps[T](x: Def.Initialize[Task[T]]): Def.InitTaskOps[T] =
new Def.InitTaskOps(x)
}

View File

@ -0,0 +1,18 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.test
import sbt._
import sbt.Def.Initialize
import sbt.TupleSyntax._
object TupleSyntaxTest {
def t1[T](a: SettingKey[T], b: TaskKey[T], c: Initialize[T], d: Initialize[Task[T]]) = {
(a, b, c.toTaskable, d.toTaskable).map((x: T, y: T, z: T, w: T) => "" + x + y + z + w)
}
}