Skip to content

Major Rewrite refactor: fix #19, fix #56 #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 29, 2018
21 changes: 14 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,24 @@ matrix:
# | oraclejdk8 | 2.13.0-M4 | jvm | | |
# | oraclejdk8 | 2.13.0-M4 | js | 0.6.23 | |
# | oraclejdk8 | 2.12.6 | jvm | | true |

before_script: ./checkCLA.sh
script:
- java -version
- admin/build.sh

before_cache:
- find $HOME/.sbt -name "*.lock" | xargs rm
- find $HOME/.ivy2/cache -name "ivydata-*.properties" | xargs rm
cache:
directories:
- $HOME/.ivy2/cache
- $HOME/.sbt/boot
- $HOME/.sbt/launchers
- "$HOME/.sbt/0.13/dependency"
- "$HOME/.sbt/boot/scala*"
- "$HOME/.sbt/launchers"
- "$HOME/.ivy2/cache"
- "$HOME/.coursier"

before_cache:
- du -h -d 1 $HOME/.ivy2/cache
- du -h -d 2 $HOME/.sbt/
- find $HOME/.sbt -name "*.lock" -type f -delete
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -type f -delete
- find $HOME/.ivy2/cache -name "*scalafix*.xml" -type f -delete
- rm -rf $HOME/.ivy2/local
18 changes: 9 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

### Sbt Projects

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

## Migration tool

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

2. Add a file in the `scalafix/input/src/main/scala/fix/` directory with code
that uses the standard collections:

~~~ scala
class toIteratorVsIterator(xs: Iterable[Int]) {
xs.toIterator
}
~~~

3. Add a corresponding file in the `scalafix/output/src/main/scala/fix/` directory
3. Add a corresponding file in the `scalafix/output213/src/main/scala/fix/` directory
with the same code but using the strawman:

~~~ scala
import strawman.collection.Iterable

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

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

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

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

~~~
> tests/test
> scalafixTests/test
~~~

