Skip to content

Commit e5a117f

Browse files
Support for Scala-Native
currently fail to link: > scala-collection-compatNative/test [warn] MiMa will NOT run because no mimaPreviousVersion is provided. [info] Linking (1002 ms) [error] cannot link: @java.lang.Class::getField_java.lang.String_java.lang.reflect.Field [error] cannot link: @java.lang.ClassLoader::loadClass_java.lang.String_java.lang.Class [error] unable to link [error] (scala-collection-compatNative/nativetest:nativeLink) unable to link [error] Total time: 2 s, completed Jun 19, 2018 3:21:42 PM We cannot use openjdk6 since maven central wont serve TLS1.0 Server access Error: Received fatal alert: protocol_version url=https://repo1.maven.org/maven2/org/scala-sbt/compiler-interface/0.13.17/compiler-interface-0.13.17.jar see https://stackoverflow.com/a/50824799/449071
1 parent 6dd4505 commit e5a117f

File tree

12 files changed

+337
-259
lines changed

12 files changed

+337
-259
lines changed

.travis.yml

+35-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ scala:
1212
- 2.12.6
1313
- 2.13.0-M4
1414
jdk:
15-
- openjdk6
15+
- openjdk7
1616
- oraclejdk8
1717
env:
1818
global:
@@ -23,25 +23,53 @@ env:
2323
# SONA_PASS
2424
- 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="
2525
matrix:
26-
- SCALAJS_VERSION=
27-
- SCALAJS_VERSION=0.6.23
28-
- SCALAJS_VERSION=1.0.0-M3
26+
- SCALA_TARGET=jvm
27+
- SCALA_TARGET=js SCALAJS_VERSION=0.6.23
28+
- SCALA_TARGET=js SCALAJS_VERSION=1.0.0-M3
2929

3030
matrix:
3131
exclude:
32-
- jdk: openjdk6
32+
# > 2.12 requires jdk8
33+
- jdk: openjdk7
3334
scala: 2.12.6
34-
- jdk: openjdk6
35+
36+
- jdk: openjdk7
3537
scala: 2.13.0-M4
38+
39+
# ?
3640
- jdk: oraclejdk8
3741
scala: 2.11.12
42+
43+
# 2.13.0-M4 is not available in Scala.js 1.0.0-M3
3844
- scala: 2.13.0-M4
39-
env: SCALAJS_VERSION=1.0.0-M3
45+
env: SCALA_TARGET=js SCALAJS_VERSION=1.0.0-M3
46+
47+
# run migration test
4048
include:
4149
- scala: 2.12.6
4250
jdk: oraclejdk8
4351
env: TEST_SCALAFIX=true
4452

53+
- scala: 2.11.12
54+
jdk: oraclejdk8
55+
env: SCALA_TARGET=native
56+
sudo: required
57+
before_install:
58+
- curl https://raw.githubusercontent.com/scala-native/scala-native/master/scripts/travis_setup.sh | bash -
59+
60+
# | jdk | scala | scala target | scala target version | scalafix test |
61+
# | ----------- | --------- | ------------ | -------------------- |---------------|
62+
# | openjdk7 | 2.11.12 | jvm | | |
63+
# | openjdk7 | 2.11.12 | js | 0.6.23 | |
64+
# | openjdk7 | 2.11.12 | js | 1.0.0-M3 | |
65+
# | oraclejdk8 | 2.12.6 | jvm | | |
66+
# | oraclejdk8 | 2.12.6 | js | 0.6.23 | |
67+
# | oraclejdk8 | 2.12.6 | js | 1.0.0-M3 | |
68+
# | oraclejdk8 | 2.13.0-M4 | jvm | | |
69+
# | oraclejdk8 | 2.13.0-M4 | js | 0.6.23 | |
70+
# | oraclejdk8 | 2.11.12 | native | 0.3.7 | |
71+
# | oraclejdk8 | 2.12.6 | jvm | | true |
72+
4573
before_script: ./checkCLA.sh
4674
script:
4775
# work around https://github.com/travis-ci/travis-ci/issues/9713

admin/build.sh

+19-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,24 @@ if [[ "$TEST_SCALAFIX" == "true" ]]; then
2323
exit 0
2424
fi
2525

26-
if [ "$SCALAJS_VERSION" = "" ]; then
27-
projectPrefix="scala-collection-compat"
28-
else
29-
projectPrefix="scala-collection-compatJS"
30-
fi
26+
case "$SCALA_TARGET" in
27+
jvm)
28+
targetSuffix=""
29+
;;
30+
31+
js)
32+
targetSuffix="JS"
33+
;;
34+
35+
native)
36+
targetSuffix="Native"
37+
;;
38+
*)
39+
echo $"SCALA_TARGET: $SCALA_TARGET {jvm|js|native}"
40+
exit 1
41+
esac
42+
43+
projectPrefix="scala-collection-compat$targetSuffix"
3144

