Skip to content

Commit

Permalink
Use enumeration for Scala 2 library TASTy setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 22, 2023
1 parent fd4c034 commit 14f5fc0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
64 changes: 31 additions & 33 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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(".")
Expand Down

0 comments on commit 14f5fc0

Please sign in to comment.