diff --git a/.travis.yml b/.travis.yml index 33ef5cfc..53ff71d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,15 +28,28 @@ matrix: # run migration test - scala: 2.12.8 - env: TEST_SCALAFIX=true ADOPTOPENJDK=11 + env: TEST_SCALAFIX=true ADOPTOPENJDK=11 # run binary compatibility test - scala: 2.12.8 - env: TEST_BINARY_COMPAT=true ADOPTOPENJDK=11 + env: TEST_BINARY_COMPAT=true ADOPTOPENJDK=11 # run scalafmt - scala: 2.12.8 - env: TEST_SCALAFMT=true ADOPTOPENJDK=11 + env: TEST_SCALAFMT=true ADOPTOPENJDK=11 + + # Scala Native includes + - scala: 2.11.12 + env: SCALANATIVE_VERSION=0.3.9 ADOPTOPENJDK=8 + + - scala: 2.11.12 + env: SCALANATIVE_VERSION=0.4.0-M2 ADOPTOPENJDK=8 + + - scala: 2.11.12 + env: SCALANATIVE_VERSION=0.3.9 ADOPTOPENJDK=11 + + - scala: 2.11.12 + env: SCALANATIVE_VERSION=0.4.0-M2 ADOPTOPENJDK=11 before_install: # adding $HOME/.sdkman to cache would create an empty directory, which interferes with the initial installation diff --git a/build.sbt b/build.sbt index 91b45435..3d857bff 100644 --- a/build.sbt +++ b/build.sbt @@ -24,6 +24,7 @@ lazy val root = project .aggregate( compat211JVM, compat211JS, + compat211Native, compat212JVM, compat212JS, compat213JVM, @@ -60,17 +61,17 @@ scalaVersionsByJvm in ThisBuild := { } /** Create an OSGi version range for standard Scala versioning - * schemes that describes binary compatible versions. */ + * schemes that describes binary compatible versions. */ def osgiVersionRange(version: String, requireMicro: Boolean = false): String = - if(version contains '-') "${@}" // M, RC or SNAPSHOT -> exact version - else if(requireMicro) "${range;[===,=+)}" // At least the same micro version + if (version contains '-') "${@}" // M, RC or SNAPSHOT -> exact version + else if (requireMicro) "${range;[===,=+)}" // At least the same micro version else "${range;[==,=+)}" // Any binary compatible version /** Create an OSGi Import-Package version specification. */ def osgiImport(pattern: String, version: String, requireMicro: Boolean = false): String = pattern + ";version=\"" + osgiVersionRange(version, requireMicro) + "\"" -lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)( +lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform, NativePlatform)( "compat", _.settings(scalaModuleSettings) .settings(commonSettings) @@ -90,7 +91,8 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)( if (scalaVersion.value.startsWith("2.13.")) Seq(s"scala.collection.compat.*;version=${version.value}") else - Seq(s"scala.collection.compat.*;version=${version.value},scala.jdk.*;version=${version.value}") + Seq( + s"scala.collection.compat.*;version=${version.value},scala.jdk.*;version=${version.value}") }, OsgiKeys.importPackage := Seq(osgiImport("*", scalaBinaryVersion.value)), OsgiKeys.privatePackage := Nil, @@ -109,18 +111,25 @@ lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)( ) .jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)) .disablePlugins(ScalafixPlugin) + .nativeSettings( + crossScalaVersions := List(scala211), + scalaVersion := scala211, // allows to compile if scalaVersion set not 2.11 + nativeLinkStubs := true, + Test / test := {} + ) ) val compat211 = compat(scala211) val compat212 = compat(scala212) val compat213 = compat(scala213) -lazy val compat211JVM = compat211.jvm -lazy val compat211JS = compat211.js -lazy val compat212JVM = compat212.jvm -lazy val compat212JS = compat212.js -lazy val compat213JVM = compat213.jvm -lazy val compat213JS = compat213.js +lazy val compat211JVM = compat211.jvm +lazy val compat211JS = compat211.js +lazy val compat211Native = compat211.native +lazy val compat212JVM = compat212.jvm +lazy val compat212JS = compat212.js +lazy val compat213JVM = compat213.jvm +lazy val compat213JS = compat213.js lazy val `binary-compat-old` = project .in(file("binary-compat/old")) @@ -285,6 +294,7 @@ val preRelease = "preRelease" val travisScalaVersion = sys.env.get("TRAVIS_SCALA_VERSION").flatMap(Version.parse) val releaseVersion = sys.env.get("TRAVIS_TAG").flatMap(Version.parse) val isScalaJs = sys.env.get("SCALAJS_VERSION").map(_.nonEmpty).getOrElse(false) +val isScalaNative = sys.env.get("SCALANATIVE_VERSION").map(_.nonEmpty).getOrElse(false) val isScalafix = sys.env.get("TEST_SCALAFIX").nonEmpty val isScalafmt = sys.env.get("TEST_SCALAFMT").nonEmpty val isBinaryCompat = sys.env.get("TEST_BINARY_COMPAT").nonEmpty @@ -342,13 +352,14 @@ inThisBuild( "TRAVIS_SCALA_VERSION", "TRAVIS_TAG", "SCALAJS_VERSION", + "SCALANATIVE_VERSION", "TEST_SCALAFIX", "TEST_SCALAFMT", "TEST_BINARY_COMPAT" ).foreach(k => println(k.padTo(20, " ").mkString("") + " -> " + sys.env.get(k).getOrElse("None"))) - val platformSuffix = if (isScalaJs) "JS" else "" + val platformSuffix = if (isScalaJs) "JS" else if (isScalaNative) "Native" else "" val compatProject = "compat" + travisScalaVersion.get.binary + platformSuffix val binaryCompatProject = "binary-compat" @@ -387,7 +398,7 @@ inThisBuild( Seq( setPublishVersion, List(s"$projectPrefix/clean"), - List(s"$testProjectPrefix/test"), + if (isScalaNative) List() else List(s"$testProjectPrefix/test"), List(s"$projectPrefix/publishLocal"), publishTask ).flatten diff --git a/compat/src/main/scala-2.11_2.12/scala/collection/compat/BuildFrom.scala b/compat/src/main/scala-2.11_2.12/scala/collection/compat/BuildFrom.scala index cb80484a..01f3f44f 100644 --- a/compat/src/main/scala-2.11_2.12/scala/collection/compat/BuildFrom.scala +++ b/compat/src/main/scala-2.11_2.12/scala/collection/compat/BuildFrom.scala @@ -26,7 +26,7 @@ trait BuildFrom[-From, -A, +C] extends Any { def fromSpecific(from: From)(it: IterableOnce[A]): C /** Get a Builder for the collection. For non-strict collection types this will use an intermediate buffer. - * Building collections with `fromSpecific` is preferred because it can be lazy for lazy collections. */ + * Building collections with `fromSpecific` is preferred because it can be lazy for lazy collections. */ def newBuilder(from: From): mutable.Builder[A, C] @deprecated("Use newBuilder() instead of apply()", "2.13.0") @@ -40,7 +40,7 @@ object BuildFrom { implicit cbf: CanBuildFrom[From, A, C]): BuildFrom[From, A, C] = new BuildFrom[From, A, C] { def fromSpecific(from: From)(it: IterableOnce[A]): C = (cbf(from) ++= it).result() - def newBuilder(from: From): mutable.Builder[A, C] = cbf(from) + def newBuilder(from: From): mutable.Builder[A, C] = cbf(from) } // Implicit conversion derived from an implicit conversion to CanBuildFrom diff --git a/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala b/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala index 0a8fbb0b..e2ce485b 100644 --- a/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala +++ b/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala @@ -163,7 +163,8 @@ private[compat] trait PackageShared { type IterableOnce[+X] = c.TraversableOnce[X] val IterableOnce = c.TraversableOnce - implicit def toMapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](self: IterableView[(K, V), C]): MapViewExtensionMethods[K, V, C] = + implicit def toMapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]]( + self: IterableView[(K, V), C]): MapViewExtensionMethods[K, V, C] = new MapViewExtensionMethods[K, V, C](self) } @@ -242,7 +243,10 @@ class TraversableExtensionMethods[A](private val self: c.Traversable[A]) extends def iterableFactory: GenericCompanion[Traversable] = self.companion } -class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](private val self: IterableView[(K, V), C]) extends AnyVal { - def mapValues[W, That](f: V => W)(implicit bf: CanBuildFrom[IterableView[(K, V), C], (K, W), That]): That = +class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]]( + private val self: IterableView[(K, V), C]) + extends AnyVal { + def mapValues[W, That](f: V => W)( + implicit bf: CanBuildFrom[IterableView[(K, V), C], (K, W), That]): That = self.map[(K, W), That] { case (k, v) => (k, f(v)) } } diff --git a/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala b/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala index ff299818..298040de 100644 --- a/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala +++ b/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala @@ -256,7 +256,7 @@ object ArraySeq { return false val len = xs.length - var i = 0 + var i = 0 while (i < len) { if (xs(i) != ys(i)) return false diff --git a/compat/src/test/scala/scala/jdk/CollectionConvertersTest.scala b/compat/src/test/scala/scala/jdk/CollectionConvertersTest.scala index a43dc05d..8eb12800 100644 --- a/compat/src/test/scala/scala/jdk/CollectionConvertersTest.scala +++ b/compat/src/test/scala/scala/jdk/CollectionConvertersTest.scala @@ -15,9 +15,9 @@ class CollectionConvertersTest { val it = "a b c".split(" ").iterator { - val j = it.asJava + val j = it.asJava val je = it.asJavaEnumeration - val s = (j: ju.Iterator[String]).asScala + val s = (j: ju.Iterator[String]).asScala assert((s: Iterator[String]) eq it) val es = (je: ju.Enumeration[String]).asScala assert((es: Iterator[String]) eq it) @@ -25,9 +25,9 @@ class CollectionConvertersTest { { val i: c.Iterable[String] = it.to(Iterable) - val j = i.asJava - val jc = i.asJavaCollection - val s = (j: jl.Iterable[String]).asScala + val j = i.asJava + val jc = i.asJavaCollection + val s = (j: jl.Iterable[String]).asScala assert((s: c.Iterable[String]) eq i) val cs = (jc: ju.Collection[String]).asScala assert((cs: c.Iterable[String]) eq i) @@ -35,44 +35,44 @@ class CollectionConvertersTest { { val b: m.Buffer[String] = it.to(m.Buffer) - val j = b.asJava - val s = (j: ju.List[String]).asScala + val j = b.asJava + val s = (j: ju.List[String]).asScala assert((s: m.Buffer[String]) eq b) } { val q: m.Seq[String] = it.to(m.Seq) - val j = q.asJava - val s = (j: ju.List[String]).asScala + val j = q.asJava + val s = (j: ju.List[String]).asScala assert((s: m.Buffer[String]) == q) // not eq } { val q: c.Seq[String] = it.to(c.Seq) - val j = q.asJava - val s = (j: ju.List[String]).asScala + val j = q.asJava + val s = (j: ju.List[String]).asScala assert((s: m.Buffer[String]) == q) // not eq } { val t: m.Set[String] = it.to(m.Set) - val j = t.asJava - val s = (j: ju.Set[String]).asScala + val j = t.asJava + val s = (j: ju.Set[String]).asScala assert((s: m.Set[String]) eq t) } { val t: c.Set[String] = it.to(c.Set) - val j = t.asJava - val s = (j: ju.Set[String]).asScala + val j = t.asJava + val s = (j: ju.Set[String]).asScala assert((s: m.Set[String]) == t) // not eq } { val p: m.Map[String, String] = m.Map(it.map(a => (a, a)).toSeq: _*) - val j = p.asJava - val jd = p.asJavaDictionary - val s = (j: ju.Map[String, String]).asScala + val j = p.asJava + val jd = p.asJavaDictionary + val s = (j: ju.Map[String, String]).asScala assert((s: m.Map[String, String]) eq p) val ds = (jd: ju.Dictionary[String, String]).asScala assert((ds: m.Map[String, String]) eq p) @@ -80,8 +80,8 @@ class CollectionConvertersTest { { val p: c.Map[String, String] = c.Map(it.map(a => (a, a)).toSeq: _*) - val j = p.asJava - val s = (j: ju.Map[String, String]).asScala + val j = p.asJava + val s = (j: ju.Map[String, String]).asScala assert((s: m.Map[String, String]) == p) // not eq } diff --git a/compat/src/test/scala/test/scala/collection/BuildFromTest.scala b/compat/src/test/scala/test/scala/collection/BuildFromTest.scala index 4e766a17..badf15a3 100644 --- a/compat/src/test/scala/test/scala/collection/BuildFromTest.scala +++ b/compat/src/test/scala/test/scala/collection/BuildFromTest.scala @@ -162,6 +162,6 @@ class BuildFromTest { // Implement BuildFrom class MyBuildFrom[From, A, C] extends BuildFrom[From, A, C] { def fromSpecific(from: From)(it: IterableOnce[A]): C = ??? - def newBuilder(from: From): Builder[A, C] = ??? + def newBuilder(from: From): Builder[A, C] = ??? } } diff --git a/compat/src/test/scala/test/scala/collection/ViewTest.scala b/compat/src/test/scala/test/scala/collection/ViewTest.scala index bb9a5dd0..7e080863 100644 --- a/compat/src/test/scala/test/scala/collection/ViewTest.scala +++ b/compat/src/test/scala/test/scala/collection/ViewTest.scala @@ -21,9 +21,9 @@ class ViewTest { @Test def mapValues: Unit = { - val m = Map("a" -> 1, "b" -> 2, "c" -> 3) - val oldStyle = m.mapValues(x => x*x) - val newStyle = m.view.mapValues(x => x*x) + val m = Map("a" -> 1, "b" -> 2, "c" -> 3) + val oldStyle = m.mapValues(x => x * x) + val newStyle = m.view.mapValues(x => x * x) assertEquals(oldStyle.toMap, newStyle.toMap) } diff --git a/project/plugins.sbt b/project/plugins.sbt index 19bbcd0a..85c52bfd 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,9 +1,15 @@ -val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.28") +val crossVer = "0.6.1" +val scalaJSVersion = + Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.28") +val scalaNativeVersion = + Option(System.getenv("SCALANATIVE_VERSION")).filter(_.nonEmpty).getOrElse("0.3.9") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1") -addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.0.0") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.5") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1") -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % crossVer) +addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion) +addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % crossVer) +addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.0.0") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.5") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")