Skip to content

Add cross build for Scala 3 #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ scala:
- 2.11.12
- 2.12.12
- 2.13.3
- 3.0.0-M1

env:
- SCALAJS_VERSION= ADOPTOPENJDK=8
- SCALAJS_VERSION=0.6.33 ADOPTOPENJDK=8
- SCALAJS_VERSION=1.3.0 ADOPTOPENJDK=8
- SCALAJS_VERSION=1.3.1 ADOPTOPENJDK=8
- SCALAJS_VERSION= ADOPTOPENJDK=11
- SCALAJS_VERSION=0.6.33 ADOPTOPENJDK=11
- SCALAJS_VERSION=1.3.0 ADOPTOPENJDK=11
- SCALAJS_VERSION=1.3.1 ADOPTOPENJDK=11

matrix:
exclude:
# Scala.js 0.6.x is not supported with Scala 3
- scala: 3.0.0-M1
env: SCALAJS_VERSION=0.6.33 ADOPTOPENJDK=8

- scala: 3.0.0-M1
env: SCALAJS_VERSION=0.6.33 ADOPTOPENJDK=11

include:

Expand Down
25 changes: 17 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ lazy val root = project
compat212JS,
compat213JVM,
compat213JS,
compat30JVM,
compat30JS,
`scalafix-data211`,
`scalafix-data212`,
`scalafix-data213`,
Expand All @@ -51,6 +53,7 @@ lazy val junit = libraryDependencies += "com.novocode" % "junit-interface" % "0.
lazy val scala211 = "2.11.12"
lazy val scala212 = "2.12.12"
lazy val scala213 = "2.13.3"
lazy val scala30 = "3.0.0-M1"

lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform, NativePlatform)(
"compat",
Expand All @@ -62,7 +65,7 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform, NativePlatform
scalacOptions ++= Seq("-feature", "-language:higherKinds", "-language:implicitConversions"),
Compile / unmanagedSourceDirectories += {
val sharedSourceDir = (ThisBuild / baseDirectory).value / "compat/src/main"
if (scalaVersion.value.startsWith("2.13.")) sharedSourceDir / "scala-2.13"
if (scalaVersion.value.startsWith("2.13.") || isDotty.value) sharedSourceDir / "scala-2.13"
else sharedSourceDir / "scala-2.11_2.12"
},
)
Expand All @@ -79,13 +82,16 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform, NativePlatform
},
)
.jsSettings(
scalacOptions += {
val x = (LocalRootProject / baseDirectory).value.toURI.toString
val y = "https://raw.githubusercontent.com/scala/scala-collection-compat/" + sys.process
.Process("git rev-parse HEAD")
.lineStream_!
.head
s"-P:scalajs:mapSourceURI:$x->$y/"
scalacOptions ++= {
if (isDotty.value) Seq() // Scala.js does not support -P with Scala 3: lampepfl/dotty#9783
else {
val x = (LocalRootProject / baseDirectory).value.toURI.toString
val y = "https://raw.githubusercontent.com/scala/scala-collection-compat/" + sys.process
.Process("git rev-parse HEAD")
.lineStream_!
.head
Seq(s"-P:scalajs:mapSourceURI:$x->$y/")
}
},
Test / fork := false // Scala.js cannot run forked tests
)
Expand All @@ -102,6 +108,7 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform, NativePlatform
val compat211 = compat(scala211)
val compat212 = compat(scala212)
val compat213 = compat(scala213)
val compat30 = compat(scala30)

lazy val compat211JVM = compat211.jvm
lazy val compat211JS = compat211.js
Expand All @@ -110,6 +117,8 @@ lazy val compat212JVM = compat212.jvm
lazy val compat212JS = compat212.js
lazy val compat213JVM = compat213.jvm
lazy val compat213JS = compat213.js
lazy val compat30JVM = compat30.jvm
lazy val compat30JS = compat30.js

lazy val `binary-compat-old` = project
.in(file("binary-compat/old"))
Expand Down
13 changes: 7 additions & 6 deletions compat/src/test/scala/test/scala/collection/ArraySeqTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package test.scala.collection

import org.junit.{Assert, Test}

import scala.reflect.ClassTag
import scala.collection.compat.immutable.ArraySeq

// The unmodified ArraySeqTest from collection-strawman
Expand Down Expand Up @@ -53,22 +54,22 @@ class ArraySeqTest {

def unit1(): Unit = {}
def unit2(): Unit = {}
Assert.assertEquals(unit1, unit2)
Assert.assertEquals(unit1(), unit2())
// unitArray is actually an instance of Immutable[BoxedUnit], the check to which is actually checked slice
// implementation of ofRef
val unitArray: ArraySeq[Unit] = Array(unit1, unit2, unit1, unit2)
check(unitArray, Array(unit1, unit1), Array(unit1, unit1))
val unitArray: ArraySeq[Unit] = Array(unit1(), unit2(), unit1(), unit2())
check(unitArray, Array(unit1(), unit1()), Array(unit1(), unit1()))
}

private def check[T](array: ArraySeq[T],
expectedSliceResult1: ArraySeq[T],
expectedSliceResult2: ArraySeq[T]) {
expectedSliceResult2: ArraySeq[T])(implicit elemTag: ClassTag[T]): Unit = {
Assert.assertEquals(array, array.slice(-1, 4))
Assert.assertEquals(array, array.slice(0, 5))
Assert.assertEquals(array, array.slice(-1, 5))
Assert.assertEquals(expectedSliceResult1, array.slice(0, 2))
Assert.assertEquals(expectedSliceResult2, array.slice(1, 3))
Assert.assertEquals(ArraySeq.empty[Nothing], array.slice(1, 1))
Assert.assertEquals(ArraySeq.empty[Nothing], array.slice(2, 1))
Assert.assertEquals(ArraySeq[T](), array.slice(1, 1))
Assert.assertEquals(ArraySeq[T](), array.slice(2, 1))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LazyListTest {
assertEquals(5, wf.map(identity).length) // success instead of NPE
}

@Test(timeout = 10000) // scala/bug#6881
@Test(timeout = 10000L) // scala/bug#6881
def test_reference_equality: Unit = {
// Make sure we're tested with reference equality
val s = LazyList.from(0)
Expand Down Expand Up @@ -192,7 +192,7 @@ class LazyListTest {

val cycle1: LazyList[Int] = 1 #:: 2 #:: cycle1
val cycle2: LazyList[Int] = 1 #:: 2 #:: 3 #:: cycle2
@Test(timeout = 10000)
@Test(timeout = 10000L)
def testSameElements(): Unit = {
assert(LazyList().sameElements(LazyList()))
assert(!LazyList().sameElements(LazyList(1)))
Expand Down
1 change: 1 addition & 0 deletions project/MultiScalaProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ trait MultiScala {
val sourceDir = (ThisBuild / baseDirectory).value / base / "src" / "main"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 12 => List(sourceDir / "scala-2.12+")
case Some((3, _)) => List(sourceDir / "scala-2.13")
case _ => Nil
}
},
Expand Down
3 changes: 2 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
val crossVer = "1.0.0"
val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.33")
Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("1.3.1")
val scalaNativeVersion =
Option(System.getenv("SCALANATIVE_VERSION")).filter(_.nonEmpty).getOrElse("0.3.9")

addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % crossVer)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)
Expand Down