Skip to content

Commit

Permalink
remove coupling to sbt-projectmatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
github-brice-jaglin committed May 19, 2021
1 parent 97eb494 commit 76868f2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 49 deletions.
1 change: 0 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
unmanagedSourceDirectories.in(Compile) ++= {
Expand Down
39 changes: 0 additions & 39 deletions src/main/scala-sbt-1.0/scalafix/sbt/ScalafixTestkitPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package scalafix.sbt

import sbt.Keys._
import sbt._
import sbt.internal.ProjectMatrix
import sbt.plugins.JvmPlugin
import sbtprojectmatrix.ProjectMatrixPlugin.autoImport._

import java.io.File.pathSeparator

Expand All @@ -13,43 +11,6 @@ object ScalafixTestkitPlugin extends AutoPlugin {
override def requires: Plugins = JvmPlugin

object autoImport {
case class TestkitTargetAxis(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 TestkitTargetAxis {

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

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)
}

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)
}
}

val scalafixTestkitInputClasspath =
taskKey[Classpath]("Classpath of input project")
val scalafixTestkitInputScalacOptions =
Expand Down
18 changes: 9 additions & 9 deletions src/sbt-test/sbt-1.5/testkit/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,41 @@ lazy val tests = projectMatrix
.settings(
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.scalafixVersion % Test cross CrossVersion.full,
scalafixTestkitOutputSourceDirectories :=
TestkitTargetAxis
TargetAxis
.resolve(output, Compile / unmanagedSourceDirectories)
.value,
scalafixTestkitInputSourceDirectories :=
TestkitTargetAxis
TargetAxis
.resolve(input, Compile / unmanagedSourceDirectories)
.value,
scalafixTestkitInputClasspath :=
TestkitTargetAxis.resolve(input, Compile / fullClasspath).value,
TargetAxis.resolve(input, Compile / fullClasspath).value,
scalafixTestkitInputScalacOptions :=
TestkitTargetAxis.resolve(input, Compile / scalacOptions).value,
TargetAxis.resolve(input, Compile / scalacOptions).value,
scalafixTestkitInputScalaVersion :=
TestkitTargetAxis.resolve(input, Compile / scalaVersion).value
TargetAxis.resolve(input, Compile / scalaVersion).value
)
.defaultAxes(
rulesCrossVersions.map(VirtualAxis.scalaABIVersion) :+ VirtualAxis.jvm: _*
)
.customRow(
scalaVersions = Seq(V.scala212),
axisValues = Seq(TestkitTargetAxis(scala3Version), VirtualAxis.jvm),
axisValues = Seq(TargetAxis(scala3Version), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala213),
axisValues = Seq(TestkitTargetAxis(V.scala213), VirtualAxis.jvm),
axisValues = Seq(TargetAxis(V.scala213), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala212),
axisValues = Seq(TestkitTargetAxis(V.scala212), VirtualAxis.jvm),
axisValues = Seq(TargetAxis(V.scala212), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala211),
axisValues = Seq(TestkitTargetAxis(V.scala211), VirtualAxis.jvm),
axisValues = Seq(TargetAxis(V.scala211), VirtualAxis.jvm),
settings = Seq()
)
.dependsOn(rules)
Expand Down
47 changes: 47 additions & 0 deletions src/sbt-test/sbt-1.5/testkit/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)
}

}

0 comments on commit 76868f2

Please sign in to comment.