Skip to content

Commit 7713c76

Browse files
authored
Merge pull request #121 from MasseGuillaume/simplify-cross-compile
Simplify cross-compilation for scalafix output
2 parents d6a03c5 + 1d29c1f commit 7713c76

22 files changed

+71
-66
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
- `compat` project: implementation of the compatibility library ;
88
- `scalafix*`: implementation of the migration tool.
9+
- `binary-compat`: preserve binary compatibility when using the compat library on 2.12
910

1011
## Migration tool
1112

1213
Several levels of contribution are possible!
1314

1415
### Report a missing case
1516

16-
Create an issue tagged with the
17-
[migration](https://github.com/scala/collection-strawman/labels/migration) label.
17+
Create an issue [scala-collection-compat/issues](https://github.com/scala/scala-collection-compat/issues).
1818
Embrace `diff`s to describe differences between the standard collections and
19-
the strawman:
19+
the new collection:
2020

2121
~~~ diff
2222
- xs.toIterator
@@ -33,18 +33,18 @@ Even better, instead of providing a diff, you can directly add it as a test case
3333
that uses the standard collections:
3434

3535
~~~ scala
36-
class toIteratorVsIterator(xs: Iterable[Int]) {
36+
class ToIteratorVsIteratorSrc(xs: Iterable[Int]) {
3737
xs.toIterator
3838
}
3939
~~~
4040

4141
3. Add a corresponding file in the `scalafix/output/src/main/scala/fix/` directory
42-
with the same code but using the strawman:
42+
with the same code but using the new collection:
4343

4444
~~~ scala
4545
import scala.collection.compat._
4646

47-
class toIteratorVsIterator(xs: Iterable[Int]) {
47+
class ToIteratorVsIteratorSrc(xs: Iterable[Int]) {
4848
xs.iterator
4949
}
5050
~~~
@@ -63,55 +63,35 @@ Then maybe someone will take over and implement your use case… or maybe you wi
6363
Even better, complete the migration tool implementation to support the missing case!
6464

6565
After you have added the missing case (see previous section), run the following
66-
sbt task (with sbt started from the `scalafix/` directory) to run the
67-
migration tool on the input files and check whether the result matches the
66+
sbt task to run the migration tool on the input files and check whether the result matches the
6867
expected output files:
6968

7069
~~~
7170
> scalafix-tests/test
7271
~~~
7372

74-
Fix the implementation of the rule (in the
75-
`rules/src/main/scala/fix/NewCollections.scala` file) until the
73+
Fix the implementation of the rule (in the `rules/src/main/scala/fix/NewCollections.scala` file) until the
7674
tests are green. You can find more help about the scalafix API in its
7775
[documentation](https://scalacenter.github.io/scalafix/docs/rule-authors/setup).
7876

7977

8078
### Scalafix Teskit Directory Layout
8179

80+
8281
```
83-
.
84-
├── data |
85-
│   └── src |
86-
│   └── main |
87-
│   └── scala | Project to avoid duplicating code between input and output
88-
├── input |
89-
│   └── src |
90-
│   └── main |
91-
│   ├── scala | Input that cross-compile
92-
│   └── scala-2.12 | 2.12 specific input
93-
├── output |
94-
│   └── src |
95-
│   └── main |
96-
│   └── scala | Output that cross-compile
97-
├── output212 |
98-
│   └── src |
99-
│   └── main |
100-
│   └── scala-2.12 | 2.12 specific output
101-
├── output213 |
102-
│   └── src |
103-
│   └── main |
104-
│   └── scala | 2.13 specific output (from a cross-compiled input)
105-
├── output213-failure |
106-
│   └── src |
107-
│   └── main |
108-
│   └── scala | 2.13 specific output that cannot be migrated due to technical limitations
109-
├── rules |
110-
│   └── src |
111-
│   └── main |
112-
│   └── scala | Rule implementations
113-
└── tests |
114-
└── src |
115-
└── test |
116-
└── scala | Scalafix testkit launcher (useful to run a single input file)
82+
+------------------+-----+-----------------+
83+
| |Input| Output |
84+
| | 2.12| 2.11| 2.12| 2.13|
85+
+------------------+-----+-----+-----+-----+
86+
|data | X | X | X | X |
87+
|input | X | | | |
88+
|output | | X | X | X |
89+
|output212 | | | X | |
90+
|output212+ | | | X | X |
91+
|output213 | | | | X |
92+
|output213-failure | | | | X |
93+
+------------------+-----+-----+-----+-----+
94+
95+
rules: Rule implementations
96+
tests: Scalafix testkit launcher (useful to run a single input file)
11797
```

build.sbt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,29 @@ val `scalafix-output` = MultiScalaProject("scalafix-output", "scalafix/output",
183183
lazy val output212 = Def.setting((baseDirectory in ThisBuild).value / "scalafix/output212/src/main")
184184
lazy val addOutput212 = unmanagedSourceDirectories in Compile += output212.value / "scala"
185185

186+
lazy val output212Plus = Def.setting((baseDirectory in ThisBuild).value / "scalafix/output212+/src/main")
187+
lazy val addOutput212Plus = unmanagedSourceDirectories in Compile += output212Plus.value / "scala"
188+
186189
lazy val output213 = Def.setting((baseDirectory in ThisBuild).value / "scalafix/output213/src/main")
187190
lazy val addOutput213 = unmanagedSourceDirectories in Compile += output213.value / "scala"
188191

189-
lazy val `scalafix-output211` = `scalafix-output`(scala211, _.dependsOn(`scalafix-data211`))
190-
lazy val `scalafix-output212` = `scalafix-output`(scala212, _.settings(addOutput212).dependsOn(`scalafix-data212`))
192+
lazy val `scalafix-output211` = `scalafix-output`(
193+
scala211,
194+
_.dependsOn(`scalafix-data211`)
195+
)
196+
197+
198+
lazy val `scalafix-output212` = `scalafix-output`(
199+
scala212,
200+
_.settings(addOutput212)
201+
.settings(addOutput212Plus)
202+
.dependsOn(`scalafix-data212`)
203+
)
204+
191205
lazy val `scalafix-output213` = `scalafix-output`(
192206
scala213,
193207
_.settings(addOutput213)
208+
.settings(addOutput212Plus)
194209
.settings(scala213Settings)
195210
.dependsOn(`scalafix-data213`)
196211
)
@@ -213,7 +228,9 @@ lazy val `scalafix-tests` = project
213228
"inputSourceroot" -> sourceDirectory.in(`scalafix-input`, Compile).value,
214229
"outputSourceroot" -> (baseDirectory in ThisBuild).value / "scalafix/output/src/main",
215230
"output212Sourceroot" -> output212.value,
231+
"output212PlusSourceroot" -> output212Plus.value,
216232
"output213Sourceroot" -> output213.value,
233+
"output212PlusSourceroot" -> output212Plus.value,
217234
"output213FailureSourceroot" -> sourceDirectory.in(`scalafix-output213-failure`, Compile).value,
218235
"inputClassdirectory" -> classDirectory.in(`scalafix-input`, Compile).value
219236
),

project/MultiScalaProject.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ trait MultiScala {
4040
(baseDirectory in ThisBuild).value / base / "src" / "main" / "scala",
4141
unmanagedSourceDirectories in Compile +=
4242
(baseDirectory in ThisBuild).value / base / "src" / "main" / ("scala-" + scalaBinaryVersion.value),
43+
unmanagedSourceDirectories in Compile ++= {
44+
val sourceDir = (baseDirectory in ThisBuild).value / base / "src" / "main"
45+
CrossVersion.partialVersion(scalaVersion.value) match {
46+
case Some((2, n)) if n >= 12 => List(sourceDir / "scala-2.12+")
47+
case _ => Nil
48+
}
49+
},
4350
unmanagedSourceDirectories in Test +=
4451
(baseDirectory in ThisBuild).value / base / "src" / "test" / "scala",
4552
unmanagedResourceDirectories in Compile +=

scalafix/input/src/main/scala-2.12/fix/BreakoutSrc212.scala renamed to scalafix/input/src/main/scala/fix/BreakoutSrc212Plus.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package fix
66
import scala.collection.mutable
77
import scala.collection.breakOut
88

9-
object BreakoutSrc212 {
9+
object BreakoutSrc212Plus {
1010
List(1 -> "1").map(x => x)(breakOut): mutable.SortedMap[Int, String]
1111
List(1 -> "1").map(x => x)(breakOut): mutable.TreeMap[Int, String]
1212
}

scalafix/input/src/main/scala/fix/CanBuildFromNegSrc.scala renamed to scalafix/input/src/main/scala/fix/CanBuildFromNegSrc213Failure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.language.higherKinds
77

88
import collection.generic.CanBuildFrom
99

10-
class CanBuildFromNegSrc() {
10+
object CanBuildFromNegSrc213Failure {
1111

1212
// negative test
1313
def g[C0, A, C1[_]](c0: C0)(implicit cbf3: CanBuildFrom[C0, A, C1[A]]): C1[A] = {

scalafix/input/src/main/scala/fix/CanBuildFromSrc.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.language.higherKinds
77

88
import collection.generic.CanBuildFrom
99

10-
class CanBuildFromSrc() {
10+
object CanBuildFromSrc {
1111

1212
def f[C0, A, C1[_]](c0: C0)(implicit
1313
cbf: CanBuildFrom[Nothing, Int, C1[Int]],

scalafix/input/src/main/scala/fix/CompanionSrc.scala renamed to scalafix/input/src/main/scala/fix/CompanionSrc212.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package fix
66
import scala.collection.{immutable => i, mutable => m}
77
import scala.{collection => c}
88

9-
object CompanionSrc {
9+
object CompanionSrc212 {
1010

1111
(null: c.IndexedSeq[Int]).companion
1212
(null: c.Iterable[Int]).companion

scalafix/input/src/main/scala/fix/RetainSrc.scala renamed to scalafix/input/src/main/scala/fix/RetainSrc213.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package fix
55

66
import scala.collection.mutable.{Map, Set}
77

8-
class MethodRenames(xs: Map[Int, Int], ys: Set[Int]) {
8+
class RetainSrc213(xs: Map[Int, Int], ys: Set[Int]) {
99
xs.retain((_, _) => true)
1010
xs.retain{case (x, y) => true}
1111
ys.retain(_ => true)

scalafix/input/src/main/scala/fix/Roughly212Src.scala renamed to scalafix/input/src/main/scala/fix/RoughlySrc.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package fix
1010
import scala.{collection => c}
1111
import scala.collection.{immutable => i, mutable => m}
1212

13-
object Roughly212Src {
13+
object RoughlySrc {
1414

1515
def id[T](x: T): T = x
1616
def f[T](x: T): Boolean = true

scalafix/input/src/main/scala/fix/Roughly213Src.scala renamed to scalafix/input/src/main/scala/fix/RoughlySrc213.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Roughly = {
77
*/
88
package fix
99

10-
class Roughly213Src() {
10+
object RoughlySrc213 {
1111
val s = Stream(1, 2, 3)
1212
s.append(List(4, 5, 6))
1313
1 #:: 2 #:: 3 #:: Stream.Empty

scalafix/input/src/main/scala-2.12/fix/SortedSrc212.scala renamed to scalafix/input/src/main/scala/fix/SortedSrc212Plus.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package fix
55

66
import scala.collection.{mutable => m}
77

8-
object SortedSrc212 {
8+
object SortedSrc212Plus {
99
m.SortedMap(1 -> 1).from(0)
1010
m.TreeMap(1 -> 1).from(0)
1111
m.SortedMap(1 -> 1).to(0)

scalafix/input/src/main/scala/fix/TupleNZippedSrc.scala renamed to scalafix/input/src/main/scala/fix/TupleNZippedSrc213.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ rule = "scala:fix.NewCollections"
44
package fix
55

66
import scala.language.postfixOps
7-
object Collectionstrawman_v0_Tuple2Zipped {
7+
object Tuple2ZippedSrc213 {
88
def zipped(xs: List[Int], ys: List[Int]): Unit = {
99
(xs, ys).zipped
1010
(xs,ys).zipped
@@ -19,7 +19,7 @@ object Collectionstrawman_v0_Tuple2Zipped {
1919
def coll(x: Int): List[Int] = ???
2020
}
2121

22-
object Collectionstrawman_v0_Tuple3Zipped {
22+
object Tuple3ZippedSrc213 {
2323
def zipped(xs: List[Int], ys: List[Int], zs: List[Int]): Unit = {
2424
(xs, ys, zs).zipped
2525
(xs,ys,zs).zipped

scalafix/output/src/main/scala/fix/CanBuildFromSrc.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.language.higherKinds
77

88
import scala.collection.compat._
99

10-
class CanBuildFromSrc() {
10+
object CanBuildFromSrc {
1111

1212
def f[C0, A, C1[_]](c0: C0)(implicit
1313
cbf: Factory[Int, C1[Int]],

scalafix/output/src/main/scala/fix/Roughly212Src.scala renamed to scalafix/output/src/main/scala/fix/RoughlySrc.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package fix
66
import scala.{collection => c}
77
import scala.collection.{immutable => i, mutable => m}
88

9-
object Roughly212Src {
9+
object RoughlySrc {
1010

1111
def id[T](x: T): T = x
1212
def f[T](x: T): Boolean = true

scalafix/output212/src/main/scala-2.12/fix/BreakoutSrc212.scala renamed to scalafix/output212+/src/main/scala/fix/BreakoutSrc212Plus.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package fix
66
import scala.collection.mutable
77
import scala.collection.compat._
88

9-
object BreakoutSrc212 {
9+
object BreakoutSrc212Plus {
1010
scala.collection.mutable.SortedMap.from(List(1 -> "1").iterator.map(x => x)): mutable.SortedMap[Int, String]
1111
scala.collection.mutable.TreeMap.from(List(1 -> "1").iterator.map(x => x)): mutable.TreeMap[Int, String]
1212
}

scalafix/output212/src/main/scala-2.12/fix/SortedSrc212.scala renamed to scalafix/output212+/src/main/scala/fix/SortedSrc212Plus.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package fix
66
import scala.collection.{mutable => m}
77
import scala.collection.compat._
88

9-
object SortedSrc212 {
9+
object SortedSrc212Plus {
1010
m.SortedMap(1 -> 1).rangeFrom(0)
1111
m.TreeMap(1 -> 1).rangeFrom(0)
1212
m.SortedMap(1 -> 1).rangeTo(0)

scalafix/output212/src/main/scala/fix/CompanionSrc.scala renamed to scalafix/output212/src/main/scala/fix/CompanionSrc212.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.collection.{immutable => i, mutable => m}
77
import scala.{collection => c}
88
import scala.collection.compat._
99

10-
object CompanionSrc {
10+
object CompanionSrc212 {
1111

1212
(null: c.IndexedSeq[Int]).iterableFactory
1313
(null: c.Iterable[Int]).iterableFactory

scalafix/output213-failure/src/main/scala/fix/CanBuildFromNegSrc.scala renamed to scalafix/output213-failure/src/main/scala/fix/CanBuildFromNegSrc213Failure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.language.higherKinds
77

88
import collection.generic.CanBuildFrom
99

10-
class CanBuildFromNegSrc() {
10+
object CanBuildFromNegSrc213Failure {
1111

1212
// negative test
1313
def g[C0, A, C1[_]](c0: C0)(implicit cbf3: CanBuildFrom[C0, A, C1[A]]): C1[A] = {

scalafix/output213/src/main/scala/fix/RetainSrc.scala renamed to scalafix/output213/src/main/scala/fix/RetainSrc213.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package fix
55

66
import scala.collection.mutable.{Map, Set}
77

8-
class MethodRenames(xs: Map[Int, Int], ys: Set[Int]) {
8+
class RetainSrc213(xs: Map[Int, Int], ys: Set[Int]) {
99
xs.filterInPlace{case (_, _) => true}
1010
xs.filterInPlace{case (x, y) => true}
1111
ys.filterInPlace(_ => true)

scalafix/output213/src/main/scala/fix/Roughly213Src.scala renamed to scalafix/output213/src/main/scala/fix/RoughlySrc213.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package fix
55

6-
class Roughly213Src() {
6+
object RoughlySrc213 {
77
val s = LazyList(1, 2, 3)
88
s.lazyAppendedAll(List(4, 5, 6))
99
1 #:: 2 #:: 3 #:: LazyList.Empty

scalafix/output213/src/main/scala/fix/TupleNZippedSrc.scala renamed to scalafix/output213/src/main/scala/fix/TupleNZippedSrc213.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package fix
55

66
import scala.language.postfixOps
7-
object Collectionstrawman_v0_Tuple2Zipped {
7+
object Tuple2ZippedSrc213 {
88
def zipped(xs: List[Int], ys: List[Int]): Unit = {
99
xs.lazyZip(ys)
1010
xs.lazyZip(ys)
@@ -19,7 +19,7 @@ object Collectionstrawman_v0_Tuple2Zipped {
1919
def coll(x: Int): List[Int] = ???
2020
}
2121

22-
object Collectionstrawman_v0_Tuple3Zipped {
22+
object Tuple3ZippedSrc213 {
2323
def zipped(xs: List[Int], ys: List[Int], zs: List[Int]): Unit = {
2424
xs.lazyZip(ys).lazyZip(zs)
2525
xs.lazyZip(ys).lazyZip(zs)

scalafix/tests/src/test/scala/fix/ScalafixTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ScalafixTests
1212
AbsolutePath(BuildInfo.outputSourceroot),
1313
AbsolutePath(BuildInfo.output212Sourceroot),
1414
AbsolutePath(BuildInfo.output213Sourceroot),
15+
AbsolutePath(BuildInfo.output212PlusSourceroot),
1516
AbsolutePath(BuildInfo.output213FailureSourceroot)
1617
)
1718
) {

0 commit comments

Comments
 (0)