Skip to content

Commit

Permalink
switch build to projectmatrix
Browse files Browse the repository at this point in the history
- allow more parallel building/testing
- make it easier to understand we use 2.13 to run/test against 3
  • Loading branch information
bjaglin committed Apr 9, 2022
1 parent e7d4a20 commit b235d4e
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ jobs:
- uses: actions/checkout@v3
- uses: olafurpg/setup-scala@v13
- run: git fetch --unshallow
- run: sbt +versionPolicyCheck
- run: sbt versionPolicyCheck
118 changes: 86 additions & 32 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import sbt.Keys.scalacOptions
inThisBuild(
List(
onLoadMessage := s"Welcome to scalafix ${version.value}",
scalaVersion := scala213,
crossScalaVersions := List(scala213, scala212, scala211),
fork := true,
scalacOptions ++= List("-P:semanticdb:synthetics:on"),
semanticdbEnabled := true,
Expand All @@ -28,7 +26,7 @@ def inferJavaHome() = {
Some(actualHome)
}

lazy val interfaces = project
lazy val interfaces = projectMatrix
.in(file("scalafix-interfaces"))
.settings(
Compile / resourceGenerators += Def.task {
Expand Down Expand Up @@ -57,9 +55,11 @@ lazy val interfaces = project
crossPaths := false,
autoScalaLibrary := false
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions)
.disablePlugins(ScalafixPlugin)

lazy val core = project
lazy val core = projectMatrix
.in(file("scalafix-core"))
.settings(
moduleName := "scalafix-core",
Expand All @@ -81,9 +81,11 @@ lazy val core = project
)
}
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions)
.enablePlugins(BuildInfoPlugin)

lazy val rules = project
lazy val rules = projectMatrix
.in(file("scalafix-rules"))
.settings(
moduleName := "scalafix-rules",
Expand All @@ -96,10 +98,12 @@ lazy val rules = project
collectionCompat
)
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions)
.dependsOn(core)
.enablePlugins(BuildInfoPlugin)

lazy val reflect = project
lazy val reflect = projectMatrix
.in(file("scalafix-reflect"))
.settings(
moduleName := "scalafix-reflect",
Expand All @@ -109,9 +113,11 @@ lazy val reflect = project
"org.scala-lang" % "scala-reflect" % scalaVersion.value
)
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions)
.dependsOn(core)

lazy val cli = project
lazy val cli = projectMatrix
.in(file("scalafix-cli"))
.settings(
moduleName := "scalafix-cli",
Expand All @@ -123,21 +129,27 @@ lazy val cli = project
commonText
)
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions)
.dependsOn(reflect, interfaces, rules)

