From 6e2a4743137ae0fbc8ce42db5f97d151180472cf Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Tue, 30 May 2017 17:33:19 +0200 Subject: [PATCH] Cross compile to Scala Native --- .travis.yml | 9 +++++ build.sbt | 11 ++++++ .../main/scala/org/scalacheck/Platform.scala | 36 +++++++++++++++++++ project/plugin.sbt | 2 ++ .../org/scalacheck/PropSpecification.scala | 4 +-- 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 native/src/main/scala/org/scalacheck/Platform.scala diff --git a/.travis.yml b/.travis.yml index bdf6d828a..4b4e8e442 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: scala +dist: trusty script: ./tools/travis-script.sh after_success: ./tools/travis-deploy.sh branches: @@ -30,3 +31,11 @@ env: - PLATFORM=js SBT_PARALLEL=true WORKERS=1 DEPLOY=true - PLATFORM=js SBT_PARALLEL=true WORKERS=1 DEPLOY=true SCALAJS_VERSION=1.0.0-M1 sudo: false + +matrix: + include: + - scala: 2.11.11 + before_script: + - curl https://raw.githubusercontent.com/scala-native/scala-native/21539aa97947f767afcd85b5c2fb3c0262b2d301/bin/travis_setup.sh | bash -x + sudo: required + env: PLATFORM=native SBT_PARALLEL=true WORKERS=1 DEPLOY=true diff --git a/build.sbt b/build.sbt index 14147d210..e319c9f8a 100644 --- a/build.sbt +++ b/build.sbt @@ -129,3 +129,14 @@ lazy val jvm = project.in(file("jvm")) .settings( libraryDependencies += "org.scala-sbt" % "test-interface" % "1.0" ) + +lazy val native = project.in(file("native")) + .settings(sharedSettings: _*) + .settings( + doc in Compile := (doc in Compile in jvm).value, + scalaVersion := "2.11.11", + libraryDependencies ++= Seq( + "org.scala-native" %% "test-interface_native0.3" % "0.3.1" + ) + ) + .enablePlugins(ScalaNativePlugin) diff --git a/native/src/main/scala/org/scalacheck/Platform.scala b/native/src/main/scala/org/scalacheck/Platform.scala new file mode 100644 index 000000000..162a1e011 --- /dev/null +++ b/native/src/main/scala/org/scalacheck/Platform.scala @@ -0,0 +1,36 @@ +/*-------------------------------------------------------------------------*\ +** ScalaCheck ** +** Copyright (c) 2007-2017 Rickard Nilsson. All rights reserved. ** +** http://www.scalacheck.org ** +** ** +** This software is released under the terms of the Revised BSD License. ** +** There is NO WARRANTY. See the file LICENSE for the full text. ** +\*------------------------------------------------------------------------ */ + +package org.scalacheck + +import Test._ + +import scala.scalanative.testinterface.PreloadedClassLoader + +private[scalacheck] object Platform { + + def runWorkers( + params: Parameters, + workerFun: Int => Result, + stop: () => Unit + ): Result = { + workerFun(0) + } + + def loadModule(name: String, loader: ClassLoader): AnyRef = + loader.asInstanceOf[PreloadedClassLoader].loadPreloaded(name) + + def newInstance(name: String, loader: ClassLoader, paramTypes: Seq[Class[_]])(args: Seq[AnyRef]): AnyRef = + org.scalajs.testinterface.TestUtils.newInstance(name, loader, paramTypes)(args) + + // We don't need those annotation in Native, and they have been deprecated. + // We use `String` instead of the definition in Native because `-Xfatal-warnings` + // is set. + type EnableReflectiveInstantiation = String +} diff --git a/project/plugin.sbt b/project/plugin.sbt index c144ef57b..aa3e6ed2e 100644 --- a/project/plugin.sbt +++ b/project/plugin.sbt @@ -7,4 +7,6 @@ val scalaJSVersion = addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.3") + scalacOptions += "-deprecation" diff --git a/src/test/scala/org/scalacheck/PropSpecification.scala b/src/test/scala/org/scalacheck/PropSpecification.scala index ec3517acb..2feabbd93 100644 --- a/src/test/scala/org/scalacheck/PropSpecification.scala +++ b/src/test/scala/org/scalacheck/PropSpecification.scala @@ -144,8 +144,8 @@ object PropSpecification extends Properties("Prop") { } property("throws") = throws(classOf[java.lang.Exception]) { - val s: String = null - s.length + val it: Iterator[Int] = Iterator.empty + it.next() } property("sizedProp") = {