From 52de082b2e73865c085d52ec84e9ea7787ca70e7 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 27 Mar 2017 13:16:55 +0100 Subject: [PATCH] Add OptJsonWriter to SettingKey --- .../src/main/scala/sbt/Structure.scala | 19 ++++++++++--------- .../src/main/scala/sbt/std/KeyMacro.scala | 11 +++++++++-- main/src/main/scala/sbt/Keys.scala | 1 + 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/main-settings/src/main/scala/sbt/Structure.scala b/main-settings/src/main/scala/sbt/Structure.scala index 5752c7e96..c06c34bf0 100644 --- a/main-settings/src/main/scala/sbt/Structure.scala +++ b/main-settings/src/main/scala/sbt/Structure.scala @@ -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]) } diff --git a/main-settings/src/main/scala/sbt/std/KeyMacro.scala b/main-settings/src/main/scala/sbt/std/KeyMacro.scala index 243eeb6fb..bf0af5ee1 100644 --- a/main-settings/src/main/scala/sbt/std/KeyMacro.scala +++ b/main-settings/src/main/scala/sbt/std/KeyMacro.scala @@ -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")`.""") diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index bb42f5105..0559fc834 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -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,