Skip to content

Commit 0cd8b30

Browse files
authored
Merge pull request #2081 from ccellado/ergo-core-213
Compile ergo-core and avldb to 2.13 and 2.11
2 parents de98585 + 373d460 commit 0cd8b30

38 files changed

+262
-163
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
matrix:
2323
os: [ubuntu-latest]
24-
scala: [2.13.8, 2.12.10, 2.11.12]
24+
scala: [2.13.12, 2.12.18, 2.11.12]
2525
java: [adopt@1.8]
2626
runs-on: ${{ matrix.os }}
2727
steps:
@@ -62,7 +62,7 @@ jobs:
6262
strategy:
6363
matrix:
6464
os: [ubuntu-latest]
65-
scala: [2.12.10]
65+
scala: [2.12.18]
6666
java: [adopt@1.8]
6767
runs-on: ${{ matrix.os }}
6868
steps:

avldb/build.sbt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import sbt.Keys.testFrameworks
22

3+
val scala211 = "2.11.12"
4+
val scala212 = "2.12.18"
5+
val scala213 = "2.13.12"
6+
37
name := "avldb"
48

9+
val Versions = new {
10+
11+
val spire = (scalaVersion: String) =>
12+
if (scalaVersion == scala213) "0.17.0"
13+
else "0.14.1"
14+
15+
val scalameter = (scalaVersion: String) =>
16+
if (scalaVersion == scala213) "0.19"
17+
else "0.9"
18+
}
19+
520
libraryDependencies ++= Seq(
621
"javax.xml.bind" % "jaxb-api" % "2.4.0-b180830.0359",
722
"ch.qos.logback" % "logback-classic" % "1.2.3",
823
"com.google.guava" % "guava" % "23.0",
9-
"org.scorexfoundation" %% "scrypto" % "2.3.0"
10-
)
11-
12-
libraryDependencies ++= Seq(
24+
"org.scorexfoundation" %% "scrypto" % "2.3.0",
1325
"org.scalatest" %% "scalatest" % "3.1.1" % "test",
1426
"org.scalacheck" %% "scalacheck" % "1.14.3" % "test",
1527
"org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % Test,
16-
"com.storm-enroute" %% "scalameter" % "0.9" % "test"
17-
)
18-
19-
libraryDependencies ++= Seq(
28+
"com.storm-enroute" %% "scalameter" % Versions.scalameter(scalaVersion.value) % "test",
2029
"org.ethereum" % "leveldbjni-all" % "1.18.3",
21-
"org.typelevel" %% "spire" % "0.14.1"
30+
"org.typelevel" %% "spire" % Versions.spire(scalaVersion.value)
2231
)
2332

2433
testOptions in Test := Seq(Tests.Filter(t => !t.matches(".*Benchmark$")))
@@ -38,13 +47,13 @@ publishTo := {
3847

3948
pomIncludeRepository := { _ => false }
4049

41-
scalacOptions ++= Seq("-Xfatal-warnings", "-feature", "-deprecation")
50+
scalacOptions ++= Seq("-feature", "-deprecation")
4251

4352
// set bytecode version to 8 to fix NoSuchMethodError for various ByteBuffer methods
4453
// see https://github.com/eclipse/jetty.project/issues/3244
4554
// these options applied only in "compile" task since scalac crashes on scaladoc compilation with "-release 8"
4655
// see https://github.com/scala/community-builds/issues/796#issuecomment-423395500
47-
scalacOptions in(Compile, compile) ++= Seq("-release", "8")
48-
scalacOptions --= Seq("-Ywarn-numeric-widen", "-Ywarn-value-discard")
56+
scalacOptions in(Compile, compile) ++= (if (scalaBinaryVersion.value == "2.11") Seq() else Seq("-release", "8"))
57+
scalacOptions --= Seq("-Ywarn-numeric-widen", "-Ywarn-value-discard", "-Ywarn-unused:params", "-Xfatal-warnings")
4958

5059
enablePlugins(ReproducibleBuildsPlugin)

avldb/src/main/scala/scorex/crypto/authds/avltree/batch/VersionedLDBAVLStorage.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class VersionedLDBAVLStorage(store: LDBVersionedStore)
114114
}
115115

