forked from alephium/alephium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
550 lines (498 loc) · 15.1 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
import sbt._
import sbt.Keys._
import APIMapping._
import Dependencies._
Global / cancelable := true // Allow cancellation of forked task without killing SBT
resolvers += "Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/"
def baseProject(id: String): Project = {
Project(id, file(id))
.settings(commonSettings: _*)
.settings(name := s"alephium-$id")
}
val scalastyleCfgFile = "project/scalastyle-config.xml"
val scalastyleTestCfgFile = "project/scalastyle-test-config.xml"
lazy val root: Project = Project("alephium-scala-blockflow", file("."))
.settings(commonSettings: _*)
.settings(
name := "alephium",
scalastyle := {},
Test / scalastyle := {},
publish / skip := true
)
.aggregate(
macros,
util,
serde,
io,
crypto,
api,
rpc,
app,
benchmark,
flow,
json,
conf,
protocol,
ralph,
http,
wallet,
ralphc,
tools
)
def mainProject(id: String): Project =
project(id).enablePlugins(JavaAppPackaging).dependsOn(flow)
def project(path: String): Project = {
baseProject(path)
.configs(IntegrationTest extend Test)
.settings(
Defaults.itSettings,
inConfig(IntegrationTest)(org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings),
Compile / scalastyleConfig := root.base / scalastyleCfgFile,
Test / scalastyleConfig := root.base / scalastyleTestCfgFile,
inConfig(IntegrationTest)(ScalastylePlugin.rawScalastyleSettings()),
IntegrationTest / scalastyleConfig := root.base / scalastyleTestCfgFile,
IntegrationTest / scalastyleTarget := target.value / "scalastyle-it-results.xml",
IntegrationTest / scalastyleSources := (IntegrationTest / unmanagedSourceDirectories).value,
apiMappings +=
APIMapping.scalaDocs(
classPath = (Compile / fullClasspath).value,
scalaVersion = scalaVersion.value
)
)
}
lazy val macros = project("macros")
.settings(
libraryDependencies += `scala-reflect`(scalaVersion.value),
Compile / compile / wartremoverErrors := Seq()
)
lazy val util = project("util")
.dependsOn(macros)
.settings(
libraryDependencies ++= Seq(
akka,
`akka-slf4j`,
bcprov,
`scala-logging`,
`scala-reflect`(scalaVersion.value)
)
)
lazy val serde = project("serde")
.settings(
Compile / sourceGenerators += (Compile / sourceManaged).map(Boilerplate.genSrc).taskValue,
Test / sourceGenerators += (Test / sourceManaged).map(Boilerplate.genTest).taskValue
)
.dependsOn(util % "test->test;compile->compile")
lazy val crypto = project("crypto")
.dependsOn(util % "test->test;compile->compile", serde, json % "test->test")
lazy val io = project("io")
.dependsOn(util % "test->test;compile->compile", serde, crypto)
.settings(
libraryDependencies ++= Seq(rocksdb, `scala-logging`)
)
lazy val rpc = project("rpc")
.settings(
libraryDependencies ++= Seq(
`scala-logging`,
`akka-test`
),
publish / skip := true
)
.dependsOn(json, util % "test->test;compile->compile")
lazy val api = project("api")
.dependsOn(
json,
protocol % "test->test;compile->compile",
ralph % "test->test;compile->compile",
crypto,
serde,
util % "test->test;compile->compile"
)
.settings(
libraryDependencies ++= Seq(
`scala-logging`,
`tapir-core`,
`tapir-server`,
`tapir-openapi`,
`tapir-openapi-model`
)
)
lazy val app = mainProject("app")
.dependsOn(
json,
api,
rpc,
http % "compile->compile;test->test",
util % "it,test->test",
flow,
flow % "it,test->test",
wallet
)
.enablePlugins(sbtdocker.DockerPlugin, BuildInfoPlugin)
.settings(
assembly / mainClass := Some("org.alephium.app.Boot"),
assembly / assemblyJarName := s"alephium-${version.value}.jar",
assembly / test := {},
assemblyMergeStrategy := {
case "logback.xml" => MergeStrategy.first
case PathList("META-INF", "maven", "org.webjars", "swagger-ui", xs @ _*) =>
MergeStrategy.first
case PathList("META-INF", "io.netty.versions.properties", xs @ _*) =>
MergeStrategy.first
case PathList("module-info.class") =>
MergeStrategy.discard
case x if x.endsWith("module-info.class") =>
MergeStrategy.discard
case other =>
assemblyMergeStrategy.value(other)
},
libraryDependencies ++= Seq(
vertx,
`tapir-core`,
`tapir-vertx`,
`tapir-openapi`,
`tapir-swagger-ui`
),
publish / skip := true,
docker / dockerfile := {
val artifact: File = assembly.value
val artifactTargetPath = "/alephium.jar"
val userConf: File = file("docker/user.conf")
val alephiumHome = "/alephium-home"
new Dockerfile {
from("openjdk:17-jdk")
// Uncomment the next line and comment the previous one if you want to use GraalVM instead of OpenJDK
// from("ghcr.io/graalvm/graalvm-ce:java11-21.0.0.2")
runRaw(
Seq(
s"mkdir -p $alephiumHome && usermod -d $alephiumHome nobody && chown nobody $alephiumHome",
s"mkdir -p $alephiumHome/.alephium && chown nobody $alephiumHome/.alephium",
s"mkdir -p $alephiumHome/.alephium/mainnet && chown nobody $alephiumHome/.alephium/mainnet",
s"mkdir -p $alephiumHome/.alephium-wallets && chown nobody $alephiumHome/.alephium-wallets"
).mkString(" && ")
)
workDir(alephiumHome)
copy(userConf, file(s"$alephiumHome/.alephium/user.conf"))
copy(artifact, artifactTargetPath)
expose(12973) // http
expose(11973) // ws
expose(10973) // miner
expose(9973) // p2p
volume(s"$alephiumHome/.alephium")
volume(s"$alephiumHome/.alephium-wallets")
user("nobody")
entryPoint("java", "-jar", artifactTargetPath)
}
},
docker / imageNames := {
dockerImageNames(
baseImageName = "alephium/dev-alephium",
versionTag = version.value.replace('+', '_')
)
},
buildInfoKeys := Seq[BuildInfoKey](
name,
scalaVersion,
sbtVersion,
BuildInfoKey("commitId" -> git.gitHeadCommit.value.getOrElse("missing-git-commit")),
BuildInfoKey("branch" -> git.gitCurrentBranch.value),
BuildInfoKey("releaseVersion" -> version.value)
),
buildInfoPackage := "org.alephium.app",
buildInfoUsePackageAsPath := true
)
lazy val json = project("json")
.dependsOn(util % "test->test")
.settings(
libraryDependencies ++= Seq(
upickle
)
)
lazy val conf = project("conf")
.dependsOn(protocol, util)
.settings(
libraryDependencies ++= Seq(
ficus
)
)
lazy val http = project("http")
.dependsOn(api, json, util % "test->test")
.settings(
libraryDependencies ++= Seq(
`tapir-vertx`,
`tapir-client`,
`sttp-backend`
)
)
lazy val tools = mainProject("tools")
.enablePlugins(sbtdocker.DockerPlugin)
.settings(
assembly / assemblyJarName := s"alephium-tools-${version.value}.jar",
assembly / test := {},
assemblyMergeStrategy := {
case "logback.xml" => MergeStrategy.first
case PathList("META-INF", "io.netty.versions.properties", xs @ _*) =>
MergeStrategy.first
case PathList("module-info.class") =>
MergeStrategy.discard
case x if x.endsWith("module-info.class") =>
MergeStrategy.discard
case other =>
assemblyMergeStrategy.value(other)
},
docker / dockerfile := {
val artifact: File = assembly.value
val artifactTargetPath = "/alephium-tools.jar"
val alephiumHome = "/alephium-home"
new Dockerfile {
from("openjdk:17-jdk")
runRaw(
Seq(
s"mkdir -p $alephiumHome && usermod -d $alephiumHome nobody && chown nobody $alephiumHome",
s"mkdir -p $alephiumHome/.alephium && chown nobody $alephiumHome/.alephium",
s"mkdir -p $alephiumHome/.alephium/mainnet && chown nobody $alephiumHome/.alephium/mainnet"
).mkString(" && ")
)
workDir(alephiumHome)
copy(artifact, artifactTargetPath)
volume(s"$alephiumHome/.alephium")
user("nobody")
entryPoint("java", "-cp", artifactTargetPath)
}
},
docker / imageNames := {
dockerImageNames(
baseImageName = "alephium/dev-alephium-tools",
versionTag = version.value.replace('+', '_')
)
}
)
.dependsOn(app)
lazy val benchmark = project("benchmark")
.enablePlugins(JmhPlugin)
.dependsOn(flow)
.settings(
publish / skip := true,
scalacOptions += "-Xdisable-assertions",
Compile / compile / wartremoverErrors := Seq.empty
)
lazy val flow = project("flow")
.dependsOn(conf, crypto, io, serde, util % "test->test")
.settings(
libraryDependencies ++= Seq(
akka,
`akka-slf4j`,
logback,
`scala-logging`,
weupnp,
`prometheus-simple-client`,
`prometheus-simple-client-common`,
`prometheus-simple-client-hotspot`
),
publish / skip := true
)
.dependsOn(protocol % "test->test;compile->compile", ralph % "test->test;compile->compile")
lazy val protocol = project("protocol")
.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoPackage := "org.alephium.protocol",
buildInfoUsePackageAsPath := true
)
.dependsOn(
crypto % "compile->compile;test->test",
io % "compile->compile;test->test",
serde,
util % "test->test"
)
.settings(
libraryDependencies ++= Seq(
`prometheus-simple-client`,
fastparse
)
)
lazy val ralph = project("ralph")
.dependsOn(protocol % "test->test;compile->compile")
.settings(
apiMappings +=
APIMapping.fastParseDocs(
classPath = (Compile / fullClasspath).value,
scalaVersion = scalaVersion.value
)
)
lazy val wallet = project("wallet")
.dependsOn(
conf,
json,
api,
crypto,
http % "compile->compile;test->test",
util % "test->test",
protocol % "compile->compile;test->test"
)
.settings(
libraryDependencies ++= Seq(
vertx,
`scala-logging`,
`tapir-core`,
`tapir-openapi`,
`tapir-swagger-ui`,
`scala-logging`,
logback
),
publish / skip := true,
assembly / mainClass := Some("org.alephium.wallet.Main"),
assembly / assemblyJarName := s"alephium-wallet-${version.value}.jar",
assembly / test := {},
assemblyMergeStrategy := {
case PathList("META-INF", "maven", "org.webjars", "swagger-ui", xs @ _*) =>
MergeStrategy.first
case PathList("META-INF", "io.netty.versions.properties", xs @ _*) =>
MergeStrategy.first
case PathList("module-info.class") =>
MergeStrategy.discard
case x if x.endsWith("module-info.class") =>
MergeStrategy.discard
case other =>
assemblyMergeStrategy.value(other)
}
)
lazy val ralphc = project("ralphc")
.dependsOn(
json,
api,
crypto,
ralph,
util % "test->test",
protocol % "compile->compile;test->test"
)
.settings(
libraryDependencies ++= Seq(
upickle,
scopt
),
publish / skip := false,
assembly / mainClass := Some("org.alephium.ralphc.Main"),
assembly / assemblyJarName := s"alephium-ralphc-${version.value}.jar",
assembly / test := {},
assemblyMergeStrategy := {
case PathList("module-info.class") =>
MergeStrategy.discard
case x if x.endsWith("module-info.class") =>
MergeStrategy.discard
case other =>
assemblyMergeStrategy.value(other)
}
)
val publishSettings = Seq(
organization := "org.alephium",
homepage := Some(url("https://github.com/alephium/alephium")),
licenses := Seq("LGPL 3.0" -> new URL("https://www.gnu.org/licenses/lgpl-3.0.en.html")),
developers := List(
Developer(
id = "alephium core dev",
name = "alephium core dev",
email = "[email protected]",
url = url("https://alephium.org/")
)
)
)
val commonSettings = publishSettings ++ Seq(
scalaVersion := "2.13.10",
Test / parallelExecution := false,
scalacOptions ++= Seq(
"-Xsource:3",
"-opt:l:method",
// "-Xdisable-assertions", // TODO: use this properly
"-deprecation",
"-encoding",
"utf-8",
"-explaintypes",
"-feature",
"-unchecked",
"-Xlint:adapted-args",
"-Xlint:constant",
"-Xlint:delayedinit-select",
"-Xlint:doc-detached",
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:missing-interpolator",
"-Xlint:nullary-unit",
"-Xlint:option-implicit",
"-Xlint:package-object-classes",
"-Xlint:poly-implicit-overload",
"-Xlint:private-shadow",
"-Xlint:stars-align",
"-Xlint:type-parameter-shadow",
"-Xlint:nonlocal-return",
"-Xfatal-warnings",
"-Ywarn-dead-code",
"-Ywarn-extra-implicit",
"-Ywarn-numeric-widen",
"-Ywarn-unused:implicits",
"-Ywarn-unused:imports",
"-Ywarn-unused:locals",
"-Ywarn-unused:params",
"-Ywarn-unused:patvars",
"-Ywarn-unused:privates",
"-Ywarn-value-discard",
"-Ymacro-annotations"
),
Compile / console / scalacOptions --= Seq("-Ywarn-unused:imports", "-Xfatal-warnings"),
Compile / compile / wartremoverErrors := Warts.allBut(wartsCompileExcludes: _*),
Test / test / wartremoverErrors := Warts.allBut(wartsTestExcludes: _*),
IntegrationTest / test / wartremoverErrors := Warts.allBut(wartsTestExcludes: _*),
fork := true,
javaOptions += "-Xss2m",
Test / scalacOptions ++= Seq("-Xcheckinit"),
Test / envVars += "ALEPHIUM_ENV" -> "test",
Test / testOptions += Tests.Argument("-oD"),
IntegrationTest / envVars += "ALEPHIUM_ENV" -> "it",
libraryDependencies ++= Seq(
`akka-test`,
scalacheck,
scalatest,
scalatestplus
),
Compile / doc / sources ~= (_ filter (_.getName endsWith ".scala"))
)
val wartsCompileExcludes = Seq(
Wart.MutableDataStructures,
Wart.Var,
Wart.Overloading,
Wart.ImplicitParameter,
Wart.NonUnitStatements,
Wart.Nothing,
Wart.Null, // Partially covered by scalastyle, only use _ inside actors
Wart.Return, // Covered by scalastyle
Wart.Any,
Wart.Throw,
Wart.Equals,
Wart.StringPlusAny,
Wart.While,
Wart.SizeIs,
Wart.ScalaApp
)
val wartsTestExcludes = wartsCompileExcludes ++ Seq(
Wart.PublicInference,
Wart.IterableOps,
Wart.OptionPartial
)
def dockerImageNames(baseImageName: String, versionTag: String): Seq[ImageName] = {
Seq(
ImageName(baseImageName + ":latest"),
ImageName(baseImageName + ":" + versionTag),
ImageName(baseImageName + ":" + versionTag + "-jdk17")
)
}
addCommandAlias(
"format",
"scalafmtSbt;scalafmt;test:scalafmt;scalastyle;test:scalastyle;it:scalafmt;it:scalastyle;doc"
)
addCommandAlias(
"unitTest",
"scalafmtSbtCheck;scalafmtCheck;test:scalafmtCheck;scalastyle;test:scalastyle;coverage;test;coverageReport;doc"
)
addCommandAlias(
"integrationTest",
"it:scalafmtCheck;it:scalastyle;it:test"
)