3245
verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
3346
tagPat="^v$verPat(#.*)?$"
@@ -52,4 +65,4 @@ if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
5265
fi
5366
fi
5467
55-
sbt "++$TRAVIS_SCALA_VERSION" "$publishVersion" "$projectPrefix/clean" "$projectPrefix/test" "$projectPrefix/publishLocal" "$publishTask"
68+
sbt -Dhttps.protocols=TLSv1.2 "++$TRAVIS_SCALA_VERSION" "$publishVersion" "$projectPrefix/clean" "$projectPrefix/test" "$projectPrefix/publishLocal" "$publishTask"

admin/nix-run.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
HERE="`dirname $0`"
4+
5+
nix-shell $HERE/scala-native.nix -A clangEnv

admin/scala-native.nix

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let
2+
pkgs = import <nixpkgs> {};
3+
stdenv = pkgs.stdenv;
4+
in rec {
5+
clangEnv = stdenv.mkDerivation rec {
6+
name = "clang-env";
7+
shellHook = ''
8+
alias cls=clear
9+
'';
10+
CLANG_PATH = pkgs.clang + "/bin/clang";
11+
CLANGPP_PATH = pkgs.clang + "/bin/clang++";
12+
buildInputs = with pkgs; [
13+
stdenv
14+
sbt
15+
openjdk
16+
boehmgc
17+
libunwind
18+
re2
19+
clang
20+
zlib
21+
];
22+
};
23+
}

build.sbt

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ inThisBuild(Seq(
55
crossScalaVersions := Seq("2.12.6", "2.13.0-M4", "2.11.12")
66
))
77

8-
disablePlugins(JvmPlugin)
8+
lazy val root = project
9+
.in(file("."))
10+
.aggregate(
11+
`scala-collection-compatJVM`,
12+
`scala-collection-compatJS`,
13+
`scala-collection-compatNative`
14+
)
915

10-
lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
16+
17+
lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform, NativePlatform)
1118
.withoutSuffixFor(JVMPlatform)
1219
.crossType(CrossType.Pure)
1320
.in(file("."))
@@ -17,15 +24,16 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
1724
name := "scala-collection-compat",
1825
version := "0.1-SNAPSHOT",
1926
scalacOptions ++= Seq("-feature", "-language:higherKinds", "-language:implicitConversions"),
27+
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.6.4",
28+
testFrameworks += new TestFramework("utest.runner.Framework"),
2029
unmanagedSourceDirectories in Compile += {
2130
val sharedSourceDir = baseDirectory.value.getParentFile / "src/main"
2231
if (scalaVersion.value.startsWith("2.13.")) sharedSourceDir / "scala-2.13"
2332
else sharedSourceDir / "scala-2.11_2.12"
2433
}
2534
)
2635
.jvmSettings(
27-
OsgiKeys.exportPackage := Seq(s"scala.collection.compat.*;version=${version.value}"),
28-
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
36+
OsgiKeys.exportPackage := Seq(s"scala.collection.compat.*;version=${version.value}")
2937
)
3038
.jsSettings(
3139
scalacOptions += {
@@ -35,7 +43,10 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
3543
},
3644
fork in Test := false // Scala.js cannot run forked tests
3745
)
38-
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
46+
.nativeSettings(
47+
scalaVersion := "2.11.12"
48+
)
3949

4050
lazy val `scala-collection-compatJVM` = `scala-collection-compat`.jvm
4151
lazy val `scala-collection-compatJS` = `scala-collection-compat`.js
52+
lazy val `scala-collection-compatNative` = `scala-collection-compat`.native

