From 50acf94a706e093d0bf139c68a5239db948e9a01 Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Sun, 6 Oct 2024 00:19:32 +0200 Subject: [PATCH] cross-build to sbt 2.x --- .github/workflows/ci.yml | 10 ++-- .github/workflows/release.yml | 2 + bin/test-release.sh | 4 ++ build.sbt | 57 +++++++++++++------ .../internal/sbt/ScalafixInterface.scala | 6 +- .../internal/sbt/SemanticRuleValidator.scala | 2 +- .../scala/scalafix/sbt/ScalafixEnable.scala | 30 +++++----- .../scala/scalafix/sbt/ScalafixPlugin.scala | 13 +++-- 8 files changed, 78 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffade04d..9f7b96fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: with: jvm: temurin:8 - run: rm -rf src/sbt-test/skip-sbt1.4 - - run: sbt test scripted + - run: sbt +test +scripted jdk11: name: JDK11 tests runs-on: ubuntu-latest @@ -24,7 +24,7 @@ jobs: with: jvm: temurin:11 - run: rm -rf src/sbt-test/skip-sbt1.4 - - run: sbt test scripted + - run: sbt +test +scripted jdk17: name: JDK17 tests runs-on: ubuntu-latest @@ -35,7 +35,7 @@ jobs: jvm: temurin:17 - run: rm -rf src/sbt-test/skip-java17+ - run: rm -rf src/sbt-test/skip-sbt1.4 - - run: sbt test scripted + - run: sbt +test +scripted jdk21: name: JDK21 tests @@ -46,7 +46,7 @@ jobs: with: jvm: temurin:21 - run: rm -rf src/sbt-test/skip-java17+ - - run: sbt test scripted + - run: sbt +test +scripted windows: name: Windows tests runs-on: windows-latest @@ -55,7 +55,7 @@ jobs: - uses: coursier/setup-action@v1 - run: rm -r -fo src\sbt-test\skip-sbt1.4 - run: rm -r -fo src\sbt-test\skip-windows - - run: sbt test-skip-windows scripted + - run: sbt +"testOnly -- -l SkipWindows" +scripted shell: bash checks: name: Scalafmt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bddb3aef..88fb047d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: coursier/setup-action@v1 + with: + jvm: temurin:8 - uses: olafurpg/setup-gpg@v3 - run: git fetch --unshallow - name: Publish ${{ github.ref }} diff --git a/bin/test-release.sh b/bin/test-release.sh index ff2a97c1..ef261b4c 100755 --- a/bin/test-release.sh +++ b/bin/test-release.sh @@ -6,3 +6,7 @@ version=$1 cs resolve \ --sbt-version 1.0 \ --sbt-plugin "ch.epfl.scala:sbt-scalafix:$version" + +cs resolve \ + --sbt-version 2.0.0-M2 \ + --sbt-plugin "ch.epfl.scala:sbt-scalafix:$version" diff --git a/build.sbt b/build.sbt index 7a4ec6e2..a4a129db 100644 --- a/build.sbt +++ b/build.sbt @@ -31,11 +31,6 @@ developers := List( ) ) -commands += Command.command("test-skip-windows") { s => - "testOnly -- -l SkipWindows" :: - s -} - // Dependencies resolvers ++= Resolver.sonatypeOssRepos("public") libraryDependencies ++= Dependencies.all @@ -44,29 +39,59 @@ libraryDependencies ++= List( "org.scalatest" %% "scalatest" % "3.2.19" % Test ) -scalaVersion := "2.12.20" +lazy val scala212 = "2.12.20" +lazy val scala3 = "3.3.4" + +scalaVersion := scala212 +crossScalaVersions := Seq(scala212, scala3) // keep this as low as possible to avoid running into binary incompatibility such as https://github.com/sbt/sbt/issues/5049 -pluginCrossBuild / sbtVersion := "1.4.0" +pluginCrossBuild / sbtVersion := { + scalaBinaryVersion.value match { + case "2.12" => + "1.4.0" + case _ => + "2.0.0-M2" + } +} scriptedSbt := { val jdk = System.getProperty("java.specification.version").toDouble if (jdk >= 21) - "1.9.0" // first release that supports JDK21 + Ordering[String].max( + (pluginCrossBuild / sbtVersion).value, + "1.9.0" // first release that supports JDK21 + ) else (pluginCrossBuild / sbtVersion).value } -libraryDependencies += compilerPlugin(scalafixSemanticdb) - -scalacOptions ++= List("-Ywarn-unused", "-Yrangepos") +libraryDependencies ++= { + scalaBinaryVersion.value match { + case "2.12" => + List(compilerPlugin(scalafixSemanticdb)) + case _ => + Nil + } +} -scalacOptions ++= List( - "-target:jvm-1.8", - "-Xfatal-warnings", - "-Xlint" -) +scalacOptions ++= { + scalaBinaryVersion.value match { + case "2.12" => + List( + "-Ywarn-unused", + "-Yrangepos", + "-Xfatal-warnings", + "-Xlint" + ) + case _ => + List( + "-Wunused:all", + "-Werror" + ) + } +} // Scripted enablePlugins(ScriptedPlugin) diff --git a/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala b/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala index f2ed4605..b393b660 100644 --- a/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala +++ b/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala @@ -38,7 +38,7 @@ object Arg { .map(uri => java.nio.file.Paths.get(uri).toFile) .flatMap { case classDirectory if classDirectory.isDirectory => - classDirectory.**(RegularFileFilter).get + classDirectory.**(RegularFileFilter).get() case jar => Seq(jar) } @@ -109,10 +109,10 @@ class ScalafixInterface private ( scalafixArguments.run().toSeq def availableRules(): Seq[ScalafixRule] = - scalafixArguments.availableRules().asScala + scalafixArguments.availableRules().asScala.toSeq def rulesThatWillRun(): Seq[ScalafixRule] = - try scalafixArguments.rulesThatWillRun().asScala + try scalafixArguments.rulesThatWillRun().asScala.toSeq catch { case e: ScalafixException => throw new InvalidArgument(e.getMessage) } diff --git a/src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala b/src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala index a088b278..3a63af1b 100644 --- a/src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala +++ b/src/main/scala/scalafix/internal/sbt/SemanticRuleValidator.scala @@ -25,7 +25,7 @@ class SemanticRuleValidator(ifNotFound: SemanticdbNotFound) { invalidArguments.foreach { invalidArgument => errors += invalidArgument.getMessage } - errors + errors.toSeq } } } diff --git a/src/main/scala/scalafix/sbt/ScalafixEnable.scala b/src/main/scala/scalafix/sbt/ScalafixEnable.scala index 8e071a57..46fd8687 100644 --- a/src/main/scala/scalafix/sbt/ScalafixEnable.scala +++ b/src/main/scala/scalafix/sbt/ScalafixEnable.scala @@ -155,21 +155,21 @@ object ScalafixEnable { } else { val latestAvailable = tail.lastOption.getOrElse(earliestAvailable) - Seq( - semanticdbVersion := { - val v = latestAvailable.toString - sLog.value.info( - s"Setting semanticdbVersion to $v in project " + - s"${project.ref.project} since the version " + - s"${recommendedSemanticdbV} tracked by scalafix " + - s"${BuildInfo.scalafixVersion} is no longer " + - s"published for scala " + - s"${project.scalaVersion0.toString} - " + - s"consider bumping scala" - ) - v - } - ) + Seq( + semanticdbVersion := { + val v = latestAvailable.toString + sLog.value.info( + s"Setting semanticdbVersion to $v in project " + + s"${project.ref.project} since the version " + + s"${recommendedSemanticdbV} tracked by scalafix " + + s"${BuildInfo.scalafixVersion} is no longer " + + s"published for scala " + + s"${project.scalaVersion0.toString} - " + + s"consider bumping scala" + ) + v + } + ) } } } :+ (semanticdbEnabled := true) diff --git a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala index efd6d978..676fb9f9 100644 --- a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala +++ b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala @@ -243,7 +243,7 @@ object ScalafixPlugin extends AutoPlugin { } update.result.value match { - case Value(v) => v + case Value(v: UpdateReport) => v case Inc(inc: Incomplete) => Incomplete.allExceptions(inc).toList match { case (resolveException: ResolveException) :: Nil => @@ -264,7 +264,7 @@ object ScalafixPlugin extends AutoPlugin { } }, ivyConfigurations += ScalafixConfig, - scalafixAll := scalafixAllInputTask.evaluated, + scalafixAll := scalafixAllInputTask().evaluated, (scalafixScalaBinaryVersion: @nowarn) := scalaVersion.value.split('.').take(2).mkString(".") ) @@ -351,7 +351,7 @@ object ScalafixPlugin extends AutoPlugin { val invocationDepsExternal = parsed.map(_.dependency) val projectDepsInternal0 = projectDepsInternal.filter { case directory if directory.isDirectory => - directory.**(AllPassFilter).get.exists(_.isFile) + directory.**(AllPassFilter).get().exists(_.isFile) case file if file.isFile => true case _ => false } @@ -632,7 +632,7 @@ object ScalafixPlugin extends AutoPlugin { } private lazy val checkIfTriggeredSectionExists: Boolean = { - val confInArgs = interface.args + val confInArgs: Option[Path] = interface.args .collect { case Arg.Config(conf) => conf } .flatten .lastOption @@ -672,7 +672,7 @@ object ScalafixPlugin extends AutoPlugin { Tracked.diffInputs( streams.cacheDirectory / "targets-by-rule" / rule, cachingStyle - )(targets) { changeReport: ChangeReport[File] => + )(targets) { (changeReport: ChangeReport[File]) => doForStaleTargets(changeReport.modified -- changeReport.removed) } @@ -696,7 +696,8 @@ object ScalafixPlugin extends AutoPlugin { } } - val ruleTargetDiffs = interface.rulesThatWillRun + val ruleTargetDiffs = interface + .rulesThatWillRun() .map(rule => diffTargets(rule.name) _) .toList accumulateAndRunForStaleTargets(ruleTargetDiffs)