From 14f5fc0cd421d90895c55b09f42fe6d9bacc3eca Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 22 Nov 2023 09:18:03 +0100 Subject: [PATCH] Use enumeration for Scala 2 library TASTy setting --- .github/workflows/ci.yaml | 4 +-- project/Build.scala | 64 +++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ed9d5548cddd..0741a936b22c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -143,10 +143,10 @@ jobs: ./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test ;sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test ;sjsCompilerTests/test" - name: Test with Scala 2 library TASTy - run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala" # only test a subset of test to avoid doubling the CI execution time + run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala" # only test a subset of test to avoid doubling the CI execution time - name: Test with Scala 2 library TASTy with CC - run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryCCTasty := true ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala" # only test a subset of test to avoid doubling the CI execution time + run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala" # only test a subset of test to avoid doubling the CI execution time test_windows_fast: runs-on: [self-hosted, Windows] diff --git a/project/Build.scala b/project/Build.scala index b9a230e63269..d12dfeb9645e 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -173,17 +173,23 @@ object Build { // Run tests with filter through vulpix test suite val testCompilation = inputKey[Unit]("runs integration test with the supplied filter") + sealed trait Scala2Library + // Use Scala 2 compiled library JAR + object Scala2LibraryJar extends Scala2Library // Use the TASTy jar from `scala2-library-tasty` in the classpath // This only works with `scala3-bootstrapped/scalac` and tests in `scala3-bootstrapped` // - // Enable in SBT with: `set ThisBuild/Build.useScala2LibraryTasty := true` - val useScala2LibraryTasty = settingKey[Boolean]("Use the TASTy jar from `scala2-library-tasty` in the classpath") - + object Scala2LibraryTasty extends Scala2Library // Use the TASTy jar from `scala2-library-cc-tasty` in the classpath // This only works with `scala3-bootstrapped/scalac` and tests in `scala3-bootstrapped` // - // Enable in SBT with: `set ThisBuild/Build.useScala2LibraryCCTasty := true` - val useScala2LibraryCCTasty = settingKey[Boolean]("Use the TASTy jar from `scala2-library-cc-tasty` in the classpath") + object Scala2LibraryCCTasty extends Scala2Library + + // Set in SBT with: + // - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryJar` (default) + // - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty` + // - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty` + val scala2Library = settingKey[Scala2Library]("Choose which version of the Scala 2 library should be used") // Used to compile files similar to ./bin/scalac script val scalac = inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath") @@ -231,8 +237,7 @@ object Build { outputStrategy := Some(StdoutOutput), - useScala2LibraryTasty := false, - useScala2LibraryCCTasty := false, + scala2Library := Scala2LibraryJar, // enable verbose exception messages for JUnit (Test / testOptions) += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s"), @@ -652,26 +657,21 @@ object Build { val externalDeps = externalCompilerClasspathTask.value val jars = packageAll.value - val scala2LibraryTasty = jars.get("scala2-library-tasty") match { - case Some(scala2LibraryTastyJar) if useScala2LibraryTasty.value => - Seq("-Ddotty.tests.tasties.scalaLibrary=" + scala2LibraryTastyJar) - case _ => - if (useScala2LibraryTasty.value) log.warn("useScala2LibraryTasty is ignored on non-bootstrapped compiler") - Seq.empty - } - - val scala2LibraryCCTasty = jars.get("scala2-library-cc-tasty") match { - case Some(scala2LibraryCCTastyJar) if useScala2LibraryCCTasty.value => - if (useScala2LibraryTasty.value) { - log.warn("Both useScala2LibraryTasty and useScala2LibraryCCTasty are set (ignoring useScala2LibraryCCTasty)") - Seq.empty - } else Seq("-Ddotty.tests.tasties.scalaLibrary=" + scala2LibraryCCTastyJar) - case _ => - if (useScala2LibraryCCTasty.value) log.warn("useScala2LibraryCCTasty is ignored on non-bootstrapped compiler") - Seq.empty + def libraryPathProperty(jarName: String): Seq[String] = + jars.get(jarName) match { + case Some(jar) => + Seq(s"-Ddotty.tests.tasties.scalaLibrary=$jar") + case None => + log.warn("Scala 2 library TASTy is ignored on non-bootstrapped compiler") + Seq.empty + } + val scala2LibraryTasty = scala2Library.value match { + case Scala2LibraryJar => Seq.empty + case Scala2LibraryTasty => libraryPathProperty("scala2-library-tasty") + case Scala2LibraryTastyCC => libraryPathProperty("scala2-library-cc-tasty") } - scala2LibraryTasty ++ scala2LibraryCCTasty ++ Seq( + scala2LibraryTasty ++ Seq( "-Ddotty.tests.dottyCompilerManagedSources=" + managedSrcDir, "-Ddotty.tests.classes.dottyInterfaces=" + jars("scala3-interfaces"), "-Ddotty.tests.classes.dottyLibrary=" + jars("scala3-library"), @@ -776,14 +776,12 @@ object Build { else if (debugFromTasty) "dotty.tools.dotc.fromtasty.Debug" else "dotty.tools.dotc.Main" - var extraClasspath = - scalaLibTastyOpt match { - case Some(scalaLibTasty) if useScala2LibraryTasty.value => - Seq(scalaLibTasty, scalaLib, dottyLib) - case _ => - if (useScala2LibraryTasty.value) log.warn("useScala2LibraryTasty is ignored on non-bootstrapped compiler") - Seq(scalaLib, dottyLib) - } + val scala2LibraryTasty = scala2Library.value match { + case Scala2LibraryJar => Seq.empty + case Scala2LibraryTasty => jars.get("scala2-library-tasty").toSeq + case Scala2LibraryTastyCC => jars.get("scala2-library-cc-tasty").toSeq + } + var extraClasspath = scala2LibraryTasty ++ Seq(scalaLib, dottyLib) if (decompile && !args.contains("-classpath")) extraClasspath ++= Seq(".")