Skip to content

support for scala-native #45

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 35 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ scala:
- 2.12.6
- 2.13.0-M4
jdk:
- openjdk6
- openjdk7
- oraclejdk8
env:
global:
Expand All @@ -23,25 +23,53 @@ env:
# SONA_PASS
- secure: "m0Fw/eH7RXJJoBTfqV6CMd7kaIN2pRPnQPNXJGb546UjqYAlYTkfjvVrWpsgpisRBptI1FEHn24yGbgAHjIes/4un/O62K66I0BffL8PbdeHeNcDjSrTesKEqage2mQfGOiqccVsmkgiKeXNYL8tPZRmPQQ3XZ97mS1SXWlqAJSMW6HfNnvqW14Gdb/snR6I8lQ2o5tRnLerWPnI96pp+xjZca2lD4XDvH2wLJXXLmYY61e23ZYzZMepxBxhGa7js3YTYzCWNrOfBLjFJ5nwRxbjR0WMuz5z5Gdy715WtguKS4Fffd/GJHycLROBU9LCAQDMTxMFvqzFqVFpfq0BuTmmkXFXj+a7dO+ABG0RfoDfoMjn7pHwyHNCZyMMuR1HCjMkbGFwC+Zme2UAYNivtcsuWWeMuypwjyqjfFfNns4FHJ0SXFtC/6+OJkAuUdbEJKReYWKWEsP5SnCH/8PLlc+uUl3tjQkFLc1sOAyx9cTWyBErwuJXhgTrjT9AWvO+fvhcm8z/p5+aaF/U9GIrzPqziX4hGjzc/WC+rsFJSiBDlFQl7br+m8WWs7/wuXqPGXmhf0BNQViDi7fZndDHcY3p3T0An05d/IMKjCUrgLDlJi6VYs9XN7S8ay6MH+XTwIsJGSxtGjfEO4rHGIjtR2GRr8TqdNfnpsI3ucbia1Y="
matrix:
- SCALAJS_VERSION=
- SCALAJS_VERSION=0.6.23
- SCALAJS_VERSION=1.0.0-M3
- SCALA_TARGET=jvm
- SCALA_TARGET=js SCALAJS_VERSION=0.6.23
- SCALA_TARGET=js SCALAJS_VERSION=1.0.0-M3

matrix:
exclude:
- jdk: openjdk6
# > 2.12 requires jdk8
- jdk: openjdk7
scala: 2.12.6
- jdk: openjdk6

- jdk: openjdk7
scala: 2.13.0-M4

# ?
- jdk: oraclejdk8
scala: 2.11.12

# 2.13.0-M4 is not available in Scala.js 1.0.0-M3
- scala: 2.13.0-M4
env: SCALAJS_VERSION=1.0.0-M3
env: SCALA_TARGET=js SCALAJS_VERSION=1.0.0-M3

# run migration test
include:
- scala: 2.12.6
jdk: oraclejdk8
env: TEST_SCALAFIX=true

- scala: 2.11.12
jdk: oraclejdk8
env: SCALA_TARGET=native
sudo: required
before_install:
- curl https://raw.githubusercontent.com/scala-native/scala-native/master/scripts/travis_setup.sh | bash -

# | jdk | scala | scala target | scala target version | scalafix test |
# | ----------- | --------- | ------------ | -------------------- |---------------|
# | openjdk7 | 2.11.12 | jvm | | |
# | openjdk7 | 2.11.12 | js | 0.6.23 | |
# | openjdk7 | 2.11.12 | js | 1.0.0-M3 | |
# | oraclejdk8 | 2.12.6 | jvm | | |
# | oraclejdk8 | 2.12.6 | js | 0.6.23 | |
# | oraclejdk8 | 2.12.6 | js | 1.0.0-M3 | |
# | oraclejdk8 | 2.13.0-M4 | jvm | | |
# | oraclejdk8 | 2.13.0-M4 | js | 0.6.23 | |
# | oraclejdk8 | 2.11.12 | native | 0.3.7 | |
# | oraclejdk8 | 2.12.6 | jvm | | true |

