-
Notifications
You must be signed in to change notification settings - Fork 9
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
Test Scala 3 input/output with rule built against Scala 2.12 #19
Changes from all commits
434d3c8
a74c1f4
72cdd7c
24e1158
71a1160
625fd96
ee98b06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
version = 2.7.5 | ||
project.git = true | ||
assumeStandardLibraryStripMargin = true | ||
project.excludeFilters = [ | ||
"main/g8" | ||
"main/g8/.*/.*\\.scala" | ||
"output/src" | ||
"migration-rules/*" | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
repo = My Repo | ||
scalameta_version = maven(org.scalameta, scalameta_2.13) | ||
scalafix_version = maven(ch.epfl.scala, sbt-scalafix) | ||
repo = scalafix-my-rules | ||
scalafix_version = 0.9.28 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
lazy val V = _root_.scalafix.sbt.BuildInfo | ||
|
||
lazy val rulesCrossVersions = Seq(V.scala213, V.scala212, V.scala211) | ||
lazy val scala3Version = "3.0.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As 3.x releases come out, we might want to test against different versions (although upgrading scala should not be as hard as on the 2.x era obviously). When/if that happens, we should use the full scala version as matrix suffixes, but I don't see a reason to do it now. |
||
|
||
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("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), | ||
licenses := List( | ||
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0") | ||
), | ||
developers := List( | ||
Developer( | ||
"example-username", | ||
|
@@ -14,41 +18,88 @@ inThisBuild( | |
url("https://example.com") | ||
) | ||
), | ||
addCompilerPlugin(scalafixSemanticdb), | ||
scalacOptions ++= List( | ||
"-Yrangepos", | ||
"-P:semanticdb:synthetics:on" | ||
) | ||
semanticdbEnabled := true, | ||
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 | ||
) | ||
Comment on lines
+26
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's ugly, but without that |
||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suffix all projects for clarity, including the 2.13 one |
||
.jvmPlatform(scalaVersions = rulesCrossVersions :+ scala3Version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two calls to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Actually, having different settings was the goal here, since I have amended to follow my initial intent, but I wonder if it makes sense to keep
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have now removed the |
||
|
||
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: _*) | ||
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added to maintain backward compatibility on CI statements (for people upgrading somehow) and on docs |
||
|
||
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 := | ||
TargetAxis.resolve(input, Compile / scalacOptions).value, | ||
scalafixTestkitInputScalaVersion := | ||
TargetAxis.resolve(input, Compile / scalaVersion).value | ||
) | ||
.defaultAxes( | ||
rulesCrossVersions.map(VirtualAxis.scalaABIVersion) :+ VirtualAxis.jvm: _* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. omit the scala version in the suffix to focus on what is being tested - the "target" |
||
) | ||
.customRow( | ||
scalaVersions = Seq(V.scala212), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Matches the default binary version used to load scalafix in sbt-scalafix https://github.com/scalacenter/sbt-scalafix/blob/429e6181bae3c6edb4e2dd25aefa416a07f302d5/src/main/scala/scalafix/sbt/ScalafixPlugin.scala#L232 |
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was initially a way to test that everything works, but since we have now Scala3 scripteds in |
||
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. |
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 declared in | ||
* that TargetAxis, 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 declared in | ||
* that TargetAxis, 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) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
resolvers += Resolver.sonatypeRepo("releases") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "$scalafix_version$") | ||
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.8.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way, I am hoping people name their repo
scalafix-*
, just like sbt plugins aresbt-*
. https://github.com/liancheng/scalafix-organize-imports does, but not the others.