lazy val testsShared = project
lazy val testsShared = projectMatrix
.in(file("scalafix-tests/shared"))
.settings(
noPublishAndNoMima,
scalacOptions --= (if (isScala3.value)
Seq("-P:semanticdb:synthetics:on")
else Nil),
coverageEnabled := false
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(testTargetScalaVersions)
.disablePlugins(ScalafixPlugin)

lazy val testsInput = project
lazy val testsInput = projectMatrix
.in(file("scalafix-tests/input"))
.settings(
noPublishAndNoMima,
crossScalaVersions := List(scala3, scala213, scala212, scala211),
scalacOptions --= (if (isScala3.value)
Seq("-P:semanticdb:synthetics:on")
else Nil),
Expand All @@ -149,9 +161,11 @@ lazy val testsInput = project
libraryDependencies ++= testsDependencies.value,
coverageEnabled := false
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(testTargetScalaVersions)
.disablePlugins(ScalafixPlugin)

lazy val testsOutput = project
lazy val testsOutput = projectMatrix
.in(file("scalafix-tests/output"))
.settings(
noPublishAndNoMima,
Expand All @@ -162,9 +176,11 @@ lazy val testsOutput = project
libraryDependencies ++= testsDependencies.value,
coverageEnabled := false
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(testTargetScalaVersions)
.disablePlugins(ScalafixPlugin)

lazy val testkit = project
lazy val testkit = projectMatrix
.in(file("scalafix-testkit"))
.settings(
moduleName := "scalafix-testkit",
Expand All @@ -174,11 +190,15 @@ lazy val testkit = project
scalatest
)
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions)
.dependsOn(cli)

lazy val unit = project
lazy val unit = projectMatrix
.in(file("scalafix-tests/unit"))
.configs(IntegrationTest)
.settings(
Defaults.itSettings,
noPublishAndNoMima,
// Change working directory to match when `fork := false`.
Test / baseDirectory := (ThisBuild / baseDirectory).value,
Expand All @@ -197,9 +217,9 @@ lazy val unit = project
Compile / compile / compileInputs := {
(Compile / compile / compileInputs)
.dependsOn(
testsInput / Compile / compile,
testsOutput / Compile / compile,
testsShared / Compile / compile
TargetAxis.resolve(testsInput, Compile / compile),
TargetAxis.resolve(testsOutput, Compile / compile),
TargetAxis.resolve(testsShared, Compile / compile)
)
.value
},
Expand All @@ -214,20 +234,29 @@ lazy val unit = project
}
put(
"inputClasspath",
(testsInput / Compile / fullClasspath).value.map(_.data)
TargetAxis
.resolve(testsInput, Compile / fullClasspath)
.value
.map(_.data)
)
put(
"inputSourceDirectories",
(testsInput / Compile / sourceDirectories).value
TargetAxis.resolve(testsInput, Compile / sourceDirectories).value
)
put(
"outputSourceDirectories",
(testsOutput / Compile / sourceDirectories).value
TargetAxis.resolve(testsOutput, Compile / sourceDirectories).value
)
props.put(
"scalaVersion",
TargetAxis.resolve(testsInput, Compile / scalaVersion).value
)
props.put("scalaVersion", (testsInput / Compile / scalaVersion).value)
props.put(
"scalacOptions",
(testsInput / Compile / scalacOptions).value.mkString("|")
TargetAxis
.resolve(testsInput, Compile / scalacOptions)
.value
.mkString("|")
)
val out =
(Test / managedResourceDirectories).value.head /
Expand All @@ -240,44 +269,69 @@ lazy val unit = project
"baseDirectory" ->
(ThisBuild / baseDirectory).value,
"inputSourceroot" ->
(testsInput / Compile / sourceDirectory).value,
TargetAxis.resolve(testsInput, Compile / sourceDirectory).value,
"outputSourceroot" ->
(testsOutput / Compile / sourceDirectory).value,
TargetAxis.resolve(testsOutput, Compile / sourceDirectory).value,
"unitResourceDirectory" -> (Compile / resourceDirectory).value,
"testsInputResources" ->
(testsInput / Compile / sourceDirectory).value / "resources",
TargetAxis
.resolve(testsInput, Compile / sourceDirectory)
.value / "resources",
"semanticClasspath" ->
Seq(
(testsInput / Compile / semanticdbTargetRoot).value,
(testsShared / Compile / semanticdbTargetRoot).value
TargetAxis.resolve(testsInput, Compile / semanticdbTargetRoot).value,
TargetAxis.resolve(testsShared, Compile / semanticdbTargetRoot).value
),
"sharedSourceroot" ->
(ThisBuild / baseDirectory).value /
"scalafix-tests" / "shared" / "src" / "main",
"sharedClasspath" ->
(testsShared / Compile / classDirectory).value
TargetAxis.resolve(testsShared, Compile / classDirectory).value
),
Test / test := (Test / test)
.dependsOn(cli / crossPublishLocalBinTransitive)
IntegrationTest / test := (IntegrationTest / test)
.dependsOn(cli.finder().get.map(_ / publishLocalTransitive): _*)
.value
)
.defaultAxes(
buildScalaVersions.map(VirtualAxis.scalaABIVersion) :+ VirtualAxis.jvm: _*
)
.customRow(
scalaVersions = Seq(scala212),
axisValues = Seq(TargetAxis(scala3), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(scala213),
axisValues = Seq(TargetAxis(scala213), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(scala212),
axisValues = Seq(TargetAxis(scala212), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(scala211),
axisValues = Seq(TargetAxis(scala211), VirtualAxis.jvm),
settings = Seq()
)
.enablePlugins(BuildInfoPlugin)
.dependsOn(testkit)

lazy val docs = project
lazy val docs = projectMatrix
.in(file("scalafix-docs"))
.settings(
noPublishAndNoMima,
run / baseDirectory := (ThisBuild / baseDirectory).value,
moduleName := "scalafix-docs",
scalaVersion := scala213,
scalacOptions += "-Wconf:msg='match may not be exhaustive':s", // silence exhaustive pattern matching warning for documentation
scalacOptions += "-Xfatal-warnings",
mdoc := (Compile / run).evaluated,
crossScalaVersions := List(scala213),
libraryDependencies += (if (isScala211.value) metaconfigDocFor211
else metaconfigDoc)
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(scalaVersions = Seq(scala213))
.dependsOn(testkit, core, cli)
.enablePlugins(DocusaurusPlugin)
.disablePlugins(ScalafixPlugin)
4 changes: 4 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ object Dependencies {
val scala212 = "2.12.15"
val scala213 = "2.13.8"
val scala3 = "3.1.1"

val buildScalaVersions = Seq(scala211, scala212, scala213)
val testTargetScalaVersions = Seq(scala211, scala212, scala213, scala3)

// we support 3 last binary versions of scala212 and scala213
val testedPreviousScalaVersions: Map[String, List[String]] =
List(scala213, scala212).map(version => version -> previousVersions(version)).toMap
Expand Down
60 changes: 19 additions & 41 deletions project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
lazy val supportedScalaVersions = List(scala213, scala211, scala212)
lazy val publishLocalTransitive =
taskKey[Unit]("Run publishLocal on this project and its dependencies")
lazy val crossPublishLocalBinTransitive = taskKey[Unit](
"Run, for each crossVersion, publishLocal without packageDoc & packageSrc, on this project and its dependencies"
)
lazy val isFullCrossVersion = Seq(
crossVersion := CrossVersion.full
)
Expand Down Expand Up @@ -127,35 +124,32 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
updateOptions := updateOptions.value.withCachedResolution(true),
ThisBuild / watchTriggeredMessage := Watch.clearScreenOnTrigger,
commands += Command.command("save-expect") { s =>
"unit/test:runMain scalafix.tests.util.SaveExpect" ::
"unitTarget2_13/test:runMain scalafix.tests.util.SaveExpect" ::
s
},
commands += Command.command("ci-3") { s =>
s"""set testsInput/scalaVersion := "$scala3"""" ::
s"""set testsOutput/scalaVersion := "$scala3"""" ::
"unit/testOnly scalafix.tests.rule.RuleSuite" :: s
"unitTarget3/test" :: s
},
commands += Command.command("ci-213") { s =>
s"""set ThisBuild/scalaVersion := "$scala213"""" ::
"unit/test" ::
"docs/run" ::
"interfaces/doc" ::
"unitTarget2_13/test" ::
"unitTarget2_13/it:test" ::
"docs2_13/run" ::
"interfaces2_13/doc" ::
testRulesAgainstPreviousScalaVersions(scala213, s)
},
commands += Command.command("ci-212") { s =>
s"""set ThisBuild/scalaVersion := "$scala212"""" ::
"unit/test" ::
"unitTarget2_12/test" ::
"unitTarget2_12/it:test" ::
testRulesAgainstPreviousScalaVersions(scala212, s)
},
commands += Command.command("ci-211") { s =>
s"""set ThisBuild/scalaVersion := "$scala211"""" ::
"unit/test" ::
"unitTarget2_11/test" ::
"unitTarget2_11/it:test" ::
testRulesAgainstPreviousScalaVersions(scala211, s)
},
commands += Command.command("ci-213-windows") { s =>
s"++$scala213" ::
"cli/crossPublishLocalBinTransitive" :: // scalafix.tests.interfaces.ScalafixSuite
s"unit/testOnly -- -l scalafix.internal.tests.utils.SkipWindows" ::
s"unitTarget2_13/testOnly -- -l scalafix.internal.tests.utils.SkipWindows" ::
"unitTarget2_13/it:test" ::
s
},
// There is flakyness in CliGitDiffTests and CliSemanticTests
Expand Down Expand Up @@ -188,10 +182,13 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
Compile / doc / scalacOptions ++= scaladocOptions,
Compile / unmanagedSourceDirectories ++= {
val sourceDir = (Compile / sourceDirectory).value
CrossVersion.partialVersion(scalaVersion.value) match {
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 12 => Seq(sourceDir / "scala-2.12+")
case _ => Seq()
}
}) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => Seq(sourceDir / "scala-2")
case _ => Seq()
})
},
publishTo := Some {
if (isSnapshot.value) Opts.resolver.sonatypeSnapshots
Expand Down Expand Up @@ -227,28 +224,9 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
publishLocalTransitive := Def.taskDyn {
val ref = thisProjectRef.value
publishLocal.all(ScopeFilter(inDependencies(ref)))
}.value,
crossPublishLocalBinTransitive := {
val currentState = state.value
val ref = thisProjectRef.value
val versions = crossScalaVersions.value
versions.map { version =>
val withScalaVersion = Project
.extract(currentState)
.appendWithoutSession(
Seq(
ThisBuild / scalaVersion := version,
ThisBuild / packageDoc / publishArtifact := false,
ThisBuild / packageSrc / publishArtifact := false
),
currentState
)
Project
.extract(withScalaVersion)
.runTask(ref / publishLocalTransitive, withScalaVersion)
}
}
}.value
)
// TODO
private def testRulesAgainstPreviousScalaVersions(
scalaVersion: String,
state: State
Expand Down
Loading

0 comments on commit b235d4e

Please sign in to comment.