Skip to content

Commit

Permalink
Merge pull request #6328 from eed3si9n/wip/in
Browse files Browse the repository at this point in the history
`in` is no longer in
  • Loading branch information
eed3si9n committed Feb 22, 2021
2 parents e4118fb + 695261a commit e6fec6b
Show file tree
Hide file tree
Showing 44 changed files with 394 additions and 282 deletions.
7 changes: 4 additions & 3 deletions main-settings/src/main/scala/sbt/Previous.scala
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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) =>
Expand Down
16 changes: 16 additions & 0 deletions main-settings/src/main/scala/sbt/Scope.scala
Expand Up @@ -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 {
Expand All @@ -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

Expand Down
9 changes: 8 additions & 1 deletion main-settings/src/main/scala/sbt/SlashSyntax.scala
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}
Expand All @@ -85,7 +92,7 @@ object SlashSyntax {
}

/** RichScope wraps a general scope to provide the `/` operator for scoping. */
final class RichScope(protected val scope: Scope) extends HasSlashKey
final class RichScope(protected val scope: Scope) extends HasSlashKeyOrAttrKey

}

Expand Down
17 changes: 17 additions & 0 deletions main-settings/src/main/scala/sbt/Structure.scala
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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],
Expand Down
2 changes: 2 additions & 0 deletions main-settings/src/test/scala/sbt/BuildSettingsInstances.scala
Expand Up @@ -26,6 +26,7 @@ import sbt.ConfigKey
import sbt.librarymanagement.syntax._
import sbt.{ InputKey, SettingKey, TaskKey }
import sbt.internal.util.{ AttributeKey, AttributeMap }
import scala.annotation.nowarn

object BuildSettingsInstances {
val genFile: Gen[File] = Gen.oneOf(new File("."), new File("/tmp")) // for now..
Expand Down Expand Up @@ -99,6 +100,7 @@ object BuildSettingsInstances {
def genSettingKey[A: Manifest]: Gen[SettingKey[A]] = genLabel map (x => SettingKey[A](x.value))
def genTaskKey[A: Manifest]: Gen[TaskKey[A]] = genLabel map (x => TaskKey[A](x.value))

@nowarn
def withScope[K <: Scoped.ScopingSetting[K]](keyGen: Gen[K]): Arbitrary[K] = Arbitrary {
Gen.frequency(
5 -> keyGen,
Expand Down
3 changes: 3 additions & 0 deletions main-settings/src/test/scala/sbt/ScopeDisplaySpec.scala
Expand Up @@ -10,10 +10,13 @@ package sbt
import org.scalatest.FlatSpec
import sbt.internal.util.{ AttributeKey, AttributeMap }
import sbt.io.syntax.file
import scala.annotation.nowarn

class ScopeDisplaySpec extends FlatSpec {
val project = ProjectRef(file("foo/bar"), "bar")
val mangledName = "bar_slash_blah_blah_blah"

@nowarn
val scopedKey = Def.ScopedKey(Scope.Global in project, AttributeKey[Task[String]](mangledName))
val am = AttributeMap.empty.put(Scope.customShowString, "blah")
val sanitizedKey = scopedKey.copy(scope = scopedKey.scope.copy(extra = Select(am)))
Expand Down
2 changes: 2 additions & 0 deletions main-settings/src/test/scala/sbt/SlashSyntaxSpec.scala
Expand Up @@ -16,7 +16,9 @@ import sbt.ConfigKey
import sbt.internal.util.AttributeKey

import BuildSettingsInstances._
import scala.annotation.nowarn

@nowarn
object SlashSyntaxSpec extends Properties("SlashSyntax") with SlashSyntax {
property("Global / key == key in Global") = {
forAll((k: Key) => expectValue(k in Global)(Global / k))
Expand Down
19 changes: 10 additions & 9 deletions main/src/main/scala/sbt/Cross.scala
Expand Up @@ -11,6 +11,7 @@ import java.io.File

import sbt.Def.{ ScopedKey, Setting }
import sbt.Keys._
import sbt.SlashSyntax0._
import sbt.internal.Act
import sbt.internal.CommandStrings._
import sbt.internal.inc.ScalaInstance
Expand Down Expand Up @@ -102,9 +103,9 @@ object Cross {

private def crossVersions(extracted: Extracted, proj: ResolvedReference): Seq[String] = {
import extracted._
(crossScalaVersions in proj get structure.data) getOrElse {
((proj / crossScalaVersions) get structure.data) getOrElse {
// reading scalaVersion is a one-time deal
(scalaVersion in proj get structure.data).toSeq
((proj / scalaVersion) get structure.data).toSeq
}
}

Expand Down Expand Up @@ -358,16 +359,16 @@ object Cross {
instance match {
case Some((home, inst)) =>
Seq(
scalaVersion in scope := version,
crossScalaVersions in scope := scalaVersions,
scalaHome in scope := Some(home),
scalaInstance in scope := inst
scope / scalaVersion := version,
scope / crossScalaVersions := scalaVersions,
scope / scalaHome := Some(home),
scope / scalaInstance := inst
)
case None =>
Seq(
scalaVersion in scope := version,
crossScalaVersions in scope := scalaVersions,
scalaHome in scope := None
scope / scalaVersion := version,
scope / crossScalaVersions := scalaVersions,
scope / scalaHome := None
)
}
}
Expand Down

0 comments on commit e6fec6b

Please sign in to comment.