Fix the implementation of the rule (in the
`rules/src/main/scala/fix/Scalacollectioncompat_v0.scala` file) until the
`rules/src/main/scala/fix/NewCollections.scala` file) until the
tests are green. You can find more help about the scalafix API in its
[documentation](https://scalacenter.github.io/scalafix/docs/rule-authors/setup).
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,3 @@ The migration tool is not exhaustive and we will continue to improve
it over time. If you encounter a use case that’s not supported, please
report it as described in the
[contributing documentation](CONTRIBUTING.md#migration-tool).

### Migrating a 2.12 code base to 2.13

Run the following sbt task on your project:

~~~
> scalafix github:scala/scala-collection-compat/NewCollections
~~~
26 changes: 18 additions & 8 deletions admin/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand All @@ -18,20 +18,30 @@ set -e

RELEASE_COMBO=true

if [[ "$TEST_SCALAFIX" == "true" ]]; then
cd scalafix && sbt input/compile output/compile tests/test
exit 0
if [ "$SCALAJS_VERSION" = "" ]; then
if [[ "$TEST_SCALAFIX" == "true" ]]; then
projectPrefix="scalafixRules"
else
projectPrefix="compat"
fi
else
projectPrefix="compatJS"
fi

if [ "$SCALAJS_VERSION" = "" ]; then
projectPrefix="scala-collection-compat"
if [[ "$TEST_SCALAFIX" == "true" ]]; then
crossScalaVersion="noop"
testProjectPrefix="scalafixTests"
else
projectPrefix="scala-collection-compatJS"
crossScalaVersion="++$TRAVIS_SCALA_VERSION"
testProjectPrefix="$projectPrefix"
fi

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

publishVersion="noop"
publishTask="noop"

if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
tagVer=$(echo $TRAVIS_TAG | sed s/#.*// | sed s/^v//)
publishVersion='set every version := "'$tagVer'"'
Expand All @@ -52,4 +62,4 @@ if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
fi
fi

sbt -Dhttps.protocols=TLSv1.2 "++$TRAVIS_SCALA_VERSION" "$publishVersion" "$projectPrefix/clean" "$projectPrefix/test" "$projectPrefix/publishLocal" "$publishTask"
sbt -Dhttps.protocols=TLSv1.2 -sbt-dir=/home/travis/.sbt ";$crossScalaVersion ;$publishVersion ;$projectPrefix/clean ;$testProjectPrefix/test ;$projectPrefix/publishLocal ;$publishTask"
3 changes: 2 additions & 1 deletion admin/encryptEnvVars.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash

#
# Encrypt sonatype credentials so that they can be
# decrypted in trusted builds on Travis CI.
Expand Down
3 changes: 2 additions & 1 deletion admin/genKeyPair.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash

#
# Generates a key pair for this repository to sign artifacts.
# Encrypt the private key and its passphrase in trusted builds
Expand Down
113 changes: 104 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import sbtcrossproject.{crossProject, CrossType}
import ScalaModulePlugin._
import sbtcrossproject.{crossProject, CrossType}
import _root_.scalafix.Versions.{version => scalafixVersion, scala212 => scalafixScala212}

inThisBuild(Seq(
crossScalaVersions := Seq("2.12.6", "2.13.0-M4", "2.11.12")
))
lazy val root = project
.in(file("."))
.settings(dontPublish)
.aggregate(
compatJVM, compatJS,
scalafixRules, scalafixInput, scalafixTests,
scalafixOutput212, scalafixOutput213
)
.disablePlugins(ScalafixPlugin)

disablePlugins(JvmPlugin)
// == Core Libraries ==

lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
lazy val compat = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("."))
.in(file("compat"))
.settings(scalaModuleSettings)
.jvmSettings(scalaModuleSettingsJVM)
.settings(
Expand All @@ -36,6 +43,94 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
fork in Test := false // Scala.js cannot run forked tests
)
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
.disablePlugins(ScalafixPlugin)

lazy val `scala-collection-compatJVM` = `scala-collection-compat`.jvm
lazy val `scala-collection-compatJS` = `scala-collection-compat`.js
lazy val compatJVM = compat.jvm
lazy val compatJS = compat.js

lazy val scalafixRules = project
.in(file("scalafix/rules"))
.settings(scalaModuleSettings)
.settings(scalaModuleSettingsJVM)
.settings(
name := "scala-collection-migrations",
scalaVersion := scalafixScala212,
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % scalafixVersion
)

// == Scalafix Test Setup ==

lazy val scalafixInput = project
.in(file("scalafix/input"))
.settings(dontPublish)
.settings(
scalaVersion := scalafixScala212,
scalafixSourceroot := sourceDirectory.in(Compile).value
)

lazy val scalafixOutput212 = project
.in(file("scalafix/output212"))
.settings(scalaVersion := scalafixScala212)
.settings(dontPublish)
.dependsOn(compatJVM)

lazy val scalafixOutput213 = project
.in(file("scalafix/output213"))
.settings(scala213Settings)
.settings(dontPublish)

lazy val scalafixOutput213Failure = project
.in(file("scalafix/output213-failure"))
.settings(scala213Settings)
.settings(dontPublish)

lazy val scalafixTests = project
.in(file("scalafix/tests"))
.settings(dontPublish)
.settings(
scalaVersion := scalafixScala212,
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % scalafixVersion % Test cross CrossVersion.full,
buildInfoPackage := "fix",
buildInfoKeys := Seq[BuildInfoKey](
"inputSourceroot" ->
sourceDirectory.in(scalafixInput, Compile).value,
"output212Sourceroot" ->
sourceDirectory.in(scalafixOutput212, Compile).value,
"output213Sourceroot" ->
sourceDirectory.in(scalafixOutput213, Compile).value,
"output213FailureSourceroot" ->
sourceDirectory.in(scalafixOutput213Failure, Compile).value,
"inputClassdirectory" ->
classDirectory.in(scalafixInput, Compile).value
),
test in Test := (test in Test).dependsOn(
compile in (scalafixOutput212, Compile),
compile in (scalafixOutput213, Compile)
).value
)
.dependsOn(scalafixInput, scalafixRules)
.enablePlugins(BuildInfoPlugin)

lazy val dontPublish = Seq(
publishArtifact := false,
packagedArtifacts := Map.empty,
publish := {},
publishLocal := {}
)

lazy val scala212 = "2.12.6"
lazy val scala213 = "2.13.0-M4"

lazy val scala213Settings = Seq(
resolvers += "scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
scalaVersion := scala213
)

// required by sbt-scala-module
inThisBuild(Seq(
crossScalaVersions := Seq(scala212, scala213, "2.11.12"),
commands += Command.command("noop") { state =>
println("noop")
state
}
))
11 changes: 6 additions & 5 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ else
// see https://github.com/scala/sbt-scala-module/issues/35
Seq(addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.3"))

val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23")
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.4.0")
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0")
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.10")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
52 changes: 0 additions & 52 deletions scalafix/build.sbt

This file was deleted.

25 changes: 0 additions & 25 deletions scalafix/input/src/main/scala/fix/BreakoutSrc.scala

This file was deleted.

2 changes: 1 addition & 1 deletion scalafix/input/src/main/scala/fix/CanBuildFromNegSrc.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
rule = "scala:fix.Scalacollectioncompat_newcollections"
rule = "scala:fix.CrossCompat"
*/
package fix

Expand Down
2 changes: 1 addition & 1 deletion scalafix/input/src/main/scala/fix/CanBuildFromSrc.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
rule = "scala:fix.Scalacollectioncompat_newcollections"
rule = "scala:fix.CrossCompat"
*/
package fix

Expand Down
Loading