116116
def dumpSubtree(sid: DigestType): Try[Unit] = {
117-
val builder = mutable.ArrayBuilder.make[Byte]()
117+
val builder = new mutable.ArrayBuilder.ofByte
118118
builder.sizeHint(200000)
119119
subtreeLoop(sid, builder)
120120
dumpStorage.insert(sid, builder.result())
@@ -141,7 +141,7 @@ class VersionedLDBAVLStorage(store: LDBVersionedStore)
141141

142142
require(rootNodeLabel.sameElements(expectedRootHash), "Root node hash changed")
143143

144-
val manifestBuilder = mutable.ArrayBuilder.make[Byte]()
144+
val manifestBuilder = new mutable.ArrayBuilder.ofByte
145145
manifestBuilder.sizeHint(200000)
146146
manifestBuilder += rootNodeHeight
147147
manifestBuilder += manifestDepth

avldb/src/main/scala/scorex/db/ByteArrayUtils.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ object ByteArrayUtils {
55
import java.util.Comparator
66

77
// Java comparator
8-
val BYTE_ARRAY_COMPARATOR: Comparator[Array[Byte]] = (o1: Array[Byte], o2: Array[Byte]) => compare(o1, o2)
9-
8+
object BYTE_ARRAY_COMPARATOR extends Ordering[Array[Byte]] {
9+
def compare(o1: Array[Byte], o2: Array[Byte]) = compare(o1, o2)
10+
}
1011
// Scala comparator
11-
implicit val ByteArrayOrdering: Ordering[Array[Byte]] =
12-
(o1: Array[Byte], o2: Array[Byte]) => ByteArrayUtils.compare(o1, o2)
12+
implicit object ByteArrayOrdering extends Ordering[Array[Byte]] {
13+
def compare(o1: Array[Byte], o2: Array[Byte]) = ByteArrayUtils.compare(o1, o2)
14+
}
1315

1416
def compare(o1: Array[Byte], o2: Array[Byte]): Int = {
1517
val len = Math.min(o1.length, o2.length)

avldb/src/main/scala/scorex/db/LDBKVStore.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class LDBKVStore(protected val db: DB) extends KVStoreReader with ScorexLogging
8282
breakable {
8383
while (i.hasNext) {
8484
val key = i.next().getKey
85-
if (ByteArrayUtils.compare(key, last) <= 0) res = Some(key) else break
85+
if (ByteArrayUtils.compare(key, last) <= 0) res = Some(key) else break()
8686
}
8787
}
8888
res

avldb/src/test/scala/scorex/db/ByteArrayUtilsSpec.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ import org.scalatest.matchers.should.Matchers
66
import org.scalatest.propspec.AnyPropSpec
77
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
88

9+
import scala.collection.mutable
10+
import scala.math.Ordering.Implicits._
11+
912
class ByteArrayUtilsSpec extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers {
1013

1114
lazy val nonEmptyBytesGen: Gen[Array[Byte]] = Gen.nonEmptyListOf(Arbitrary.arbitrary[Byte])
1215
.map(_.toArray).suchThat(_.length > 0)
1316

1417
property("compare works properly") {
1518

16-
//Simple and inefficient way to order byte arrays, based on
17-
// https://stackoverflow.com/questions/7109943/how-to-define-orderingarraybyte
18-
// but we compare unsigned bytes
19-
val ordering: Ordering[Array[Byte]] = Ordering.by((_: Array[Byte]).toIterable.map(_ & 0xFF))
19+
val ordering: Ordering[Array[Byte]] =
20+
new Ordering[Array[Byte]] {
21+
override def compare(o1: Array[Byte], o2: Array[Byte]): Int =
22+
implicitly[Ordering[Seq[Int]]].compare(o1.toSeq.map(_ & 0xFF), o2.toSeq.map(_ & 0xFF))
23+
}
2024

2125
forAll(nonEmptyBytesGen, nonEmptyBytesGen) { case (bs1, bs2) =>
2226
val efficientOrdering = Seq(bs1, bs2).sorted(ByteArrayUtils.ByteArrayOrdering)

build.sbt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ logLevel := Level.Debug
55

66
// this values should be in sync with ergo-wallet/build.sbt
77
val scala211 = "2.11.12"
8-
val scala212 = "2.12.10"
9-
val scala213 = "2.13.8"
8+
val scala212 = "2.12.18"
9+
val scala213 = "2.13.12"
1010

1111
lazy val commonSettings = Seq(
1212
organization := "org.ergoplatform",
@@ -44,16 +44,10 @@ val ficusVersion = "1.4.7"
4444
val effectiveSigmaStateVersion = Option(System.getenv().get("SIGMASTATE_VERSION")).getOrElse(sigmaStateVersion)
4545
val effectiveSigma = "org.scorexfoundation" %% "sigma-state" % effectiveSigmaStateVersion
4646

47-
4847
libraryDependencies ++= Seq(
4948
effectiveSigma.force()
5049
.exclude("ch.qos.logback", "logback-classic")
5150
.exclude("org.scorexfoundation", "scrypto"),
52-
53-
// api dependencies
54-
"io.circe" %% "circe-core" % circeVersion,
55-
"io.circe" %% "circe-generic" % circeVersion,
56-
"io.circe" %% "circe-parser" % circeVersion,
5751

5852
"ch.qos.logback" % "logback-classic" % "1.3.5",
5953

@@ -208,14 +202,17 @@ scapegoatDisabledInspections := Seq("FinalModifierOnCaseClass")
208202
Test / testOptions := Seq(Tests.Filter(s => !s.endsWith("Bench")))
209203

210204
lazy val avldb = (project in file("avldb"))
205+
.disablePlugins(ScapegoatSbtPlugin) // not compatible with crossScalaVersions
211206
.settings(
207+
crossScalaVersions := Seq(scala213, scalaVersion.value, scala211),
212208
commonSettings,
213209
name := "avldb",
214210
// set bytecode version to 8 to fix NoSuchMethodError for various ByteBuffer methods
215211
// see https://github.com/eclipse/jetty.project/issues/3244
216212
// these options applied only in "compile" task since scalac crashes on scaladoc compilation with "-release 8"
217213
// see https://github.com/scala/community-builds/issues/796#issuecomment-423395500
218-
scalacOptions in(Compile, compile) ++= Seq("-release", "8"),
214+
scalacOptions in(Compile, compile) ++= (if (scalaBinaryVersion.value == "2.11") Seq() else Seq("-release", "8")),
215+
scalacOptions in(Compile, compile) --= scalacOpts,
219216
javacOptions in(Compile, compile) ++= javacReleaseOption,
220217
libraryDependencies ++= Seq(
221218
// database dependencies
@@ -244,17 +241,19 @@ lazy val avldb_benchmarks = (project in file("avldb/benchmarks"))
244241
.enablePlugins(JmhPlugin)
245242

246243
lazy val ergoCore = (project in file("ergo-core"))
244+
.disablePlugins(ScapegoatSbtPlugin) // not compatible with crossScalaVersions
247245
.dependsOn(avldb % "test->test;compile->compile")
248246
.dependsOn(ergoWallet % "test->test;compile->compile")
249247
.settings(
248+
crossScalaVersions := Seq(scala213, scalaVersion.value, scala211),
250249
commonSettings,
251250
name := "ergo-core",
252251
libraryDependencies ++= Seq(
253252
"com.iheart" %% "ficus" % ficusVersion,
254253
effectiveSigma,
255254
(effectiveSigma % Test).classifier("tests")
256255
),
257-
scalacOptions in(Compile, compile) ++= Seq("-release", "8"),
256+
scalacOptions in(Compile, compile) ++= (if (scalaBinaryVersion.value == "2.11") Seq() else Seq("-release", "8")),
258257
scalacOptions in(Compile, compile) --= scalacOpts,
259258
)
260259

@@ -293,6 +292,10 @@ lazy val ergo = (project in file("."))
293292
scalacOptions in(Compile, compile) ++= Seq("-release", "8"),
294293
javacOptions in(Compile, compile) ++= javacReleaseOption,
295294
libraryDependencies ++= Seq(
295+
// api dependencies
296+
"io.circe" %% "circe-core" % circeVersion,
297+
"io.circe" %% "circe-generic" % circeVersion,
298+
"io.circe" %% "circe-parser" % circeVersion,
296299
// network dependencies
297300
"com.typesafe.akka" %% "akka-stream" % akkaVersion, // required for akka-http to compile
298301
"com.typesafe.akka" %% "akka-actor" % akkaVersion, // required for akka-http to compile

ergo-core/build.sbt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
// this values should be in sync with root (i.e. ../build.sbt)
22
val scala211 = "2.11.12"
3-
val scala212 = "2.12.10"
4-
val scala213 = "2.13.8"
3+
val scala212 = "2.12.18"
4+
val scala213 = "2.13.12"
5+
6+
val deps211 = Seq(
7+
"io.circe" %% "circe-core" % "0.10.0",
8+
"io.circe" %% "circe-generic" % "0.10.0",
9+
"io.circe" %% "circe-parser" % "0.10.0")
10+
val deps212 = Seq(
11+
"io.circe" %% "circe-core" % "0.13.0",
12+
"io.circe" %% "circe-generic" % "0.13.0",
13+
"io.circe" %% "circe-parser" % "0.13.0")
14+
15+
libraryDependencies ++= Seq() ++
16+
(if (scalaVersion.value == scala211) deps211 else deps212)
17+
18+
scalacOptions ++= (if (scalaBinaryVersion.value == scala211) Seq("-language:implicitConversions") else Seq())
19+
scalacOptions --= Seq("-Ywarn-numeric-widen", "-Ywarn-value-discard", "-Ywarn-unused:params", "-Xfatal-warnings")

0 commit comments

Comments
 (0)