Skip to content

Commit

Permalink
Test Scala 3 input/output with Scala 2.12 rule by default
Browse files Browse the repository at this point in the history
Move to sbt-projectmatrix so that `sbt tests/test` checks
* Scala 2.x input/output with Scala 2.x rule and
* Scala 3 input/output with Scala 2.12 rule
  • Loading branch information
github-brice-jaglin committed May 19, 2021
1 parent 8c89008 commit 4b4f00b
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/main/g8/default.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
repo = My Repo
repo = scalafix-my-rules
scalafix_version = maven(ch.epfl.scala, scalafix-cli_2.13.5)
101 changes: 76 additions & 25 deletions src/main/g8/scalafix/build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
lazy val V = _root_.scalafix.sbt.BuildInfo

lazy val rulesCrossVersions = Seq(V.scala213, V.scala212, V.scala211)
lazy val scala3Version = "3.0.0"

inThisBuild(
List(
scalaVersion := V.scala213,
crossScalaVersions := List(V.scala213, V.scala212, V.scala211),
organization := "com.example",
homepage := Some(url("https://github.com/com/example")),
licenses := List(
Expand All @@ -17,44 +19,93 @@ inThisBuild(
)
),
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalacOptions ++= List(
"-P:semanticdb:synthetics:on"
)
semanticdbVersion := scalafixSemanticdb.revision
)
)

publish / skip := true
lazy val `$repo;format="normalize"$` = (project in file("."))
.aggregate(
rules.projectRefs ++
input.projectRefs ++
output.projectRefs ++
tests.projectRefs: _*
)
.settings(
publish / skip := true
)

lazy val rules = project.settings(
moduleName := "scalafix",
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % V.scalafixVersion
)
lazy val rules = projectMatrix
.settings(
moduleName := "scalafix",
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % V.scalafixVersion
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(rulesCrossVersions)

lazy val input = project.settings(
publish / skip := true
)
lazy val input = projectMatrix
.settings(
publish / skip := true
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(
scalaVersions = rulesCrossVersions,
settings = Seq(
scalacOptions += "-P:semanticdb:synthetics:on"
)
)
.jvmPlatform(scalaVersions = Seq(scala3Version))

lazy val output = project.settings(
publish / skip := true
)
lazy val output = projectMatrix
.settings(
publish / skip := true
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(scalaVersions = rulesCrossVersions :+ scala3Version)

lazy val testsAggregate = Project("tests", file("target/testsAggregate"))
.aggregate(tests.projectRefs: _*)

lazy val tests = project
lazy val tests = projectMatrix
.settings(
publish / skip := true,
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.scalafixVersion % Test cross CrossVersion.full,
Compile / compile :=
(Compile / compile).dependsOn(input / Compile / compile).value,
scalafixTestkitOutputSourceDirectories :=
(output / Compile / unmanagedSourceDirectories).value,
TargetAxis
.resolve(output, Compile / unmanagedSourceDirectories)
.value,
scalafixTestkitInputSourceDirectories :=
(input / Compile / unmanagedSourceDirectories).value,
TargetAxis
.resolve(input, Compile / unmanagedSourceDirectories)
.value,
scalafixTestkitInputClasspath :=
(input / Compile / fullClasspath).value,
TargetAxis.resolve(input, Compile / fullClasspath).value,
scalafixTestkitInputScalacOptions :=
(input / Compile / scalacOptions).value,
TargetAxis.resolve(input, Compile / scalacOptions).value,
scalafixTestkitInputScalaVersion :=
(input / Compile / scalaVersion).value
TargetAxis.resolve(input, Compile / scalaVersion).value
)
.defaultAxes(
rulesCrossVersions.map(VirtualAxis.scalaABIVersion) :+ VirtualAxis.jvm: _*
)
.customRow(
scalaVersions = Seq(V.scala212),
axisValues = Seq(TargetAxis(scala3Version), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala213),
axisValues = Seq(TargetAxis(V.scala213), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala212),
axisValues = Seq(TargetAxis(V.scala212), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala211),
axisValues = Seq(TargetAxis(V.scala211), VirtualAxis.jvm),
settings = Seq()
)
.dependsOn(rules)
.enablePlugins(ScalafixTestkitPlugin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
rule = $repo;format="Camel"$
*/
package fix

object $repo;format="Camel"$SignificantIndentation:
val a = 1
// Add code that needs fixing here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fix

object $repo;format="Camel"$SignificantIndentation:
val a = 1
// Add code that needs fixing here.
47 changes: 47 additions & 0 deletions src/main/g8/scalafix/project/TargetAxis.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sbt._
import sbt.internal.ProjectMatrix
import sbtprojectmatrix.ProjectMatrixPlugin.autoImport._

/** Use on ProjectMatrix rows to tag an affinity to a custom scalaVersion */
case class TargetAxis(scalaVersion: String) extends VirtualAxis.WeakAxis {

private val scalaBinaryVersion = CrossVersion.binaryScalaVersion(scalaVersion)

override val idSuffix = s"Target\${scalaBinaryVersion.replace('.', '_')}"
override val directorySuffix = s"target\$scalaBinaryVersion"
}

object TargetAxis {

private def targetScalaVersion(virtualAxes: Seq[VirtualAxis]): String =
virtualAxes.collectFirst { case a: TargetAxis => a.scalaVersion }.get

/** When invoked on a ProjectMatrix with a TargetAxis, lookup the project
* generated by `matrix` with a scalaVersion matching the one defined in
* that and resolve `key`.
*/
def resolve[T](
matrix: ProjectMatrix,
key: TaskKey[T]
): Def.Initialize[Task[T]] =
Def.taskDyn {
val sv = targetScalaVersion(virtualAxes.value)
val project = matrix.finder().apply(sv)
Def.task((project / key).value)
}

/** When invoked on a ProjectMatrix with a TargetAxis, lookup the project
* generated by `matrix` with a scalaVersion matching the one defined in
* that and resolve `key`.
*/
def resolve[T](
matrix: ProjectMatrix,
key: SettingKey[T]
): Def.Initialize[T] =
Def.settingDyn {
val sv = targetScalaVersion(virtualAxes.value)
val project = matrix.finder().apply(sv)
Def.setting((project / key).value)
}

}
1 change: 1 addition & 0 deletions src/main/g8/scalafix/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
resolvers += Resolver.sonatypeRepo("snapshots")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.27+39-c332bbde-SNAPSHOT")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")

0 comments on commit 4b4f00b

Please sign in to comment.