From bdc43ab7c09377b4cc4f47479232d7b3561379ea Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 19 Oct 2023 17:04:50 +0200 Subject: [PATCH] Use setting to enable Scala2 library TASTy in scala3-bootstrapped Enabling this setting will add the Scala2 library TASTy JAR from `scala2-library-tasty` to the Scala3 bootstrapped classpath. It can be used to compile using `scala3-bootstrapped/scalac` or run any tests in `scala3-bootstrapped`. Example usage: ``` sbt> set ThisBuild/Build.useScala2LibraryTasty := true sbt> scala3-bootstrapped/scalac sbt> scala3-bootstrapped/testCompilation ``` --- compiler/test/dotty/Properties.scala | 3 +++ .../tools/vulpix/TestConfiguration.scala | 6 +++-- project/Build.scala | 22 ++++++++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/compiler/test/dotty/Properties.scala b/compiler/test/dotty/Properties.scala index cc47303d5468..c1d757378919 100644 --- a/compiler/test/dotty/Properties.scala +++ b/compiler/test/dotty/Properties.scala @@ -82,6 +82,9 @@ object Properties { /** scala-library jar */ def scalaLibrary: String = sys.props("dotty.tests.classes.scalaLibrary") + /** scala-library TASTy jar */ + def scalaLibraryTasty: Option[String] = sys.props.get("dotty.tests.tasties.scalaLibrary") + /** scala-asm jar */ def scalaAsm: String = sys.props("dotty.tests.classes.scalaAsm") diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index 21094799d8a9..04be00fe921e 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -25,12 +25,14 @@ object TestConfiguration { "-Xverify-signatures" ) - val basicClasspath = mkClasspath(List( + val basicClasspath = mkClasspath( + Properties.scalaLibraryTasty.toList ::: List( Properties.scalaLibrary, Properties.dottyLibrary )) - val withCompilerClasspath = mkClasspath(List( + val withCompilerClasspath = mkClasspath( + Properties.scalaLibraryTasty.toList ::: List( Properties.scalaLibrary, Properties.scalaAsm, Properties.jlineTerminal, diff --git a/project/Build.scala b/project/Build.scala index c8b53fd36042..f3a8194ca56d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -173,6 +173,12 @@ object Build { // Run tests with filter through vulpix test suite val testCompilation = inputKey[Unit]("runs integration test with the supplied filter") + // 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") + // 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") @@ -219,6 +225,8 @@ object Build { outputStrategy := Some(StdoutOutput), + useScala2LibraryTasty := false, + // enable verbose exception messages for JUnit (Test / testOptions) += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s"), ) @@ -633,7 +641,11 @@ object Build { val externalDeps = externalCompilerClasspathTask.value val jars = packageAll.value - Seq( + val scala2LibraryTasty = + if (useScala2LibraryTasty.value) Seq("-Ddotty.tests.tasties.scalaLibrary=" + jars("scala2-library-tasty")) + else Seq.empty + + scala2LibraryTasty ++ Seq( "-Ddotty.tests.dottyCompilerManagedSources=" + managedSrcDir, "-Ddotty.tests.classes.dottyInterfaces=" + jars("scala3-interfaces"), "-Ddotty.tests.classes.dottyLibrary=" + jars("scala3-library"), @@ -729,11 +741,9 @@ object Build { val args0: List[String] = spaceDelimited("").parsed.toList val decompile = args0.contains("-decompile") val printTasty = args0.contains("-print-tasty") - val useScala2LibraryTasty = args0.contains("-Yscala2-library-tasty") val debugFromTasty = args0.contains("-Ythrough-tasty") val args = args0.filter(arg => arg != "-repl" && arg != "-decompile" && - arg != "-with-compiler" && arg != "-Ythrough-tasty" && arg != "-print-tasty" - && arg != "-Yscala2-library-tasty") + arg != "-with-compiler" && arg != "-Ythrough-tasty" && arg != "-print-tasty") val main = if (decompile) "dotty.tools.dotc.decompiler.Main" else if (printTasty) "dotty.tools.dotc.core.tasty.TastyPrinter" @@ -742,10 +752,10 @@ object Build { var extraClasspath = scalaLibTastyOpt match { - case Some(scalaLibTasty) if useScala2LibraryTasty => + case Some(scalaLibTasty) if useScala2LibraryTasty.value => Seq(scalaLibTasty, scalaLib, dottyLib) case _ => - if (useScala2LibraryTasty) log.error("-Yscala2-library-tasty can only be used with a bootstrapped compiler") + if (useScala2LibraryTasty.value) log.warn("useScala2LibraryTasty is ignored on non-bootstrapped compiler") Seq(scalaLib, dottyLib) }