project/plugins.sbt

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ else
55
// see https://github.com/scala/sbt-scala-module/issues/35
66
Seq(addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.3"))
77

8-
val scalaJSVersion =
9-
Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23")
10-
11-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
12-
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.4.0")
138
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14")
9+
10+
11+
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.23")
12+
13+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
14+
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0")
15+
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.5.0")
16+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.7")
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
package test.scala.collection
22

3-
import org.junit.{Assert, Test}
3+
import utest._
44

55
import scala.collection.compat.immutable.ArraySeq
66

77
// The unmodified ArraySeqTest from collection-strawman
8-
class ArraySeqTest {
9-
@Test
10-
def slice(): Unit = {
11-
12-
implicit def array2ArraySeq[T](array: Array[T]): ArraySeq[T] =
13-
ArraySeq.unsafeWrapArray(array)
14-
15-
val booleanArray = Array(true, false, true, false)
16-
check(booleanArray, Array(true, false), Array(false, true))
17-
18-
val shortArray = Array(1.toShort, 2.toShort, 3.toShort, 4.toShort)
19-
check(shortArray, Array(1.toShort, 2.toShort), Array(2.toShort, 3.toShort))
20-
21-
val intArray = Array(1, 2, 3, 4)
22-
check(intArray, Array(1, 2), Array(2, 3))
23-
24-
val longArray = Array(1L, 2L, 3L, 4L)
25-
check(longArray, Array(1L, 2L), Array(2L, 3L))
26-
27-
val byteArray = Array(1.toByte, 2.toByte, 3.toByte, 4.toByte)
28-
check(byteArray, Array(1.toByte, 2.toByte), Array(2.toByte, 3.toByte))
29-
30-
val charArray = Array('1', '2', '3', '4')
31-
check(charArray, Array('1', '2'), Array('2', '3'))
32-
33-
val doubleArray = Array(1.0, 2.0, 3.0, 4.0)
34-
check(doubleArray, Array(1.0, 2.0), Array(2.0, 3.0))
35-
36-
val floatArray = Array(1.0f, 2.0f, 3.0f, 4.0f)
37-
check(floatArray, Array(1.0f, 2.0f), Array(2.0f, 3.0f))
38-
39-
val refArray = Array("1", "2", "3", "4")
40-
check[String](refArray, Array("1", "2"), Array("2", "3"))
41-
42-
def unit1(): Unit = {}
43-
def unit2(): Unit = {}
44-
Assert.assertEquals(unit1, unit2)
45-
// unitArray is actually an instance of Immutable[BoxedUnit], the check to which is actually checked slice
46-
// implementation of ofRef
47-
val unitArray: ArraySeq[Unit] = Array(unit1, unit2, unit1, unit2)
48-
check(unitArray, Array(unit1, unit1), Array(unit1, unit1))
8+
object ArraySeqTest extends TestSuite{
9+
val tests = Tests{
10+
'slice - {
11+
implicit def array2ArraySeq[T](array: Array[T]): ArraySeq[T] =
12+
ArraySeq.unsafeWrapArray(array)
13+
14+
val booleanArray = Array(true, false, true, false)
15+
check(booleanArray, Array(true, false), Array(false, true))
16+
17+
val shortArray = Array(1.toShort, 2.toShort, 3.toShort, 4.toShort)
18+
check(shortArray, Array(1.toShort, 2.toShort), Array(2.toShort, 3.toShort))
19+
20+
val intArray = Array(1, 2, 3, 4)
21+
check(intArray, Array(1, 2), Array(2, 3))
22+
23+
val longArray = Array(1L, 2L, 3L, 4L)
24+
check(longArray, Array(1L, 2L), Array(2L, 3L))
25+
26+
val byteArray = Array(1.toByte, 2.toByte, 3.toByte, 4.toByte)
27+
check(byteArray, Array(1.toByte, 2.toByte), Array(2.toByte, 3.toByte))
28+
29+
val charArray = Array('1', '2', '3', '4')
30+
check(charArray, Array('1', '2'), Array('2', '3'))
31+
32+
val doubleArray = Array(1.0, 2.0, 3.0, 4.0)
33+
check(doubleArray, Array(1.0, 2.0), Array(2.0, 3.0))
34+
35+
val floatArray = Array(1.0f, 2.0f, 3.0f, 4.0f)
36+
check(floatArray, Array(1.0f, 2.0f), Array(2.0f, 3.0f))
37+
38+
val refArray = Array("1", "2", "3", "4")
39+
check[String](refArray, Array("1", "2"), Array("2", "3"))
40+
41+
def unit1(): Unit = {}
42+
def unit2(): Unit = {}
43+
44+
// unitArray is actually an instance of Immutable[BoxedUnit], the check to which is actually checked slice
45+
// implementation of ofRef
46+
val unitArray: ArraySeq[Unit] = Array(unit1, unit2, unit1, unit2)
47+
check(unitArray, Array(unit1, unit1), Array(unit1, unit1))
48+
}
4949
}
5050

5151
private def check[T](array: ArraySeq[T], expectedSliceResult1: ArraySeq[T], expectedSliceResult2: ArraySeq[T]) {
52-
Assert.assertEquals(array, array.slice(-1, 4))
53-
Assert.assertEquals(array, array.slice(0, 5))
54-
Assert.assertEquals(array, array.slice(-1, 5))
55-
Assert.assertEquals(expectedSliceResult1, array.slice(0, 2))
56-
Assert.assertEquals(expectedSliceResult2, array.slice(1, 3))
57-
Assert.assertEquals(ArraySeq.empty[Nothing], array.slice(1, 1))
58-
Assert.assertEquals(ArraySeq.empty[Nothing], array.slice(2, 1))
52+
assert(array == array.slice(-1, 4))
53+
assert(array == array.slice(0, 5))
54+
assert(array == array.slice(-1, 5))
55+
assert(expectedSliceResult1 == array.slice(0, 2))
56+
assert(expectedSliceResult2 == array.slice(1, 3))
57+
assert(ArraySeq.empty[Nothing] == array.slice(1, 1))
58+
assert(ArraySeq.empty[Nothing] == array.slice(2, 1))
5959
}
6060
}

0 commit comments

Comments
 (0)