Skip to content

Commit e6fec6b

Browse files
authored
Merge pull request #6328 from eed3si9n/wip/in
`in` is no longer in
2 parents e4118fb + 695261a commit e6fec6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+394
-282
lines changed

main-settings/src/main/scala/sbt/Previous.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package sbt
1010
import sbt.Def.{ Initialize, ScopedKey }
1111
import sbt.Previous._
1212
import sbt.Scope.Global
13+
import sbt.SlashSyntax0._
1314
import sbt.internal.util._
1415
import sbt.std.TaskExtra._
1516
import sbt.util.StampedFormat
@@ -146,7 +147,7 @@ object Previous {
146147

147148
/** Public as a macro implementation detail. Do not call directly. */
148149
def runtime[T](skey: TaskKey[T])(implicit format: JsonFormat[T]): Initialize[Task[Option[T]]] = {
149-
val inputs = (cache in Global) zip Def.validated(skey, selfRefOk = true) zip (references in Global)
150+
val inputs = (Global / cache) zip Def.validated(skey, selfRefOk = true) zip (Global / references)
150151
inputs {
151152
case ((prevTask, resolved), refs) =>
152153
val key = Key(resolved, resolved)
@@ -159,9 +160,9 @@ object Previous {
159160
def runtimeInEnclosingTask[T](skey: TaskKey[T])(
160161
implicit format: JsonFormat[T]
161162
): Initialize[Task[Option[T]]] = {
162-
val inputs = (cache in Global)
163+
val inputs = (Global / cache)
163164
.zip(Def.validated(skey, selfRefOk = true))
164-
.zip(references in Global)
165+
.zip(Global / references)
165166
.zip(Def.resolvedScoped)
166167
inputs {
167168
case (((prevTask, resolved), refs), inTask: ScopedKey[Task[_]] @unchecked) =>

main-settings/src/main/scala/sbt/Scope.scala

+16
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,29 @@ final case class Scope(
2020
task: ScopeAxis[AttributeKey[_]],
2121
extra: ScopeAxis[AttributeMap]
2222
) {
23+
@deprecated(Scope.inIsDeprecated, "1.5.0")
2324
def in(project: Reference, config: ConfigKey): Scope =
2425
copy(project = Select(project), config = Select(config))
26+
27+
@deprecated(Scope.inIsDeprecated, "1.5.0")
2528
def in(config: ConfigKey, task: AttributeKey[_]): Scope =
2629
copy(config = Select(config), task = Select(task))
30+
31+
@deprecated(Scope.inIsDeprecated, "1.5.0")
2732
def in(project: Reference, task: AttributeKey[_]): Scope =
2833
copy(project = Select(project), task = Select(task))
34+
35+
@deprecated(Scope.inIsDeprecated, "1.5.0")
2936
def in(project: Reference, config: ConfigKey, task: AttributeKey[_]): Scope =
3037
copy(project = Select(project), config = Select(config), task = Select(task))
38+
39+
@deprecated(Scope.inIsDeprecated, "1.5.0")
3140
def in(project: Reference): Scope = copy(project = Select(project))
41+
42+
@deprecated(Scope.inIsDeprecated, "1.5.0")
3243
def in(config: ConfigKey): Scope = copy(config = Select(config))
44+
45+
@deprecated(Scope.inIsDeprecated, "1.5.0")
3346
def in(task: AttributeKey[_]): Scope = copy(task = Select(task))
3447

3548
override def toString: String = this match {
@@ -43,6 +56,9 @@ object Scope {
4356
val Global: Scope = Scope(Zero, Zero, Zero, Zero)
4457
val GlobalScope: Scope = Global
4558

59+
private[sbt] final val inIsDeprecated =
60+
"`in` is deprecated; migrate to slash syntax - https://www.scala-sbt.org/1.x/docs/Migrating-from-sbt-013x.html#slash"
61+
4662
def resolveScope(thisScope: Scope, current: URI, rootProject: URI => String): Scope => Scope =
4763
resolveProject(current, rootProject) compose replaceThis(thisScope) compose subThisProject
4864

main-settings/src/main/scala/sbt/SlashSyntax.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package sbt
99

1010
import sbt.librarymanagement.Configuration
1111
import sbt.internal.util.AttributeKey
12+
import scala.annotation.nowarn
1213

1314
/**
1415
* SlashSyntax implements the slash syntax to scope keys for build.sbt DSL.
@@ -60,19 +61,25 @@ object SlashSyntax {
6061

6162
sealed trait HasSlashKey {
6263
protected def scope: Scope
64+
@nowarn
6365
final def /[K](key: Scoped.ScopingSetting[K]): K = key in scope
6466
}
6567

6668
sealed trait HasSlashKeyOrAttrKey extends HasSlashKey {
69+
@nowarn
6770
final def /(key: AttributeKey[_]): RichScope = new RichScope(scope in key)
6871
}
6972

7073
/** RichReference wraps a reference to provide the `/` operator for scoping. */
7174
final class RichReference(protected val scope: Scope) extends HasSlashKeyOrAttrKey {
75+
@nowarn
7276
def /(c: ConfigKey): RichConfiguration = new RichConfiguration(scope in c)
77+
78+
@nowarn
7379
def /(c: Configuration): RichConfiguration = new RichConfiguration(scope in c)
7480

7581
// This is for handling `Zero / Zero / name`.
82+
@nowarn
7683
def /(configAxis: ScopeAxis[ConfigKey]): RichConfiguration =
7784
new RichConfiguration(scope.copy(config = configAxis))
7885
}
@@ -85,7 +92,7 @@ object SlashSyntax {
8592
}
8693

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

9097
}
9198

main-settings/src/main/scala/sbt/Structure.scala

+17
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ sealed abstract class SettingKey[T]
6868

6969
final def scopedKey: ScopedKey[T] = ScopedKey(scope, key)
7070

71+
// @deprecated(Scope.inIsDeprecated, "1.5.0")
7172
final def in(scope: Scope): SettingKey[T] =
7273
Scoped.scopedSetting(Scope.replaceThis(this.scope)(scope), this.key)
7374

@@ -140,6 +141,7 @@ sealed abstract class TaskKey[T]
140141

141142
def scopedKey: ScopedKey[Task[T]] = ScopedKey(scope, key)
142143

144+
// @deprecated(Scope.inIsDeprecated, "1.5.0")
143145
def in(scope: Scope): TaskKey[T] =
144146
Scoped.scopedTask(Scope.replaceThis(this.scope)(scope), this.key)
145147

@@ -206,6 +208,7 @@ sealed trait InputKey[T]
206208

207209
def scopedKey: ScopedKey[InputTask[T]] = ScopedKey(scope, key)
208210

211+
// @deprecated(Scope.inIsDeprecated, "1.5.0")
209212
def in(scope: Scope): InputKey[T] =
210213
Scoped.scopedInput(Scope.replaceThis(this.scope)(scope), this.key)
211214

@@ -244,18 +247,32 @@ object Scoped {
244247
*
245248
*/
246249
sealed trait ScopingSetting[ResultType] {
250+
// @deprecated(Scope.inIsDeprecated, "1.5.0")
247251
def in(s: Scope): ResultType
248252

253+
@deprecated(Scope.inIsDeprecated, "1.5.0")
249254
def in(p: Reference): ResultType = in(Select(p), This, This)
255+
256+
@deprecated(Scope.inIsDeprecated, "1.5.0")
250257
def in(t: Scoped): ResultType = in(This, This, Select(t.key))
258+
259+
@deprecated(Scope.inIsDeprecated, "1.5.0")
251260
def in(c: ConfigKey): ResultType = in(This, Select(c), This)
261+
262+
@deprecated(Scope.inIsDeprecated, "1.5.0")
252263
def in(c: ConfigKey, t: Scoped): ResultType = in(This, Select(c), Select(t.key))
264+
265+
@deprecated(Scope.inIsDeprecated, "1.5.0")
253266
def in(p: Reference, c: ConfigKey): ResultType = in(Select(p), Select(c), This)
267+
268+
@deprecated(Scope.inIsDeprecated, "1.5.0")
254269
def in(p: Reference, t: Scoped): ResultType = in(Select(p), This, Select(t.key))
255270

271+
@deprecated(Scope.inIsDeprecated, "1.5.0")
256272
def in(p: Reference, c: ConfigKey, t: Scoped): ResultType =
257273
in(Select(p), Select(c), Select(t.key))
258274

275+
@deprecated(Scope.inIsDeprecated, "1.5.0")
259276
def in(
260277
p: ScopeAxis[Reference],
261278
c: ScopeAxis[ConfigKey],

main-settings/src/test/scala/sbt/BuildSettingsInstances.scala

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import sbt.ConfigKey
2626
import sbt.librarymanagement.syntax._
2727
import sbt.{ InputKey, SettingKey, TaskKey }
2828
import sbt.internal.util.{ AttributeKey, AttributeMap }
29+
import scala.annotation.nowarn
2930

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

103+
@nowarn
102104
def withScope[K <: Scoped.ScopingSetting[K]](keyGen: Gen[K]): Arbitrary[K] = Arbitrary {
103105
Gen.frequency(
104106
5 -> keyGen,

main-settings/src/test/scala/sbt/ScopeDisplaySpec.scala

+3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ package sbt
1010
import org.scalatest.FlatSpec
1111
import sbt.internal.util.{ AttributeKey, AttributeMap }
1212
import sbt.io.syntax.file
13+
import scala.annotation.nowarn
1314

1415
class ScopeDisplaySpec extends FlatSpec {
1516
val project = ProjectRef(file("foo/bar"), "bar")
1617
val mangledName = "bar_slash_blah_blah_blah"
18+
19+
@nowarn
1720
val scopedKey = Def.ScopedKey(Scope.Global in project, AttributeKey[Task[String]](mangledName))
1821
val am = AttributeMap.empty.put(Scope.customShowString, "blah")
1922
val sanitizedKey = scopedKey.copy(scope = scopedKey.scope.copy(extra = Select(am)))

main-settings/src/test/scala/sbt/SlashSyntaxSpec.scala

+2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import sbt.ConfigKey
1616
import sbt.internal.util.AttributeKey
1717

1818
import BuildSettingsInstances._
19+
import scala.annotation.nowarn
1920

21+
@nowarn
2022
object SlashSyntaxSpec extends Properties("SlashSyntax") with SlashSyntax {
2123
property("Global / key == key in Global") = {
2224
forAll((k: Key) => expectValue(k in Global)(Global / k))

main/src/main/scala/sbt/Cross.scala

+10-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import java.io.File
1111

1212
import sbt.Def.{ ScopedKey, Setting }
1313
import sbt.Keys._
14+
import sbt.SlashSyntax0._
1415
import sbt.internal.Act
1516
import sbt.internal.CommandStrings._
1617
import sbt.internal.inc.ScalaInstance
@@ -102,9 +103,9 @@ object Cross {
102103

103104
private def crossVersions(extracted: Extracted, proj: ResolvedReference): Seq[String] = {
104105
import extracted._
105-
(crossScalaVersions in proj get structure.data) getOrElse {
106+
((proj / crossScalaVersions) get structure.data) getOrElse {
106107
// reading scalaVersion is a one-time deal
107-
(scalaVersion in proj get structure.data).toSeq
108+
((proj / scalaVersion) get structure.data).toSeq
108109
}
109110
}
110111

@@ -358,16 +359,16 @@ object Cross {
358359
instance match {
359360
case Some((home, inst)) =>
360361
Seq(
361-
scalaVersion in scope := version,
362-
crossScalaVersions in scope := scalaVersions,
363-
scalaHome in scope := Some(home),
364-
scalaInstance in scope := inst
362+
scope / scalaVersion := version,
363+
scope / crossScalaVersions := scalaVersions,
364+
scope / scalaHome := Some(home),
365+
scope / scalaInstance := inst
365366
)
366367
case None =>
367368
Seq(
368-
scalaVersion in scope := version,
369-
crossScalaVersions in scope := scalaVersions,
370-
scalaHome in scope := None
369+
scope / scalaVersion := version,
370+
scope / crossScalaVersions := scalaVersions,
371+
scope / scalaHome := None
371372
)
372373
}
373374
}

0 commit comments

Comments
 (0)