before_script: ./checkCLA.sh
script:
# work around https://github.com/travis-ci/travis-ci/issues/9713
Expand Down
25 changes: 19 additions & 6 deletions admin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,24 @@ if [[ "$TEST_SCALAFIX" == "true" ]]; then
exit 0
fi

if [ "$SCALAJS_VERSION" = "" ]; then
projectPrefix="scala-collection-compat"
else
projectPrefix="scala-collection-compatJS"
fi
case "$SCALA_TARGET" in
jvm)
targetSuffix=""
;;

js)
targetSuffix="JS"
;;

native)
targetSuffix="Native"
;;
*)
echo $"SCALA_TARGET: $SCALA_TARGET {jvm|js|native}"
exit 1
esac

projectPrefix="scala-collection-compat$targetSuffix"

verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
tagPat="^v$verPat(#.*)?$"
Expand All @@ -52,4 +65,4 @@ if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
fi
fi

sbt "++$TRAVIS_SCALA_VERSION" "$publishVersion" "$projectPrefix/clean" "$projectPrefix/test" "$projectPrefix/publishLocal" "$publishTask"
sbt -Dhttps.protocols=TLSv1.2 "++$TRAVIS_SCALA_VERSION" "$publishVersion" "$projectPrefix/clean" "$projectPrefix/test" "$projectPrefix/publishLocal" "$publishTask"
5 changes: 5 additions & 0 deletions admin/nix-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

HERE="`dirname $0`"

nix-shell $HERE/scala-native.nix -A clangEnv
23 changes: 23 additions & 0 deletions admin/scala-native.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
in rec {
clangEnv = stdenv.mkDerivation rec {
name = "clang-env";
shellHook = ''
alias cls=clear
'';
CLANG_PATH = pkgs.clang + "/bin/clang";
CLANGPP_PATH = pkgs.clang + "/bin/clang++";
buildInputs = with pkgs; [
stdenv
sbt
openjdk
boehmgc
libunwind
re2
clang
zlib
];
};
}
21 changes: 16 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ inThisBuild(Seq(
crossScalaVersions := Seq("2.12.6", "2.13.0-M4", "2.11.12")
))

disablePlugins(JvmPlugin)
lazy val root = project
.in(file("."))
.aggregate(
`scala-collection-compatJVM`,
`scala-collection-compatJS`,
`scala-collection-compatNative`
)

lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)

lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("."))
Expand All @@ -17,15 +24,16 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
name := "scala-collection-compat",
version := "0.1-SNAPSHOT",
scalacOptions ++= Seq("-feature", "-language:higherKinds", "-language:implicitConversions"),
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.6.4",
testFrameworks += new TestFramework("utest.runner.Framework"),
unmanagedSourceDirectories in Compile += {
val sharedSourceDir = baseDirectory.value.getParentFile / "src/main"
if (scalaVersion.value.startsWith("2.13.")) sharedSourceDir / "scala-2.13"
else sharedSourceDir / "scala-2.11_2.12"
}
)
.jvmSettings(
OsgiKeys.exportPackage := Seq(s"scala.collection.compat.*;version=${version.value}"),
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
OsgiKeys.exportPackage := Seq(s"scala.collection.compat.*;version=${version.value}")
)
.jsSettings(
scalacOptions += {
Expand All @@ -35,7 +43,10 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
},
fork in Test := false // Scala.js cannot run forked tests
)
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
.nativeSettings(
scalaVersion := "2.11.12"
)

