Skip to content

Commit

Permalink
Merge pull request #386 from griggt/scala3-cross
Browse files Browse the repository at this point in the history
Add cross build for Scala 3
  • Loading branch information
SethTisue authored Nov 21, 2020
2 parents 9bb13ce + 1da64f9 commit 89b2c44
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 22 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ 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:

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 @@ -825,7 +825,6 @@ class LazyListLazinessTest {
}

@Test
@Ignore // TODO: enable after we drop Scala.js 0.6.x support
def `#::_properlyLazy`(): Unit = {
// genericCons_properlyLazy(_ #:: _)
genericCons_properlyLazy((hd, tl) => tl.#::(hd))
Expand Down
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

0 comments on commit 89b2c44

Please sign in to comment.