Skip to content

Commit a4f7b08

Browse files
authored
Merge pull request scala#72 from MasseGuillaume/cross
Major Rewrite refactor: fix scala#19, fix scala#56
2 parents 3dd389f + 282e480 commit a4f7b08

File tree

67 files changed

+942
-873
lines changed

Some content is hidden

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

67 files changed

+942
-873
lines changed

.travis.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,24 @@ matrix:
5454
# | oraclejdk8 | 2.13.0-M4 | jvm | | |
5555
# | oraclejdk8 | 2.13.0-M4 | js | 0.6.23 | |
5656
# | oraclejdk8 | 2.12.6 | jvm | | true |
57-
57+
5858
before_script: ./checkCLA.sh
5959
script:
6060
- java -version
6161
- admin/build.sh
6262

63-
before_cache:
64-
- find $HOME/.sbt -name "*.lock" | xargs rm
65-
- find $HOME/.ivy2/cache -name "ivydata-*.properties" | xargs rm
6663
cache:
6764
directories:
68-
- $HOME/.ivy2/cache
69-
- $HOME/.sbt/boot
70-
- $HOME/.sbt/launchers
65+
- "$HOME/.sbt/0.13/dependency"
66+
- "$HOME/.sbt/boot/scala*"
67+
- "$HOME/.sbt/launchers"
68+
- "$HOME/.ivy2/cache"
69+
- "$HOME/.coursier"
70+
71+
before_cache:
72+
- du -h -d 1 $HOME/.ivy2/cache
73+
- du -h -d 2 $HOME/.sbt/
74+
- find $HOME/.sbt -name "*.lock" -type f -delete
75+
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -type f -delete
76+
- find $HOME/.ivy2/cache -name "*scalafix*.xml" -type f -delete
77+
- rm -rf $HOME/.ivy2/local

CONTRIBUTING.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
### Sbt Projects
66

7-
- `scala-collection-compat` project (in the root directory): implementation of the compatibility library ;
8-
- In directory `scalafix/` there is an independent build containing the implementation of the migration tool.
7+
- `compat` project: implementation of the compatibility library ;
8+
- `scalafix*`: implementation of the migration tool.
99

1010
## Migration tool
1111

@@ -31,16 +31,16 @@ Even better, instead of providing a diff, you can directly add it as a test case
3131

3232
2. Add a file in the `scalafix/input/src/main/scala/fix/` directory with code
3333
that uses the standard collections:
34-
34+
3535
~~~ scala
3636
class toIteratorVsIterator(xs: Iterable[Int]) {
3737
xs.toIterator
3838
}
3939
~~~
4040

41-
3. Add a corresponding file in the `scalafix/output/src/main/scala/fix/` directory
41+
3. Add a corresponding file in the `scalafix/output213/src/main/scala/fix/` directory
4242
with the same code but using the strawman:
43-
43+
4444
~~~ scala
4545
import strawman.collection.Iterable
4646