lazy val `scala-collection-compatJVM` = `scala-collection-compat`.jvm
lazy val `scala-collection-compatJS` = `scala-collection-compat`.js
lazy val `scala-collection-compatNative` = `scala-collection-compat`.native
13 changes: 8 additions & 5 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ else
// see https://github.com/scala/sbt-scala-module/issues/35
Seq(addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.3"))

val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.4.0")
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14")


val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.5.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.7")
98 changes: 49 additions & 49 deletions src/test/scala/test/scala/collection/ArraySeqTest.scala
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
package test.scala.collection

import org.junit.{Assert, Test}
import utest._
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no junit for Scala-Native.


import scala.collection.compat.immutable.ArraySeq

// The unmodified ArraySeqTest from collection-strawman
class ArraySeqTest {
@Test
def slice(): Unit = {

implicit def array2ArraySeq[T](array: Array[T]): ArraySeq[T] =
ArraySeq.unsafeWrapArray(array)

val booleanArray = Array(true, false, true, false)
check(booleanArray, Array(true, false), Array(false, true))

val shortArray = Array(1.toShort, 2.toShort, 3.toShort, 4.toShort)
check(shortArray, Array(1.toShort, 2.toShort), Array(2.toShort, 3.toShort))

val intArray = Array(1, 2, 3, 4)
check(intArray, Array(1, 2), Array(2, 3))

val longArray = Array(1L, 2L, 3L, 4L)
check(longArray, Array(1L, 2L), Array(2L, 3L))

val byteArray = Array(1.toByte, 2.toByte, 3.toByte, 4.toByte)
check(byteArray, Array(1.toByte, 2.toByte), Array(2.toByte, 3.toByte))

val charArray = Array('1', '2', '3', '4')
check(charArray, Array('1', '2'), Array('2', '3'))

val doubleArray = Array(1.0, 2.0, 3.0, 4.0)
check(doubleArray, Array(1.0, 2.0), Array(2.0, 3.0))

val floatArray = Array(1.0f, 2.0f, 3.0f, 4.0f)
check(floatArray, Array(1.0f, 2.0f), Array(2.0f, 3.0f))

val refArray = Array("1", "2", "3", "4")
check[String](refArray, Array("1", "2"), Array("2", "3"))

def unit1(): Unit = {}
def unit2(): Unit = {}
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))
object ArraySeqTest extends TestSuite{
val tests = Tests{
'slice - {
implicit def array2ArraySeq[T](array: Array[T]): ArraySeq[T] =
ArraySeq.unsafeWrapArray(array)

val booleanArray = Array(true, false, true, false)
check(booleanArray, Array(true, false), Array(false, true))

val shortArray = Array(1.toShort, 2.toShort, 3.toShort, 4.toShort)
check(shortArray, Array(1.toShort, 2.toShort), Array(2.toShort, 3.toShort))

val intArray = Array(1, 2, 3, 4)
check(intArray, Array(1, 2), Array(2, 3))

val longArray = Array(1L, 2L, 3L, 4L)
check(longArray, Array(1L, 2L), Array(2L, 3L))

val byteArray = Array(1.toByte, 2.toByte, 3.toByte, 4.toByte)
check(byteArray, Array(1.toByte, 2.toByte), Array(2.toByte, 3.toByte))

val charArray = Array('1', '2', '3', '4')
check(charArray, Array('1', '2'), Array('2', '3'))

val doubleArray = Array(1.0, 2.0, 3.0, 4.0)
check(doubleArray, Array(1.0, 2.0), Array(2.0, 3.0))

val floatArray = Array(1.0f, 2.0f, 3.0f, 4.0f)
check(floatArray, Array(1.0f, 2.0f), Array(2.0f, 3.0f))

val refArray = Array("1", "2", "3", "4")
check[String](refArray, Array("1", "2"), Array("2", "3"))

def unit1(): Unit = {}
def unit2(): Unit = {}

// 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))
}
}

private def check[T](array: ArraySeq[T], expectedSliceResult1: ArraySeq[T], expectedSliceResult2: ArraySeq[T]) {
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(array == array.slice(-1, 4))
assert(array == array.slice(0, 5))
assert(array == array.slice(-1, 5))
assert(expectedSliceResult1 == array.slice(0, 2))
assert(expectedSliceResult2 == array.slice(1, 3))
assert(ArraySeq.empty[Nothing] == array.slice(1, 1))
assert(ArraySeq.empty[Nothing] == array.slice(2, 1))
}
}
Loading