Skip to content

Commit

Permalink
Merge pull request #625 from ScorexFoundation/scala-2.11
Browse files Browse the repository at this point in the history
Support Scala 2.11 compilation and publishing
  • Loading branch information
aslesarenko authored Dec 14, 2019
2 parents 98c2744 + d4e7c51 commit 910ef28
Show file tree
Hide file tree
Showing 54 changed files with 319 additions and 260 deletions.
16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ cache:
- "$HOME/.ivy2/cache"
- "$HOME/.sbt"
language: scala
scala:
- 2.12.10
- 2.11.12
jdk:
- oraclejdk8
stages:
Expand All @@ -16,27 +19,22 @@ stages:
- name: release
if: tag =~ ^v
- name: snapshot
if: NOT tag IS present
if: "(NOT tag IS present) AND (type = push)"
jobs:
include:
- stage: test
script: sbt -jvm-opts .travis.jvmopts test
script: sbt -jvm-opts .travis.jvmopts +test
# enable scoverage after SpamSpecification timeout issue is resolved
# script: sbt -jvm-opts .travis.jvmopts coverage test
# - stage: coverage
# script: sbt coverageReport coveralls
- stage: release
script: sbt -jvm-opts .travis.jvmopts publishSigned sonatypeBundleRelease
script: openssl aes-256-cbc -K $encrypted_98cf3af00429_key -iv $encrypted_98cf3af00429_iv -in ci/secring.asc.enc -out ci/secring.asc -d && gpg --import ci/secring.asc && sbt -jvm-opts .travis.jvmopts +publishSigned sonatypeBundleRelease
- stage: snapshot
script: sbt -jvm-opts .travis.jvmopts publish
script: sbt -jvm-opts .travis.jvmopts +publish
env:
global:
- secure: IGwd+lY2TfkAeX1SfzaYBwyhiiPaFrTxoF0e+4R1bkGxiGCce1hBYjn15z1HRfK+k3hgEZh/FBG7dv8LQfNWQ6AJY5PQ2zwckd4ArYMhTVpiY4eRzUMqO1/gjTCCbbTjfFKOMsR2pAw+TGeglqoX4eyziIaS8nR901dZcFvHuC1Fr5EdKFZ0x+WHnX8vaSQoDE4u1MoBnyo5cRVumXG+xvs1Q0nZXm/hd/Flfx5u3L7veKAkGtvbHmdsJoSSySTbc1MGYQtofQjbj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TQqDpxz7hCTbyBSw=
- secure: gfhEv/PXEckwZPnwJHl4fBCJKCrCKK4KMeYCPNZZtKuV1gC4mZscvECm8r+kgB+o2G3i4tEIYcIC5Jbdcbjf4bk6uNZW/X3dna0irl/Mdswt7rTLzLan1rPz3k8Bylgs8ehETFBGr8HyNitEa8ODyaEXa84MPQaucXUmpHS+sUEhQn0Z70T70d1H9ZubUhGv9VLltNoSWkPGW5CPZlpQTHl63ZShfmylfQuQVTbVMdL8LLUHn2x2edlDKMGD8YPH5d+of0AKc3IKnlnMM36WjgYVsf1yehfLi0NH/b2Dzk7wLjetu/bw8Cu9Ne6/u0Lu83Hbh4DyS2iPQivDUGB+JXlHDFI4uji3GurnvpFDku1gbc4HVoFqhgOWyXQAiRllj2BXmq2vwp6797TUG4HrD2EVzIJV7eIZdWNN/QttZtNxNdSbBq8QQc92G2SU4q7PcogMSr0LpX05SfyL1sMgX2WeGzFzyMIu/+rAJhG0lPt7krBxEfQrRtTLdJ9eyeFjFQlxM6G/9gk68j+Nida6KunLwe9QEl2T+t1YbE4i9pndoCMJFxAOjirhw5OM3PfSWfb/mU7zXd4PSNK7RQIdOaPJff5C6UEM7h/iQ6riRZp1Pn7d/rxppTXsvUbtvwUYnkoOeUZyMvQNQsPI6Slns8jWl0zp5XiTmzSRVOuH3ME=
# decrypt the private key (exported via https://docs.scala-lang.org/overviews/contributors/index.html#export-your-pgp-key-pair )
before_install:
- openssl aes-256-cbc -K $encrypted_98cf3af00429_key -iv $encrypted_98cf3af00429_iv
-in ci/secring.asc.enc -out ci/secring.asc -d
# import decrypted private key
before_script: gpg --import ci/secring.asc
50 changes: 34 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ organization := "org.scorexfoundation"

name := "sigma-state"

lazy val scala212 = "2.12.10"
lazy val scala211 = "2.11.12"
crossScalaVersions := Seq(scala212, scala211)
scalaVersion := scala212

