-
Notifications
You must be signed in to change notification settings - Fork 75
/
build.sbt
372 lines (334 loc) · 11 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
enablePlugins(JDKPackagerPlugin, JavaAppPackaging, SolidityPlugin, JavaAgent)
javaAgents += "io.kamon" % "kanela-agent" % "1.0.6"
import scala.sys.process.Process
import NativePackagerHelper._
import com.typesafe.sbt.SbtGit.GitKeys._
// Necessary for the nix build, please do not remove.
val nixBuild = sys.props.isDefinedAt("nix")
// Enable dev mode: disable certain flags, etc.
val mantisDev = sys.props.get("mantisDev").contains("true") || sys.env.get("MANTIS_DEV").contains("true")
lazy val compilerOptimizationsForProd = Seq(
"-opt:l:method", // method-local optimizations
"-opt:l:inline", // inlining optimizations
"-opt-inline-from:io.iohk.**" // inlining the project only
)
// Releasing. https://github.com/olafurpg/sbt-ci-release
inThisBuild(
List(
organization := "io.iohk",
homepage := Some(url("https://github.com/input-output-hk/mantis")),
scmInfo := Some(
ScmInfo(url("https://github.com/input-output-hk/mantis"), "[email protected]:input-output-hk/mantis.git")
),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List()
)
)
// https://github.com/sbt/sbt/issues/3570
updateOptions := updateOptions.value.withGigahorse(false)
// artifact name will include scala version
crossPaths := true
// patch for error on 'early-semver' problems
ThisBuild / evictionErrorLevel := Level.Info
val `scala-2.12` = "2.12.13"
val `scala-2.13` = "2.13.6"
val supportedScalaVersions = List(`scala-2.12`, `scala-2.13`)
val baseScalacOptions = Seq(
"-unchecked",
"-deprecation",
"-feature",
"-Ywarn-unused",
"-Xlint",
"-encoding",
"utf-8"
)
// https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html
// cat={warning-name}:ws prints a summary with the number of warnings of the given type
// any:e turns all remaining warnings into errors
val fatalWarnings = Seq(if (sys.env.get("MANTIS_FULL_WARNS").contains("true")) {
"-Wconf:any:w"
} else {
"-Wconf:" ++ Seq(
// Let's turn those gradually into errors:
"cat=deprecation:ws",
"cat=lint-package-object-classes:ws",
"cat=unused:ws",
"cat=lint-infer-any:ws",
"cat=lint-byname-implicit:ws",
"cat=other-match-analysis:ws",
"any:e"
).mkString(",")
}) ++ Seq("-Ypatmat-exhaust-depth", "off")
def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
name := projectName,
organization := "io.iohk",
scalaVersion := `scala-2.13`,
semanticdbEnabled := true, // enable SemanticDB
semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version
ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value),
ThisBuild / scalafixDependencies ++= List(
"com.github.liancheng" %% "organize-imports" % "0.5.0",
"com.github.vovapolu" %% "scaluzzi" % "0.1.16"
),
// Scalanet snapshots are published to Sonatype after each build.
resolvers += "Sonatype OSS Snapshots".at("https://oss.sonatype.org/content/repositories/snapshots"),
(Test / testOptions) += Tests
.Argument(TestFrameworks.ScalaTest, "-l", "EthashMinerSpec"), // miner tests disabled by default,
scalacOptions := baseScalacOptions ++ fatalWarnings,
scalacOptions ++= (if (mantisDev) Seq.empty else compilerOptimizationsForProd),
(Compile / console / scalacOptions) ~= (_.filterNot(
Set(
"-Ywarn-unused-import",
"-Xfatal-warnings"
)
)),
(Compile / doc / scalacOptions) := baseScalacOptions,
scalacOptions ~= (options => if (mantisDev) options.filterNot(_ == "-Xfatal-warnings") else options),
Test / parallelExecution := true,
(Test / testOptions) += Tests.Argument("-oDG"),
(Test / scalastyleConfig) := file("scalastyle-test-config.xml"),
// Only publish selected libraries.
(publish / skip) := true
)
val publishSettings = Seq(
publish / skip := false,
crossScalaVersions := supportedScalaVersions
)
// Adding an "it" config because in `Dependencies.scala` some are declared with `% "it,test"`
// which would fail if the project didn't have configuration to add to.
val Integration = config("it").extend(Test)
lazy val bytes = {
val bytes = project
.in(file("bytes"))
.configs(Integration)
.settings(commonSettings("mantis-bytes"))
.settings(inConfig(Integration)(scalafixConfigSettings(Integration)))
.settings(publishSettings)
.settings(
libraryDependencies ++=
Dependencies.akkaUtil ++
Dependencies.testing
)
bytes
}
lazy val crypto = {
val crypto = project
.in(file("crypto"))
.configs(Integration)
.dependsOn(bytes)
.settings(commonSettings("mantis-crypto"))
.settings(inConfig(Integration)(scalafixConfigSettings(Integration)))
.settings(publishSettings)
.settings(
libraryDependencies ++=
Dependencies.akkaUtil ++
Dependencies.crypto ++
Dependencies.testing
)
crypto
}
lazy val rlp = {
val rlp = project
.in(file("rlp"))
.configs(Integration)
.dependsOn(bytes)
.settings(commonSettings("mantis-rlp"))
.settings(inConfig(Integration)(scalafixConfigSettings(Integration)))
.settings(publishSettings)
.settings(
libraryDependencies ++=
Dependencies.akkaUtil ++
Dependencies.shapeless ++
Dependencies.testing
)
rlp
}
lazy val node = {
val Benchmark = config("benchmark").extend(Test)
val Evm = config("evm").extend(Test)
val Rpc = config("rpcTest").extend(Test)
val malletDeps = Seq(
Dependencies.scopt
).flatten ++ Seq(
Dependencies.jline,
Dependencies.jna
)
val dep = {
Seq(
Dependencies.akka,
Dependencies.akkaHttp,
Dependencies.apacheCommons,
Dependencies.boopickle,
Dependencies.cats,
Dependencies.circe,
Dependencies.cli,
Dependencies.crypto,
Dependencies.dependencies,
Dependencies.enumeratum,
Dependencies.guava,
Dependencies.json4s,
Dependencies.kamon,
Dependencies.logging,
Dependencies.micrometer,
Dependencies.monix,
Dependencies.network,
Dependencies.prometheus,
Dependencies.rocksDb,
Dependencies.scaffeine,
Dependencies.scopt,
Dependencies.testing
).flatten ++ malletDeps
}
(Test / scalastyleSources) ++= (Integration / unmanagedSourceDirectories).value
(Evm / test) := (Evm / test).dependsOn(solidityCompile).value
(Evm / sourceDirectory) := baseDirectory.value / "src" / "evmTest"
val node = project
.in(file("."))
.configs(Integration, Benchmark, Evm, Rpc)
.enablePlugins(BuildInfoPlugin)
.dependsOn(bytes, crypto, rlp)
.settings(
buildInfoKeys := BuildInfoKey.ofN(
name,
version,
scalaVersion,
sbtVersion,
gitHeadCommit,
gitCurrentBranch,
gitCurrentTags,
gitDescribedVersion,
gitUncommittedChanges,
(Compile / libraryDependencies)
),
buildInfoPackage := "io.iohk.ethereum.utils",
(Test / fork) := true,
(Compile / buildInfoOptions) += BuildInfoOption.ToMap
)
.settings(commonSettings("mantis"): _*)
.settings(inConfig(Integration)(scalafixConfigSettings(Integration)))
.settings(inConfig(Evm)(scalafixConfigSettings(Evm)))
.settings(inConfig(Rpc)(scalafixConfigSettings(Rpc)))
.settings(
libraryDependencies ++= dep
)
.settings(
executableScriptName := name.value
)
.settings(
inConfig(Integration)(
Defaults.testSettings
++ org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings :+ (Test / parallelExecution := false)
): _*
)
.settings(inConfig(Benchmark)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
.settings(inConfig(Evm)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
.settings(inConfig(Rpc)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
.settings(
// protobuf compilation
// Into a subdirectory of src_managed to avoid it deleting other generated files; see https://github.com/sbt/sbt-buildinfo/issues/149
(Compile / PB.targets) := Seq(
scalapb.gen() -> (Compile / sourceManaged).value / "protobuf"
),
// have the protobuf API version file as a resource
(Compile / unmanagedResourceDirectories) += baseDirectory.value / "src" / "main" / "protobuf",
// Packaging
(Compile / mainClass) := Some("io.iohk.ethereum.App"),
(Compile / discoveredMainClasses) := Seq(),
// Requires the 'ant-javafx.jar' that comes with Oracle JDK
// Enables creating an executable with the configuration files, has to be run on the OS corresponding to the desired version
ThisBuild / jdkPackagerType := "image",
(Universal / mappings) ++= directory((Compile / resourceDirectory).value / "conf"),
(Universal / mappings) += (Compile / resourceDirectory).value / "logback.xml" -> "conf/logback.xml",
bashScriptExtraDefines += """addJava "-Dconfig.file=${app_home}/../conf/app.conf"""",
bashScriptExtraDefines += """addJava "-Dlogback.configurationFile=${app_home}/../conf/logback.xml"""",
batScriptExtraDefines += """call :add_java "-Dconfig.file=%APP_HOME%\conf\app.conf"""",
batScriptExtraDefines += """call :add_java "-Dlogback.configurationFile=%APP_HOME%\conf\logback.xml""""
)
.settings(
crossScalaVersions := List(`scala-2.13`)
)
if (!nixBuild)
node
else
//node.settings(PB.protocExecutable := file("protoc"))
node.settings((Compile / PB.runProtoc) := (args => Process("protoc", args) !))
}
coverageExcludedPackages := "io\\.iohk\\.ethereum\\.extvm\\.msg.*"
addCommandAlias(
"compile-all",
""";bytes/compile
|;bytes/test:compile
|;crypto/compile
|;crypto/test:compile
|;rlp/compile
|;rlp/test:compile
|;compile
|;test:compile
|;evm:compile
|;it:compile
|;rpcTest:compile
|;benchmark:compile
|""".stripMargin
)
// prepare PR
addCommandAlias(
"pp",
""";compile-all
|;bytes/scalafmtAll
|;bytes/scalastyle
|;bytes/test:scalastyle
|;crypto/scalafmtAll
|;crypto/scalastyle
|;crypto/test:scalastyle
|;rlp/scalafmtAll
|;rlp/scalastyle
|;rlp/test:scalastyle
|;scalafmtAll
|;scalastyle
|;test:scalastyle
|;rlp/test
|;testQuick
|;it:test
|""".stripMargin
)
// format all modules
addCommandAlias(
"formatAll",
""";compile-all
|;bytes/scalafixAll
|;bytes/scalafmtAll
|;crypto/scalafixAll
|;crypto/scalafmtAll
|;rlp/scalafixAll
|;rlp/scalafmtAll
|;scalafixAll
|;scalafmtAll
|""".stripMargin
)
// check modules formatting
addCommandAlias(
"formatCheck",
""";compile-all
|;bytes/scalafixAll --check
|;bytes/scalafmtCheckAll
|;crypto/scalafixAll --check
|;crypto/scalafmtCheckAll
|;rlp/scalafixAll --check
|;rlp/scalafmtCheckAll
|;scalafixAll --check
|;scalafmtCheckAll
|""".stripMargin
)
// testAll
addCommandAlias(
"testAll",
""";compile-all
|;rlp/test
|;bytes/test
|;crypto/test
|;test
|;it:test
|""".stripMargin
)
(ThisBuild / scapegoatVersion) := "1.4.9"
scapegoatReports := Seq("xml")