From a0eee40bc73f3ad71279514dde7eea9e02e323ed Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Fri, 15 Jan 2021 16:23:53 +0100 Subject: [PATCH] Update Scala to 2.12.13 (#1145) --- .github/workflows/actions.yml | 16 +++--- .../interp/CompilerCompatibility.scala | 0 .../interp/CompilerCompatibility.scala | 55 +++++++++++++++++++ .../ammonite/interp/MakeReporter.scala | 43 +++++++++++++++ .../ammonite/interp/MakeReporter.scala | 0 .../interp/script/AmmoniteBuildServer.scala | 2 +- .../scala/ammonite/session/BuiltinTests.scala | 6 +- appveyor.yml | 4 +- build.sc | 24 ++++---- 9 files changed, 126 insertions(+), 24 deletions(-) rename amm/interp/src/main/{scala-2.12 => scala-2.12.0_12}/ammonite/interp/CompilerCompatibility.scala (100%) create mode 100644 amm/interp/src/main/scala-2.12.13+/ammonite/interp/CompilerCompatibility.scala create mode 100644 amm/interp/src/main/scala-2.12.13+/ammonite/interp/MakeReporter.scala rename amm/interp/src/main/{scala-not-2.13.1+ => scala-not-2.12.13+-2.13.1+}/ammonite/interp/MakeReporter.scala (100%) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index c5fe9d34e..d49f186c7 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -7,7 +7,7 @@ on: branches: - master jobs: - unit-11-2_12_12: + unit-11-2_12_13: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -16,8 +16,8 @@ jobs: - uses: actions/setup-java@v1 with: java-version: '11' - - run: ./mill -i unitTest 2.12.12 - unit-8-2_12_12: + - run: ./mill -i unitTest 2.12.13 + unit-8-2_12_13: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -26,7 +26,7 @@ jobs: - uses: actions/setup-java@v1 with: java-version: '8' - - run: ./mill -i unitTest 2.12.12 + - run: ./mill -i unitTest 2.12.13 unit-8-2_13_4: runs-on: ubuntu-latest @@ -39,7 +39,7 @@ jobs: java-version: '8' - run: ./mill -i unitTest 2.13.4 - integration-11-2_12_12: + integration-11-2_12_13: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -48,8 +48,8 @@ jobs: - uses: actions/setup-java@v1 with: java-version: '11' - - run: ./mill -i integrationTest 2.12.12 - integration-8-2_12_12: + - run: ./mill -i integrationTest 2.12.13 + integration-8-2_12_13: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -58,7 +58,7 @@ jobs: - uses: actions/setup-java@v1 with: java-version: '8' - - run: ./mill -i integrationTest 2.12.12 + - run: ./mill -i integrationTest 2.12.13 integration-8-2_13_4: runs-on: ubuntu-latest diff --git a/amm/interp/src/main/scala-2.12/ammonite/interp/CompilerCompatibility.scala b/amm/interp/src/main/scala-2.12.0_12/ammonite/interp/CompilerCompatibility.scala similarity index 100% rename from amm/interp/src/main/scala-2.12/ammonite/interp/CompilerCompatibility.scala rename to amm/interp/src/main/scala-2.12.0_12/ammonite/interp/CompilerCompatibility.scala diff --git a/amm/interp/src/main/scala-2.12.13+/ammonite/interp/CompilerCompatibility.scala b/amm/interp/src/main/scala-2.12.13+/ammonite/interp/CompilerCompatibility.scala new file mode 100644 index 000000000..85f7458e5 --- /dev/null +++ b/amm/interp/src/main/scala-2.12.13+/ammonite/interp/CompilerCompatibility.scala @@ -0,0 +1,55 @@ +package ammonite.interp + +import ammonite.runtime.Classpath + +import scala.reflect.internal.util.Position +import scala.reflect.io.FileZipArchive +import scala.tools.nsc +import scala.tools.nsc.classpath.{AggregateClassPath, ZipAndJarClassPathFactory} +import scala.tools.nsc.{Global, Settings} +import scala.tools.nsc.interactive.{InteractiveAnalyzer, Global => InteractiveGlobal} +import scala.tools.nsc.plugins.Plugin +import scala.tools.nsc.reporters.Reporter +import scala.tools.nsc.typechecker.Analyzer + +object CompilerCompatibility { + + def analyzer(g: Global, cl: ClassLoader): Analyzer { val global: g.type } = { + new { val global: g.type = g } with Analyzer { + override def findMacroClassLoader() = cl + } + } + + def interactiveAnalyzer(g: InteractiveGlobal, + cl: ClassLoader): InteractiveAnalyzer { val global: g.type } = { + new { val global: g.type = g } with InteractiveAnalyzer + } + + def importInfo(g: Global)(t: g.Import) = + new g.analyzer.ImportInfo(t, 0) + + def initGlobal(settings: Settings, + reporter: Reporter, + jcp: AggregateClassPath, + evalClassloader: ClassLoader, + createPlugins: Global => List[Plugin]): Global = { + + new nsc.Global(settings, reporter) { g => + override lazy val plugins = createPlugins(g) + + override def classPath = jcp + + override lazy val platform: ThisPlatform = new GlobalPlatform { + override val global = g + override val settings = g.settings + override val classPath = jcp + } + + override lazy val analyzer = CompilerCompatibility.analyzer(g, evalClassloader) + } + } + + def createZipJarFactory(arc: FileZipArchive, settings: Settings) = { + ZipAndJarClassPathFactory.create(arc, settings, new scala.tools.nsc.CloseableRegistry()) + } +} diff --git a/amm/interp/src/main/scala-2.12.13+/ammonite/interp/MakeReporter.scala b/amm/interp/src/main/scala-2.12.13+/ammonite/interp/MakeReporter.scala new file mode 100644 index 000000000..42580afe5 --- /dev/null +++ b/amm/interp/src/main/scala-2.12.13+/ammonite/interp/MakeReporter.scala @@ -0,0 +1,43 @@ +package ammonite.interp + +import ammonite.runtime.Classpath + +import scala.reflect.internal.util.Position +import scala.reflect.io.FileZipArchive +import scala.tools.nsc +import scala.tools.nsc.classpath.{AggregateClassPath, ZipAndJarClassPathFactory} +import scala.tools.nsc.{Global, Settings} +import scala.tools.nsc.interactive.{InteractiveAnalyzer, Global => InteractiveGlobal} +import scala.tools.nsc.plugins.Plugin +import scala.tools.nsc.reporters.FilteringReporter +import scala.tools.nsc.typechecker.Analyzer + +object MakeReporter { + + type Reporter = scala.tools.nsc.reporters.Reporter + + def makeReporter(errorLogger: (Position, String) => Unit, + warningLogger: (Position, String) => Unit, + infoLogger: (Position, String) => Unit, + outerSettings: Settings): Reporter = + new FilteringReporter { + + def doReport(pos: scala.reflect.internal.util.Position, + msg: String, + severity: Severity): Unit = + display(pos, msg, severity) + + def display(pos: Position, msg: String, severity: Severity) = + severity match{ + case ERROR => + Classpath.traceClasspathProblem(s"ERROR: $msg") + errorLogger(pos, msg) + case WARNING => + warningLogger(pos, msg) + case INFO => + infoLogger(pos, msg) + } + + def settings = outerSettings + } +} diff --git a/amm/interp/src/main/scala-not-2.13.1+/ammonite/interp/MakeReporter.scala b/amm/interp/src/main/scala-not-2.12.13+-2.13.1+/ammonite/interp/MakeReporter.scala similarity index 100% rename from amm/interp/src/main/scala-not-2.13.1+/ammonite/interp/MakeReporter.scala rename to amm/interp/src/main/scala-not-2.12.13+-2.13.1+/ammonite/interp/MakeReporter.scala diff --git a/amm/interp/src/main/scala/ammonite/interp/script/AmmoniteBuildServer.scala b/amm/interp/src/main/scala/ammonite/interp/script/AmmoniteBuildServer.scala index a6faad1d3..2e4555a5b 100644 --- a/amm/interp/src/main/scala/ammonite/interp/script/AmmoniteBuildServer.scala +++ b/amm/interp/src/main/scala/ammonite/interp/script/AmmoniteBuildServer.scala @@ -64,7 +64,7 @@ class AmmoniteBuildServer( Dependency.of( "org.scalameta", "semanticdb-scalac_" + scala.util.Properties.versionNumberString, - "4.4.0" + "4.4.6" ) ), root, diff --git a/amm/repl/src/test/scala/ammonite/session/BuiltinTests.scala b/amm/repl/src/test/scala/ammonite/session/BuiltinTests.scala index 479b1ad33..5db1e9603 100644 --- a/amm/repl/src/test/scala/ammonite/session/BuiltinTests.scala +++ b/amm/repl/src/test/scala/ammonite/session/BuiltinTests.scala @@ -94,7 +94,11 @@ object BuiltinTests extends TestSuite{ // not sure why that one doesn't pass in 2.13 // even disabling the noimports and imports settings instead of setting noimports to false // doesn't seem to reinstate imports - if (TestUtils.scala2_12) check.session(s""" + def sv = scala.util.Properties.versionNumberString + // In 2.12.13, I would have expected things like + // interp.configureCompiler(_.settings.Wconf.tryToSet(List("any:wv", "cat=unchecked:ws"))) + // to re-instate the expected warning below, to no avail :| + if (TestUtils.scala2_12 && sv.stripPrefix("2.12.").toInt <= 12) check.session(s""" @ // Disabling default Scala imports @ List(1, 2, 3) + "lol" diff --git a/appveyor.yml b/appveyor.yml index f0c929e6f..0df3f9700 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,11 +6,11 @@ environment: matrix: - JAVA_OPTS: -Dfile.encoding=UTF8 JAVA_HOME: C:\Program Files\Java\jdk9 - TEST_TASKS: terminal[2.12.12].test amm.repl[2.12.12].test terminal[2.13.4].test amm.repl[2.13.4].test + TEST_TASKS: terminal[2.12.13].test amm.repl[2.12.13].test terminal[2.13.4].test amm.repl[2.13.4].test - JAVA_OPTS: -Dfile.encoding=UTF8 JAVA_HOME: C:\Program Files\Java\jdk1.8.0 - TEST_TASKS: integration[2.12.12].test integration[2.13.4].test + TEST_TASKS: integration[2.12.13].test integration[2.13.4].test install: - SET MILL_URL=https://github.com/lihaoyi/mill/releases/download/0.8.0/0.8.0-assembly diff --git a/build.sc b/build.sc index 0b55d8750..aa9a0acd5 100644 --- a/build.sc +++ b/build.sc @@ -21,12 +21,12 @@ val commitsSinceTaggedVersion = { } -val binCrossScalaVersions = Seq("2.12.12", "2.13.4") +val binCrossScalaVersions = Seq("2.12.13", "2.13.4") def isScala2_12_10OrLater(sv: String): Boolean = { (sv.startsWith("2.12.") && sv.stripPrefix("2.12.").length > 1) || (sv.startsWith("2.13.") && sv != "2.13.0") } val fullCrossScalaVersions = Seq( - "2.12.1", "2.12.2", "2.12.3", "2.12.4", "2.12.6", "2.12.7", "2.12.8", "2.12.9", "2.12.10", "2.12.11", "2.12.12", + "2.12.1", "2.12.2", "2.12.3", "2.12.4", "2.12.6", "2.12.7", "2.12.8", "2.12.9", "2.12.10", "2.12.11", "2.12.12", "2.12.13", "2.13.0", "2.13.1", "2.13.2", "2.13.3", "2.13.4" ) @@ -65,12 +65,10 @@ trait AmmInternalModule extends mill.scalalib.CrossSbtModule{ val extraDir = if (sv.startsWith("2.12.")) { val patch = sv.stripPrefix("2.12.").takeWhile(_.isDigit).toInt - val dirName = - if (patch <= 8) - "scala-2.12.0_8" - else - "scala-2.12.9+" - Seq(PathRef(millSourcePath / "src" / "main" / dirName)) + val dirName0 = if (patch <= 8) "scala-2.12.0_8" else "scala-2.12.9+" + val dirNames1 = if (patch <= 12) Seq("scala-2.12.0_12") else Nil + val dirNames = Seq(dirName0) ++ dirNames1 + dirNames.map(dirName => PathRef(millSourcePath / "src" / "main" / dirName)) } else Nil @@ -79,10 +77,12 @@ trait AmmInternalModule extends mill.scalalib.CrossSbtModule{ else millSourcePath / "src" / "main" / "scala-not-2.12.10-2.13.1+" ) val extraDir3 = - if (!sv.startsWith("2.13.") || sv == "2.13.0") - PathRef(millSourcePath / "src" / "main" / "scala-not-2.13.1+") - else + if (sv.startsWith("2.13.") && sv != "2.13.0") PathRef(millSourcePath / "src" / "main" / "scala-2.13.1+") + else if (sv.startsWith("2.12.") && sv.stripPrefix("2.12.").toInt >= 13) + PathRef(millSourcePath / "src" / "main" / "scala-2.12.13+") + else + PathRef(millSourcePath / "src" / "main" / "scala-not-2.12.13+-2.13.1+") super.sources() ++ extraDir ++ Seq(extraDir2, extraDir3) } @@ -212,7 +212,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions:_*){ def crossFullScalaVersion = true def ivyDeps = Agg( ivy"ch.epfl.scala:bsp4j:$bspVersion", - ivy"org.scalameta::trees:4.4.0", + ivy"org.scalameta::trees:4.4.6", ivy"org.scala-lang:scala-compiler:$crossScalaVersion", ivy"org.scala-lang:scala-reflect:$crossScalaVersion", ivy"com.lihaoyi::scalaparse:2.3.0",