javacOptions ++=
"-source" :: "1.7" ::
"-target" :: "1.7" ::
Nil

lazy val allConfigDependency = "compile->compile;test->test"

lazy val commonSettings = Seq(
organization := "org.scorexfoundation",
scalaVersion := "2.12.8",
resolvers += Resolver.sonatypeRepo("public"),
licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")),
homepage := Some(url("https://github.com/ScorexFoundation/sigmastate-interpreter")),
Expand All @@ -34,7 +43,7 @@ lazy val commonSettings = Seq(
</developer>
</developers>,
publishMavenStyle := true,
publishTo := sonatypePublishToBundle.value,
publishTo := sonatypePublishToBundle.value
)

enablePlugins(GitVersioning)
Expand Down Expand Up @@ -68,16 +77,15 @@ version in ThisBuild := {

git.gitUncommittedChanges in ThisBuild := true

val bouncycastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % "1.60"
val scrypto = "org.scorexfoundation" %% "scrypto" % "2.1.6"
val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.1.4"
val bouncycastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % "1.64"
val scrypto = "org.scorexfoundation" %% "scrypto" % "2.1.7"
val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.1.6"
val macroCompat = "org.typelevel" %% "macro-compat" % "1.1.1"
val paradise = "org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full
val debox = "org.spire-math" %% "debox" % "0.8.0"
val kiama = "org.bitbucket.inkytonik.kiama" %% "kiama" % "2.1.0"
val fastparse = "com.lihaoyi" %% "fastparse" % "1.0.0"
val commonsIo = "commons-io" % "commons-io" % "2.5"
val configs = "com.github.kxbmap" %% "configs" % "0.4.4"

val specialVersion = "0.6.1"
val meta = "io.github.scalan" %% "meta" % specialVersion
Expand All @@ -90,7 +98,7 @@ val testingDependencies = Seq(
"org.scalacheck" %% "scalacheck" % "1.14.+" % "test",
"com.storm-enroute" %% "scalameter" % "0.8.2" % Test,
"junit" % "junit" % "4.12" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test"
)

lazy val testSettings = Seq(
Expand All @@ -106,7 +114,6 @@ libraryDependencies ++= Seq(
scrypto,
scorexUtil,
"org.bouncycastle" % "bcprov-jdk15on" % "1.+",
"com.typesafe.akka" %% "akka-actor" % "2.4.+",
kiama, fastparse, debox
) ++ testingDependencies

Expand All @@ -123,8 +130,8 @@ scalacOptions ++= Seq("-feature", "-deprecation")
// see https://github.com/eclipse/jetty.project/issues/3244
// these options applied only in "compile" task since scalac crashes on scaladoc compilation with "-release 8"
// see https://github.com/scala/community-builds/issues/796#issuecomment-423395500
javacOptions in(Compile, compile) ++= Seq("-target", "8", "-source", "8" )
scalacOptions in(Compile, compile) ++= Seq("-release", "8")
//javacOptions in(Compile, compile) ++= Seq("-target", "8", "-source", "8" )
//scalacOptions in(Compile, compile) ++= Seq("-release", "8")

//uncomment lines below if the Scala compiler hangs to see where it happens
//scalacOptions in Compile ++= Seq("-Xprompt", "-Ydebug", "-verbose" )
Expand Down Expand Up @@ -184,7 +191,7 @@ lazy val libraryimpl = Project("library-impl", file("library-impl"))
lazy val core = Project("core", file("core"))
.dependsOn(common % allConfigDependency, libraryapi % allConfigDependency)
.settings(commonSettings,
libraryDependencies ++= Seq( configs, debox ))
libraryDependencies ++= Seq( debox ))
.settings(publish / skip := true)

lazy val library = Project("library", file("library"))
Expand All @@ -196,15 +203,26 @@ lazy val library = Project("library", file("library"))

lazy val sigmaconf = Project("sigma-conf", file("sigma-conf"))
.settings(commonSettings,
libraryDependencies ++= Seq(
plugin, libraryconf
))
libraryDependencies ++= (
if(scalaBinaryVersion.value == "2.11")
Seq.empty
else
Seq(plugin, libraryconf)
),
skip in compile := scalaBinaryVersion.value == "2.11"
)
.settings(publish / skip := true)

lazy val scalanizer = Project("scalanizer", file("scalanizer"))
.dependsOn(sigmaconf, libraryapi, libraryimpl)
.settings(commonSettings,
libraryDependencies ++= Seq(meta, plugin),
libraryDependencies ++= (
if(scalaBinaryVersion.value == "2.11")
Seq.empty
else
Seq(meta, plugin)
),
skip in compile := scalaBinaryVersion.value == "2.11",
assemblyOption in assembly ~= { _.copy(includeScala = false, includeDependency = true) },
assemblyMergeStrategy in assembly := {
case PathList("scalan", xs @ _*) => MergeStrategy.first
Expand Down Expand Up @@ -276,7 +294,7 @@ lazy val rootSettings = Seq(
libraryDependencies := libraryDependencies.all(aggregateCompile).value.flatten,
mappings in (Compile, packageSrc) ++= (mappings in(Compile, packageSrc)).all(aggregateCompile).value.flatten,
mappings in (Test, packageBin) ++= (mappings in(Test, packageBin)).all(aggregateCompile).value.flatten,
mappings in(Test, packageSrc) ++= (mappings in(Test, packageSrc)).all(aggregateCompile).value.flatten,
mappings in(Test, packageSrc) ++= (mappings in(Test, packageSrc)).all(aggregateCompile).value.flatten
)

def runErgoTask(task: String, sigmastateVersion: String, log: Logger): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/scalan/Reified.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* The need for reified type arguments come from ClassTag[T], RType[T] context bounds or
* implicit parameters in the source code.
*/
@Target({ElementType.TYPE, ElementType.TYPE_PARAMETER})
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Reified {
String value() default "";
Expand Down
7 changes: 6 additions & 1 deletion common/src/main/scala/scalan/util/CollectionUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ object CollectionUtil {
implicit class HashMapOps[K,V](val source: java.util.HashMap[K,V]) extends AnyVal {
def toImmutableMap: Map[K,V] = {
var res = Map[K,V]()
source.forEach((t: K, u: V) => res = res + (t -> u))
// don't beautify: at least this code should compile under java 1.7
val entries = source.entrySet().iterator()
while (entries.hasNext) {
val e = entries.next()
res = res + (e.getKey -> e.getValue)
}
res
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/src/test/scala/scalan/util/CollectionUtilTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ class CollectionUtilTests extends BaseTests {
val xs = Seq(1, 2, 3)

{
val (ints, strings, plus1s) = xs.mapUnzip(x => (x, x.toString, x + 1))
val (ints, strings, plus1s) = xs.mapUnzip((x: Int) => (x, x.toString, x + 1))
ints shouldBe Seq(1, 2, 3)
strings shouldBe Seq("1", "2", "3")
plus1s shouldBe Seq(2, 3, 4)
}

{
val (ints, strings) = xs.mapUnzip(x => (x, x.toString))
val (ints, strings) = xs.mapUnzip((x: Int) => (x, x.toString))
ints shouldBe Seq(1, 2, 3)
strings shouldBe Seq("1", "2", "3")
}
Expand Down
14 changes: 9 additions & 5 deletions common/src/test/scala/scalan/util/GraphUtilTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class GraphUtilTests extends BaseNestedTests {
List() // 6
)

val neighbours: DFunc[Int, DBuffer[Int]] = { node: Int =>
val ns = DBuffer.empty[Int]
graph(node) foreach (ns.+=)
ns
val neighbours: DFunc[Int, DBuffer[Int]] = new DFunc[Int, DBuffer[Int]] {
def apply(node: Int) = {
val ns = DBuffer.empty[Int]
graph(node) foreach (ns.+=)
ns
}
}

it("depthFirstSetFrom") {
Expand All @@ -31,7 +33,9 @@ class GraphUtilTests extends BaseNestedTests {
depthFirstSetFrom(DBuffer(0))(neighbours) shouldBe (DSet(0, 1, 2, 3, 4, 5, 6))
}
it("depthFirstOrderFrom") {
val succ: DFunc[Int, DBuffer[Int]] = {id: Int => DBuffer(graph(id):_*)}
val succ: DFunc[Int, DBuffer[Int]] = new DFunc[Int, DBuffer[Int]] {
def apply(id: Int) = DBuffer(graph(id):_*)
}
depthFirstOrderFrom(DBuffer(6), succ) shouldBe (DBuffer(6))
depthFirstOrderFrom(DBuffer(5), succ) shouldBe (DBuffer(6, 5))
depthFirstOrderFrom(DBuffer(3), succ) shouldBe (DBuffer(6, 5, 3))
Expand Down
25 changes: 0 additions & 25 deletions core/src/main/scala/scalan/Plugins.scala

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/main/scala/scalan/Scalan.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Scalan
with Functions
with IfThenElse
with Transforming
with GraphVizExport
// with GraphVizExport
with Thunks
with Entities
with Modules
Expand Down
19 changes: 3 additions & 16 deletions core/src/main/scala/scalan/compilation/GraphVizExport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package scalan.compilation
import java.awt.Desktop
import java.io.{PrintWriter, File}

import configs.Configs
import configs.syntax._
import com.typesafe.config.{ConfigUtil, Config}
import configs.Result.{Success, Failure}
import scalan.{Plugins, Scalan, Base}
import scalan.{Scalan, Base}
import scalan.util.{ProcessUtil, FileUtil, StringUtil, ScalaNameUtil}
import scala.collection.immutable.StringOps

Expand All @@ -18,12 +14,7 @@ trait GraphVizExport extends Base { self: Scalan =>

case class GraphFile(file: File, fileType: String) {
def open() = {
Plugins.configWithPlugins.get[String](ConfigUtil.joinPath("graphviz", "viewer", fileType)) match {
case Failure(_) =>
Desktop.getDesktop.open(file)
case Success(command) =>
ProcessUtil.launch(Seq(command, file.getAbsolutePath))
}
Desktop.getDesktop.open(file)
}
}

Expand Down Expand Up @@ -458,7 +449,6 @@ case object Portrait extends Orientation
case object Landscape extends Orientation

object Orientation {
implicit val orientationC: Configs[Orientation] = Configs[Orientation]
}

sealed trait ControlFlowStyle
Expand Down Expand Up @@ -522,7 +512,6 @@ case class GraphVizConfig(emitGraphs: Boolean,
}

object GraphVizConfig {
lazy val config = Plugins.configWithPlugins.getConfig("graphviz")
// not made implicit because it would be too easy to use
// it accidentally instead of passing up
// For some reason, return type has to be given explicitly
Expand All @@ -536,9 +525,7 @@ object GraphVizConfig {
typeAliasEdges = false,
emitMetadata = false,
showLambdaReturnSym = false
) //config.extract[GraphVizConfig]
)

val none: GraphVizConfig = default.copy(emitGraphs = false)

def from(config: Config): GraphVizConfig = config.withFallback(this.config).extract[GraphVizConfig].value
}
8 changes: 6 additions & 2 deletions core/src/main/scala/scalan/primitives/Functions.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package scalan.primitives

import java.util

import scalan.staged.ProgramGraphs
import scalan.util.GraphUtil
import scalan.{Lazy, Base, Nullable, Scalan}
import debox.{Buffer => DBuffer}

import scala.language.implicitConversions
import spire.syntax.all.cfor

import scala.collection.Seq

trait Functions extends Base with ProgramGraphs { self: Scalan =>

implicit class LambdaOps[A,B](f: Ref[A => B]) {
Expand Down Expand Up @@ -102,9 +106,9 @@ trait Functions extends Base with ProgramGraphs { self: Scalan =>
def productArity: Int = 2

// AstGraph implementation
val boundVars = Array(x)
val boundVars: Seq[Sym] = Array[Sym](x)
val boundVarId = x.node._nodeId
val roots = Array(y)
val roots: Seq[Sym] = Array(y)

override lazy val rootIds: DBuffer[Int] = super.rootIds

Expand Down
10 changes: 6 additions & 4 deletions core/src/main/scala/scalan/primitives/Thunks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import spire.syntax.all.cfor
import scala.reflect.runtime.universe._
import scalan.util.{Covariant, GraphUtil}

import scala.collection.Seq

trait Thunks extends Functions with GraphVizExport { self: Scalan =>

type Th[+T] = Ref[Thunk[T]]
Expand Down Expand Up @@ -109,11 +111,11 @@ trait Thunks extends Functions with GraphVizExport { self: Scalan =>
def productArity: Int = 1

override def boundVars = Nil
override lazy val freeVars = if (schedule.isEmpty) Array(root) else super.freeVars
override lazy val freeVars: Seq[Sym] = if (schedule.isEmpty) Array(root) else super.freeVars

override protected def getDeps: Array[Sym] = freeVars.toArray

val roots = Array(root)
val roots: Seq[Sym] = Array(root)
override lazy val rootIds: DBuffer[Int] = super.rootIds
override def isIdentity: Boolean = false
}
Expand All @@ -139,7 +141,7 @@ trait Thunks extends Functions with GraphVizExport { self: Scalan =>
def scheduleForResult(root: Ref[Any]): DBuffer[Int] = {
val sch = GraphUtil.depthFirstOrderFrom(
DBuffer(root.node.nodeId),
{ id: Int =>
new DFunc[Int, DBuffer[Int]] { def apply(id: Int) = {
val deps = getSym(id).node.deps
val res = DBuffer.ofSize[Int](deps.length)
cfor(0)(_ < deps.length, _ + 1) { i =>
Expand All @@ -149,7 +151,7 @@ trait Thunks extends Functions with GraphVizExport { self: Scalan =>
res += id
}
res
}
}}
)
sch
}
Expand Down
Loading

0 comments on commit 910ef28

Please sign in to comment.