mirror of https://github.com/sbt/sbt.git
Add OptJsonWriter to SettingKey
This commit is contained in:
parent
ad2f91e357
commit
52de082b2e
|
|
@ -3,19 +3,20 @@
|
|||
*/
|
||||
package sbt
|
||||
|
||||
/** An abstraction on top of Settings for build configuration and task definition. */
|
||||
import scala.language.experimental.macros
|
||||
|
||||
import java.io.File
|
||||
|
||||
import ConcurrentRestrictions.Tag
|
||||
import Def.{ Initialize, KeyedInitialize, ScopedKey, Setting, setting }
|
||||
import sbt.io.{ FileFilter, PathFinder }
|
||||
import sbt.io.syntax._
|
||||
import std.TaskExtra.{ task => mktask, _ }
|
||||
import sbt.internal.util.Types._
|
||||
import sbt.internal.util.{ ~>, AList, AttributeKey, Settings, SourcePosition }
|
||||
import sbt.util.OptJsonWriter
|
||||
import sbt.ConcurrentRestrictions.Tag
|
||||
import sbt.Def.{ Initialize, KeyedInitialize, ScopedKey, Setting, setting }
|
||||
import std.TaskExtra.{ task => mktask, _ }
|
||||
|
||||
import language.experimental.macros
|
||||
/** An abstraction on top of Settings for build configuration and task definition. */
|
||||
|
||||
sealed trait Scoped { def scope: Scope; val key: AttributeKey[_] }
|
||||
|
||||
|
|
@ -471,17 +472,17 @@ object TaskKey {
|
|||
|
||||
/** Constructs SettingKeys, which are associated with a value to define a basic setting.*/
|
||||
object SettingKey {
|
||||
def apply[T: Manifest](label: String, description: String = "", rank: Int = KeyRanks.DefaultSettingRank): SettingKey[T] =
|
||||
def apply[T: Manifest: OptJsonWriter](label: String, description: String = "", rank: Int = KeyRanks.DefaultSettingRank): SettingKey[T] =
|
||||
apply(AttributeKey[T](label, description, rank))
|
||||
|
||||
def apply[T: Manifest](label: String, description: String, extend1: Scoped, extendN: Scoped*): SettingKey[T] =
|
||||
def apply[T: Manifest: OptJsonWriter](label: String, description: String, extend1: Scoped, extendN: Scoped*): SettingKey[T] =
|
||||
apply(AttributeKey[T](label, description, extendScoped(extend1, extendN)))
|
||||
|
||||
def apply[T: Manifest](label: String, description: String, rank: Int, extend1: Scoped, extendN: Scoped*): SettingKey[T] =
|
||||
def apply[T: Manifest: OptJsonWriter](label: String, description: String, rank: Int, extend1: Scoped, extendN: Scoped*): SettingKey[T] =
|
||||
apply(AttributeKey[T](label, description, extendScoped(extend1, extendN), rank))
|
||||
|
||||
def apply[T](akey: AttributeKey[T]): SettingKey[T] =
|
||||
new SettingKey[T] { val key = akey; def scope = Scope.ThisScope }
|
||||
|
||||
def local[T: Manifest]: SettingKey[T] = apply[T](AttributeKey.local[T])
|
||||
def local[T: Manifest: OptJsonWriter]: SettingKey[T] = apply[T](AttributeKey.local[T])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ package std
|
|||
import scala.annotation.tailrec
|
||||
import scala.reflect.macros._
|
||||
|
||||
import sbt.util.OptJsonWriter
|
||||
|
||||
private[sbt] object KeyMacro {
|
||||
def settingKeyImpl[T: c.WeakTypeTag](c: blackbox.Context)(description: c.Expr[String]): c.Expr[SettingKey[T]] =
|
||||
keyImpl[T, SettingKey[T]](c) { (name, mf) =>
|
||||
c.universe.reify { SettingKey[T](name.splice, description.splice)(mf.splice) }
|
||||
keyImpl2[T, SettingKey[T]](c) { (name, mf, ojw) =>
|
||||
c.universe.reify { SettingKey[T](name.splice, description.splice)(mf.splice, ojw.splice) }
|
||||
}
|
||||
def taskKeyImpl[T: c.WeakTypeTag](c: blackbox.Context)(description: c.Expr[String]): c.Expr[TaskKey[T]] =
|
||||
keyImpl[T, TaskKey[T]](c) { (name, mf) =>
|
||||
|
|
@ -23,6 +25,11 @@ private[sbt] object KeyMacro {
|
|||
): c.Expr[S] =
|
||||
f(getName(c), getImplicit[Manifest[T]](c))
|
||||
|
||||
private def keyImpl2[T: c.WeakTypeTag, S: c.WeakTypeTag](c: blackbox.Context)(
|
||||
f: (c.Expr[String], c.Expr[Manifest[T]], c.Expr[OptJsonWriter[T]]) => c.Expr[S]
|
||||
): c.Expr[S] =
|
||||
f(getName(c), getImplicit[Manifest[T]](c), getImplicit[OptJsonWriter[T]](c))
|
||||
|
||||
private def getName[S: c.WeakTypeTag, T: c.WeakTypeTag](c: blackbox.Context): c.Expr[String] = {
|
||||
import c.universe._
|
||||
val enclosingValName = definingValName(c, methodName => s"""$methodName must be directly assigned to a val, such as `val x = $methodName[Int]("description")`.""")
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import sbt.internal.io.WatchState
|
|||
import sbt.internal.util.{ AttributeKey, CacheStore, SourcePosition }
|
||||
|
||||
import sbt.librarymanagement.Configurations.CompilerPlugin
|
||||
import sbt.librarymanagement.LibraryManagementCodec._
|
||||
import sbt.librarymanagement.{
|
||||
Artifact,
|
||||
Configuration,
|
||||
|
|
|
|||
Loading…
Reference in New Issue