From 833024b1d9fb737dfd81a94d2f739f066ee6401f Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 21 Feb 2021 20:39:14 -0500 Subject: [PATCH] `in` is no longer in Ref https://github.com/sbt/sbt/pull/6309 This deprecates the sbt 0.13 style `key in (Compile, intask)` syntax. --- main-settings/src/main/scala/sbt/Previous.scala | 7 ++++--- main-settings/src/main/scala/sbt/Scope.scala | 16 ++++++++++++++++ .../src/main/scala/sbt/SlashSyntax.scala | 7 +++++++ .../src/main/scala/sbt/Structure.scala | 17 +++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/main-settings/src/main/scala/sbt/Previous.scala b/main-settings/src/main/scala/sbt/Previous.scala index aaa61c320..acd6ba18f 100644 --- a/main-settings/src/main/scala/sbt/Previous.scala +++ b/main-settings/src/main/scala/sbt/Previous.scala @@ -10,6 +10,7 @@ package sbt import sbt.Def.{ Initialize, ScopedKey } import sbt.Previous._ import sbt.Scope.Global +import sbt.SlashSyntax0._ import sbt.internal.util._ import sbt.std.TaskExtra._ import sbt.util.StampedFormat @@ -146,7 +147,7 @@ object Previous { /** Public as a macro implementation detail. Do not call directly. */ def runtime[T](skey: TaskKey[T])(implicit format: JsonFormat[T]): Initialize[Task[Option[T]]] = { - val inputs = (cache in Global) zip Def.validated(skey, selfRefOk = true) zip (references in Global) + val inputs = (Global / cache) zip Def.validated(skey, selfRefOk = true) zip (Global / references) inputs { case ((prevTask, resolved), refs) => val key = Key(resolved, resolved) @@ -159,9 +160,9 @@ object Previous { def runtimeInEnclosingTask[T](skey: TaskKey[T])( implicit format: JsonFormat[T] ): Initialize[Task[Option[T]]] = { - val inputs = (cache in Global) + val inputs = (Global / cache) .zip(Def.validated(skey, selfRefOk = true)) - .zip(references in Global) + .zip(Global / references) .zip(Def.resolvedScoped) inputs { case (((prevTask, resolved), refs), inTask: ScopedKey[Task[_]] @unchecked) => diff --git a/main-settings/src/main/scala/sbt/Scope.scala b/main-settings/src/main/scala/sbt/Scope.scala index 28c3daa3d..4fa31f51c 100644 --- a/main-settings/src/main/scala/sbt/Scope.scala +++ b/main-settings/src/main/scala/sbt/Scope.scala @@ -20,16 +20,29 @@ final case class Scope( task: ScopeAxis[AttributeKey[_]], extra: ScopeAxis[AttributeMap] ) { + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(project: Reference, config: ConfigKey): Scope = copy(project = Select(project), config = Select(config)) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(config: ConfigKey, task: AttributeKey[_]): Scope = copy(config = Select(config), task = Select(task)) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(project: Reference, task: AttributeKey[_]): Scope = copy(project = Select(project), task = Select(task)) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(project: Reference, config: ConfigKey, task: AttributeKey[_]): Scope = copy(project = Select(project), config = Select(config), task = Select(task)) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(project: Reference): Scope = copy(project = Select(project)) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(config: ConfigKey): Scope = copy(config = Select(config)) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(task: AttributeKey[_]): Scope = copy(task = Select(task)) override def toString: String = this match { @@ -43,6 +56,9 @@ object Scope { val Global: Scope = Scope(Zero, Zero, Zero, Zero) val GlobalScope: Scope = Global + private[sbt] final val inIsDeprecated = + "`in` is deprecated; migrate to slash syntax - https://www.scala-sbt.org/1.x/docs/Migrating-from-sbt-013x.html#slash" + def resolveScope(thisScope: Scope, current: URI, rootProject: URI => String): Scope => Scope = resolveProject(current, rootProject) compose replaceThis(thisScope) compose subThisProject diff --git a/main-settings/src/main/scala/sbt/SlashSyntax.scala b/main-settings/src/main/scala/sbt/SlashSyntax.scala index db940e220..ea5b9d007 100644 --- a/main-settings/src/main/scala/sbt/SlashSyntax.scala +++ b/main-settings/src/main/scala/sbt/SlashSyntax.scala @@ -9,6 +9,7 @@ package sbt import sbt.librarymanagement.Configuration import sbt.internal.util.AttributeKey +import scala.annotation.nowarn /** * SlashSyntax implements the slash syntax to scope keys for build.sbt DSL. @@ -60,19 +61,25 @@ object SlashSyntax { sealed trait HasSlashKey { protected def scope: Scope + @nowarn final def /[K](key: Scoped.ScopingSetting[K]): K = key in scope } sealed trait HasSlashKeyOrAttrKey extends HasSlashKey { + @nowarn final def /(key: AttributeKey[_]): RichScope = new RichScope(scope in key) } /** RichReference wraps a reference to provide the `/` operator for scoping. */ final class RichReference(protected val scope: Scope) extends HasSlashKeyOrAttrKey { + @nowarn def /(c: ConfigKey): RichConfiguration = new RichConfiguration(scope in c) + + @nowarn def /(c: Configuration): RichConfiguration = new RichConfiguration(scope in c) // This is for handling `Zero / Zero / name`. + @nowarn def /(configAxis: ScopeAxis[ConfigKey]): RichConfiguration = new RichConfiguration(scope.copy(config = configAxis)) } diff --git a/main-settings/src/main/scala/sbt/Structure.scala b/main-settings/src/main/scala/sbt/Structure.scala index 83c57ec16..6ac79293a 100644 --- a/main-settings/src/main/scala/sbt/Structure.scala +++ b/main-settings/src/main/scala/sbt/Structure.scala @@ -68,6 +68,7 @@ sealed abstract class SettingKey[T] final def scopedKey: ScopedKey[T] = ScopedKey(scope, key) + // @deprecated(Scope.inIsDeprecated, "1.5.0") final def in(scope: Scope): SettingKey[T] = Scoped.scopedSetting(Scope.replaceThis(this.scope)(scope), this.key) @@ -140,6 +141,7 @@ sealed abstract class TaskKey[T] def scopedKey: ScopedKey[Task[T]] = ScopedKey(scope, key) + // @deprecated(Scope.inIsDeprecated, "1.5.0") def in(scope: Scope): TaskKey[T] = Scoped.scopedTask(Scope.replaceThis(this.scope)(scope), this.key) @@ -206,6 +208,7 @@ sealed trait InputKey[T] def scopedKey: ScopedKey[InputTask[T]] = ScopedKey(scope, key) + // @deprecated(Scope.inIsDeprecated, "1.5.0") def in(scope: Scope): InputKey[T] = Scoped.scopedInput(Scope.replaceThis(this.scope)(scope), this.key) @@ -244,18 +247,32 @@ object Scoped { * */ sealed trait ScopingSetting[ResultType] { + // @deprecated(Scope.inIsDeprecated, "1.5.0") def in(s: Scope): ResultType + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(p: Reference): ResultType = in(Select(p), This, This) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(t: Scoped): ResultType = in(This, This, Select(t.key)) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(c: ConfigKey): ResultType = in(This, Select(c), This) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(c: ConfigKey, t: Scoped): ResultType = in(This, Select(c), Select(t.key)) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(p: Reference, c: ConfigKey): ResultType = in(Select(p), Select(c), This) + + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(p: Reference, t: Scoped): ResultType = in(Select(p), This, Select(t.key)) + @deprecated(Scope.inIsDeprecated, "1.5.0") def in(p: Reference, c: ConfigKey, t: Scoped): ResultType = in(Select(p), Select(c), Select(t.key)) + @deprecated(Scope.inIsDeprecated, "1.5.0") def in( p: ScopeAxis[Reference], c: ScopeAxis[ConfigKey],