@@ -50,8 +50,8 @@ class toIteratorVsIterator(xs: Iterable[Int]) {
5050
~~~
5151

5252
4. Check that your code example compiles
53-
- run sbt from the `scalafix/` directory
54-
and then run the following tasks `; input/compile ; output/compile`;
53+
- run sbt
54+
and then run the following task `compile`;
5555

5656
5. Commit your changes, push your branch to your fork and create a pull request.
5757

@@ -68,10 +68,10 @@ migration tool on the input files and check whether the result matches the
6868
expected output files:
6969

7070
~~~
71-
> tests/test
71+
> scalafixTests/test
7272
~~~
7373

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

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,3 @@ The migration tool is not exhaustive and we will continue to improve
4848
it over time. If you encounter a use case that’s not supported, please
4949
report it as described in the
5050
[contributing documentation](CONTRIBUTING.md#migration-tool).
51-
52-
### Migrating a 2.12 code base to 2.13
53-
54-
Run the following sbt task on your project:
55-
56-
~~~
57-
> scalafix github:scala/scala-collection-compat/NewCollections
58-
~~~

admin/build.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -e
44

@@ -18,20 +18,30 @@ set -e
1818

1919
RELEASE_COMBO=true
2020

21-
if [[ "$TEST_SCALAFIX" == "true" ]]; then
22-
cd scalafix && sbt input/compile output/compile tests/test
23-
exit 0
21+
if [ "$SCALAJS_VERSION" = "" ]; then
22+
if [[ "$TEST_SCALAFIX" == "true" ]]; then
23+
projectPrefix="scalafixRules"
24+
else
25+
projectPrefix="compat"
26+
fi
27+
else
28+
projectPrefix="compatJS"
2429
fi
2530

26-
if [ "$SCALAJS_VERSION" = "" ]; then
27-
projectPrefix="scala-collection-compat"
31+
if [[ "$TEST_SCALAFIX" == "true" ]]; then
32+
crossScalaVersion="noop"
33+
testProjectPrefix="scalafixTests"
2834
else
29-
projectPrefix="scala-collection-compatJS"
35+
crossScalaVersion="++$TRAVIS_SCALA_VERSION"
36+
testProjectPrefix="$projectPrefix"
3037
fi
3138

3239
verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
3340
tagPat="^v$verPat(#.*)?$"
3441

42+
publishVersion="noop"
43+
publishTask="noop"
44+
3545
if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
3646
tagVer=$(echo $TRAVIS_TAG | sed s/#.*// | sed s/^v//)
3747
publishVersion='set every version := "'$tagVer'"'
@@ -52,4 +62,4 @@ if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
5262
fi
5363
fi
5464
55-
sbt -Dhttps.protocols=TLSv1.2 "++$TRAVIS_SCALA_VERSION" "$publishVersion" "$projectPrefix/clean" "$projectPrefix/test" "$projectPrefix/publishLocal" "$publishTask"
65+
sbt -Dhttps.protocols=TLSv1.2 -sbt-dir=/home/travis/.sbt ";$crossScalaVersion ;$publishVersion ;$projectPrefix/clean ;$testProjectPrefix/test ;$projectPrefix/publishLocal ;$publishTask"

admin/encryptEnvVars.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
#
34
# Encrypt sonatype credentials so that they can be
45
# decrypted in trusted builds on Travis CI.

admin/genKeyPair.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
#
34
# Generates a key pair for this repository to sign artifacts.
45
# Encrypt the private key and its passphrase in trusted builds

build.sbt

Lines changed: 104 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import sbtcrossproject.{crossProject, CrossType}
21
import ScalaModulePlugin._
2+
import sbtcrossproject.{crossProject, CrossType}
3+
import _root_.scalafix.Versions.{version => scalafixVersion, scala212 => scalafixScala212}
34

4-
inThisBuild(Seq(
5-
crossScalaVersions := Seq("2.12.6", "2.13.0-M4", "2.11.12")
6-
))
5+
lazy val root = project
6+
.in(file("."))
7+
.settings(dontPublish)
8+
.aggregate(
9+
compatJVM, compatJS,
10+
scalafixRules, scalafixInput, scalafixTests,
11+
scalafixOutput212, scalafixOutput213
12+
)
13+
.disablePlugins(ScalafixPlugin)
714

8-
disablePlugins(JvmPlugin)
15+
// == Core Libraries ==
916

10-
lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
17+
lazy val compat = crossProject(JSPlatform, JVMPlatform)
1118
.withoutSuffixFor(JVMPlatform)
1219
.crossType(CrossType.Pure)
13-
.in(file("."))
20+
.in(file("compat"))
1421
.settings(scalaModuleSettings)
1522
.jvmSettings(scalaModuleSettingsJVM)
1623
.settings(
@@ -36,6 +43,94 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
3643
fork in Test := false // Scala.js cannot run forked tests
3744
)
3845
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
46+
.disablePlugins(ScalafixPlugin)
3947

40-
lazy val `scala-collection-compatJVM` = `scala-collection-compat`.jvm
41-
lazy val `scala-collection-compatJS` = `scala-collection-compat`.js
48+
lazy val compatJVM = compat.jvm
49+
lazy val compatJS = compat.js
50+
51+
lazy val scalafixRules = project
52+
.in(file("scalafix/rules"))
53+
.settings(scalaModuleSettings)
54+
.settings(scalaModuleSettingsJVM)
55+
.settings(
56+
name := "scala-collection-migrations",
57+
scalaVersion := scalafixScala212,
58+
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % scalafixVersion
59+
)
60+
61+
// == Scalafix Test Setup ==
62+
63+
lazy val scalafixInput = project
64+
.in(file("scalafix/input"))
65+
.settings(dontPublish)
66+
.settings(
67+
scalaVersion := scalafixScala212,
68+
scalafixSourceroot := sourceDirectory.in(Compile).value
69+
)
70+
71+
lazy val scalafixOutput212 = project
72+
.in(file("scalafix/output212"))
73+
.settings(scalaVersion := scalafixScala212)
74+
.settings(dontPublish)
75+
.dependsOn(compatJVM)
76+
77+
lazy val scalafixOutput213 = project
78+
.in(file("scalafix/output213"))
79+
.settings(scala213Settings)
80+
.settings(dontPublish)
81+
82+
lazy val scalafixOutput213Failure = project
83+
.in(file("scalafix/output213-failure"))
84+
.settings(scala213Settings)
85+
.settings(dontPublish)
86+
87+
lazy val scalafixTests = project
88+
.in(file("scalafix/tests"))
89+
.settings(dontPublish)
90+
.settings(
91+
scalaVersion := scalafixScala212,
92+
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % scalafixVersion % Test cross CrossVersion.full,
93+
buildInfoPackage := "fix",
94+
buildInfoKeys := Seq[BuildInfoKey](
95+
"inputSourceroot" ->
96+
sourceDirectory.in(scalafixInput, Compile).value,
97+
"output212Sourceroot" ->
98+
sourceDirectory.in(scalafixOutput212, Compile).value,
99+
"output213Sourceroot" ->
100+
sourceDirectory.in(scalafixOutput213, Compile).value,
101+
"output213FailureSourceroot" ->
102+
sourceDirectory.in(scalafixOutput213Failure, Compile).value,
103+
"inputClassdirectory" ->
104+
classDirectory.in(scalafixInput, Compile).value
105+
),
106+
test in Test := (test in Test).dependsOn(
107+
compile in (scalafixOutput212, Compile),
108+
compile in (scalafixOutput213, Compile)
109+
).value
110+
)
111+
.dependsOn(scalafixInput, scalafixRules)
112+
.enablePlugins(BuildInfoPlugin)
113+
114+
lazy val dontPublish = Seq(
115+
publishArtifact := false,
116+
packagedArtifacts := Map.empty,
117+
publish := {},
118+
publishLocal := {}
119+
)
120+
121+
lazy val scala212 = "2.12.6"
122+
lazy val scala213 = "2.13.0-M4"
123+
124+
lazy val scala213Settings = Seq(
125+
resolvers += "scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
126+
scalaVersion := scala213
127+
)
128+
129+
// required by sbt-scala-module
130+
inThisBuild(Seq(
131+
crossScalaVersions := Seq(scala212, scala213, "2.11.12"),
132+
commands += Command.command("noop") { state =>
133+
println("noop")
134+
state
135+
}
136+
))

project/plugins.sbt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ else
55
// see https://github.com/scala/sbt-scala-module/issues/35
66
Seq(addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.3"))
77

8-
val scalaJSVersion =
9-
Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23")
8+
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23")
109

11-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
12-
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.4.0")
13-
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14")
10+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
11+
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0")
12+
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14")
13+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.10")
14+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")

scalafix/build.sbt

Lines changed: 0 additions & 52 deletions
This file was deleted.

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
rule = "scala:fix.Scalacollectioncompat_newcollections"
2+
rule = "scala:fix.CrossCompat"
33
*/
44
package fix
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
rule = "scala:fix.Scalacollectioncompat_newcollections"
2+
rule = "scala:fix.CrossCompat"
33
*/
44
package fix
55

0 commit comments

Comments
 (0)