Repository navigation
Expand file tree
/
Copy pathbuild.sbt
More file actions
485 lines (429 loc) · 19.3 KB
/
Copy pathbuild.sbt
File metadata and controls
485 lines (429 loc) · 19.3 KB
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
import java.nio.file.Files
import sbt.protocol.testing.TestResult
import scala.jdk.CollectionConverters.*
/* IDEA notes
* May require to delete .idea and re-import with all checkboxes
* Worksheets may not work: https://youtrack.jetbrains.com/issue/SCL-6726
* To work with worksheets, make sure:
1. You've selected the appropriate project
2. You've checked "Make project before run"
*/
Global / onChangedBuildSource := ReloadOnSourceChanges
enablePlugins(GitVersioning)
git.uncommittedSignifier := Some("DIRTY")
ThisBuild / git.useGitDescribe := true
ThisBuild / PB.protocVersion := Dependencies.gProtoVersion
ThisBuild / dependencyOverrides ++= Dependencies.overrides.value
ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / publishMavenStyle := true
ThisBuild / publishTo := {
if (isSnapshot.value) Some(Resolver.sonatypeCentralSnapshots)
else localStaging.value
}
lazy val lang =
crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Full)
.settings(
assembly / test := TestResult.Passed,
libraryDependencies ++= Dependencies.lang.value ++ Dependencies.test,
inConfig(Compile)(
Seq(
sourceGenerators += Tasks.docSource,
PB.targets += PB.Target(scalapb.gen(flatPackage = true), sourceManaged.value),
PB.protoSources += PB.externalIncludePath.value,
PB.generate / includeFilter := { (f: File) =>
(** / "waves" / "lang" / "*.proto").matches(f.toPath)
},
PB.deleteTargetDirectory := false
)
)
)
lazy val `lang-jvm` = lang.jvm
.enablePlugins(PublishedModule)
.settings(
name := "RIDE Compiler",
normalizedName := "lang",
description := "The RIDE smart contract language compiler",
libraryDependencies ++= Seq(
"org.scala-js" %% "scalajs-stubs" % "1.1.0" % Provided,
Dependencies.logback,
Dependencies.scalaLogging,
Dependencies.gProto,
Dependencies.gProto % "protobuf"
)
)
lazy val `lang-js` = lang.js
.enablePlugins(VersionObject)
.settings(
libraryDependencies ++= Dependencies.scalapbRuntimeJS.value
)
lazy val `lang-testkit` = project
.in(file("lang/testkit"))
.dependsOn(`lang-jvm`)
.enablePlugins(PublishedModule)
.settings(
libraryDependencies ++=
Dependencies.test.map(_.withConfigurations(Some("compile"))) ++ Dependencies.logDeps :+
Dependencies.scalaLogging
)
// crypto.Provider registers Conscrypt JVM-wide, from whichever test classloader loads it first. In sbt's own JVM that
// loader is closed once its module's tests finish, and a later module then mixes Conscrypt classes from both loaders
// (IllegalAccessError, ZombieClassLoader). A fork per module gives each its own registration; checkTestLimits asserts
// every module in jvmUnitTestModules forks. A fork inherits nothing from sbt's JVM, so this repeats .sbtopts' module
// access (node code: RocksDB direct buffers, AtomicLong fields) and forwards -Dlogback.test.level.
lazy val forkedTests = Seq(
Test / fork := true,
Test / testForkedParallel := true,
// Uncached: the forwarded -Dlogback.test.level is read from sbt's own JVM, which the action cache does not track
Test / javaOptions ++= Def.uncached(
Seq(
"-Dfile.encoding=UTF-8",
"--add-exports=java.base/sun.nio.ch=ALL-UNNAMED",
"--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED"
) ++ sys.props.get("logback.test.level").map(level => s"-Dlogback.test.level=$level")
)
)
lazy val `lang-tests` = project
.in(file("lang/tests"))
.dependsOn(`lang-testkit`)
.settings(forkedTests)
lazy val node = project.dependsOn(`lang-jvm`)
lazy val `node-testkit` = project
.in(file("node/testkit"))
.dependsOn(`node`, `lang-testkit`)
.enablePlugins(PublishedModule)
.settings(libraryDependencies ++= Dependencies.nodeTests)
lazy val testTmpDir = settingKey[File]("java.io.tmpdir of forked test JVMs, emptied before every test run")
lazy val `node-tests` = project
.in(file("node/tests"))
.dependsOn(`node-testkit`)
.settings(forkedTests)
.settings(
libraryDependencies ++= Dependencies.logDeps,
// A leaking or hung suite must not thrash in GC until CI cancels it: fail fast and leave a heap dump to diagnose
Test / javaOptions ++= {
val root = (ThisBuild / baseDirectory).value
Seq(
"-Xmx4g",
"-XX:+HeapDumpOnOutOfMemoryError",
s"-XX:HeapDumpPath=$root",
"-XX:+ExitOnOutOfMemoryError",
s"-XX:ErrorFile=$root/hs_err_pid%p.log",
s"-Djava.io.tmpdir=${(Test / testTmpDir).value}"
)
},
// Suites clean up after themselves, but a killed fork (cancel, SIGKILL, ExitOnOutOfMemoryError) cannot: keep its temp files (RocksDB
// dirs, native libraries) out of the shared /tmp and wipe them before the next run
Test / testTmpDir := target.value / "test-tmp",
Test / testOptions += {
val dir = (Test / testTmpDir).value
Tests.Setup { () =>
IO.delete(dir)
IO.createDirectory(dir)
}
}
)
lazy val `grpc-server` =
project.dependsOn(node % "compile;runtime->provided", `node-testkit` % "test").settings(forkedTests)
lazy val `ride-runner` = project.dependsOn(node, `grpc-server`, `node-testkit`)
lazy val `node-it` = project.dependsOn(`repl-jvm`, `grpc-server`, `node-testkit`)
lazy val `node-generator` = project.dependsOn(node, `node-testkit`)
lazy val benchmark = project.dependsOn(node, `node-testkit`)
lazy val repl = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Full)
.settings(
libraryDependencies ++= Dependencies.circe.value ++ Seq(
Dependencies.protoSchemasLib % "protobuf"
),
inConfig(Compile)(
Seq(
PB.targets += PB.Target(scalapb.gen(flatPackage = true), sourceManaged.value),
PB.protoSources += PB.externalIncludePath.value,
PB.generate / includeFilter := { (f: File) =>
(** / "waves" / "*.proto").matches(f.toPath)
},
PB.deleteTargetDirectory := false
)
)
)
lazy val `repl-jvm` = repl.jvm
.dependsOn(`lang-jvm`, `lang-testkit`)
.settings(forkedTests)
.settings(
libraryDependencies ++= Seq(
"org.scala-js" %% "scalajs-stubs" % "1.1.0" % Provided,
Dependencies.sttp3
)
)
lazy val `repl-js` = repl.js
.dependsOn(`lang-js`)
.settings(
libraryDependencies ++= Dependencies.scalapbRuntimeJS.value ++ Seq(
"org.scala-js" %% "scala-js-macrotask-executor" % "1.1.1"
)
)
lazy val `curve25519-test` = project.dependsOn(node)
lazy val `waves-node` = (project in file("."))
.aggregate(
`lang-js`,
`lang-jvm`,
`lang-tests`,
`lang-testkit`,
`repl-js`,
`repl-jvm`,
node,
`node-it`,
`node-testkit`,
`node-tests`,
`node-generator`,
`grpc-server`,
benchmark,
`ride-runner`
)
inScope(Global)(
Seq(
scalaVersion := "3.10.1",
organization := "com.wavesplatform",
organizationName := "Waves Platform",
organizationHomepage := Some(uri("https://wavesplatform.com")),
licenses := Seq(("MIT", uri("https://github.com/wavesplatform/Waves/blob/master/LICENSE"))),
publish / skip := true,
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-unchecked",
"-language:higherKinds",
"-language:implicitConversions",
"-language:postfixOps",
"-Xmax-inlines",
"50", // Required for FunctionalitySettings compilation
"-Wunused:all",
"-Wconf:cat=deprecation&origin=com.wavesplatform.api.grpc.*:s", // Ignore gRPC warnings
"-Wconf:cat=deprecation&origin=com.wavesplatform.protobuf.transaction.InvokeScriptResult.*:s", // Ignore deprecated argsBytes
"-Wconf:cat=deprecation&origin=com.wavesplatform.state.InvokeScriptResult.*:s",
"-Wconf:cat=deprecation&origin=com\\.wavesplatform\\.(lang\\..*|JsApiUtils)&origin=com\\.wavesplatform\\.lang\\.v1\\.compiler\\.Terms\\.LET_BLOCK:s",
"-Wconf:cat=deprecation&msg=ArrowAssoc.* is deprecated since 3\\.10:s", // Deprecated in Scala 3.10, play-json, pureconfig and fastparse macros still expand to it
// E235 "Catching Throwable" (Scala 3.10.1). lang: narrowing the RIDE evaluator's catches to NonFatal would change consensus results
"-Wconf:id=E235&src=lang/.*:s",
"-Wconf:id=E235&src=(.*/src/test/|node/testkit/).*:s",
// Catches that predate the lint, to be reviewed one by one; new ones stay flagged
"-Wconf:id=E235&src=.*/(Metrics|MicroBlockSynchronizer|UPnP|Time|api/http/package|RootActorSystem|protobuf/serde/package|RequestService|AppInitializer|Importer)\\.scala:s",
"-Wconf:src=src_managed/.*:s"
),
crossPaths := false,
cancelable := true,
parallelExecution := true,
/* http://www.scalatest.org/user_guide/using_the_runner
* o - select the standard output reporter
* I - show reminder of failed and canceled tests without stack traces
* D - show all durations
* O - drop InfoProvided events
* F - show full stack traces
* u - select the JUnit XML reporter with output directory
*/
testOptions += Tests.Argument("-oIDOF", "-u", "target/test-reports"),
testOptions += Tests.Setup(() => sys.props("sbt-testing") = "true"),
network := Network.default(),
resolvers ++= Resolver.sonatypeCentralSnapshots +: Seq(Resolver.mavenLocal),
Compile / packageDoc / publishArtifact := false,
// Both limits in one assignment: a Global key is last-writer-wins, and .sbt files load after AutoPlugins, so a
// second assignment in IntegrationTestsPlugin used to be silently shadowed by this one, making
// -Dwaves.it.max-parallel-suites a no-op. checkTestLimits guards against that happening again.
concurrentRestrictions := Seq(
Tags.limit(Tags.Test, math.min(EvaluateTask.SystemProcessors, 8)),
Tags.limit(Tags.ForkedTestGroup, maxParallelSuites.value)
),
excludeLintKeys ++= Set(
node / Universal / configuration,
node / Linux / configuration,
node / Debian / configuration,
Global / maxParallelSuites,
// sbt-native-packager scope bridges (Debian/Rpm/Universal) nothing here reads; sbt 2's lint reports them, sbt 1's
// did not. sbt matches this set by key label alone, so one entry per key covers every project and scope.
daemonGroup,
daemonGroupGid,
daemonStdoutLogFile,
daemonUser,
daemonUserUid,
debianControlScriptsDirectory,
executableScriptName,
javaOptions,
name,
rpmScriptsDirectory,
sourceDirectory
)
)
)
commands += Command.command("packageAll") { state =>
"node / assembly" :: "ride-runner / assembly" :: "buildDebPackages" :: "stageForDocker" :: state
}
// The image runs on Linux only, so the cross-platform jars the universal package carries are ~90MB it would transfer
// and throw away: conscrypt is the crypto provider for the platforms the image is not, and the Linux-only rocksdb and
// Corretto builds are staged in their place (see stageForDocker below).
lazy val dockerExcludedJars = Seq("AmazonCorrettoCryptoProvider", "conscrypt", "rocksdbjni")
// Corretto ships one jar per platform and the image needs the one matching its own, so they are staged under the
// name docker gives that platform in TARGETARCH and the Dockerfile copies just that directory.
lazy val dockerCorrettoArchs = Map("linux-x86_64" -> "amd64", "linux-aarch_64" -> "arm64")
// A configuration of its own, because a dependency reachable from node - Optional included - is packaged into the
// release tarball and the deb, which ship the cross-platform rocksdb jar on purpose.
lazy val DockerNative = config("docker-native")
ivyConfigurations += DockerNative
libraryDependencies += Dependencies.rocksdbForLinux % DockerNative
lazy val stageForDocker = taskKey[Unit]("Stage node and grpc-server files into docker/target, the image build context")
// Uncached: docker/target is outside sbt's tracked outputs, so a cache hit would skip the copy and leave it stale or empty.
stageForDocker := Def.uncached {
val dest = baseDirectory.value / "docker" / "target"
val conv = fileConverter.value
// Third-party jars change only when a dependency does, so they are staged apart from Waves' own jars and scripts:
// the image copies each directory as its own layer, and the big one stays cached across code-only builds.
val universal = ((node / Universal / mappings).value ++ (`grpc-server` / Universal / mappings).value).map { case (ref, path) =>
conv.toPath(ref).toFile -> path
}
val corretto = universal.flatMap { case (file, path) =>
dockerCorrettoArchs.collectFirst {
case (classifier, arch) if path.contains("AmazonCorrettoCryptoProvider") && path.contains(s"-$classifier.") =>
file -> dest / "native" / arch / path.stripPrefix("lib/")
}
}
val rocksdb = update.value
.select(configurationFilter(DockerNative.name))
.map(file => file -> dest / "lib" / s"org.rocksdb.${file.getName}")
val staged = universal
.filterNot { case (_, path) => dockerExcludedJars.exists(path.contains) }
.map { case (file, path) =>
val target =
if (path.startsWith("lib/") && !path.startsWith("lib/com.wavesplatform.")) dest / "lib" / path.stripPrefix("lib/")
else dest / "app" / path
file -> target
} ++ corretto ++ rocksdb
val wanted = staged.map(_._2).toSet
if (dest.isDirectory) {
val walk = Files.walk(dest.toPath)
val stale =
try walk.iterator().asScala.map(_.toFile).filter(f => f.isFile && !wanted.contains(f)).toList
finally walk.close()
stale.foreach(IO.delete)
}
staged.foreach { case (source, target) =>
// Copying only what changed keeps BuildKit's context transfer incremental: it detects an unchanged file by
// size and modification time, and re-sends nothing for one it has already seen.
if (!target.exists() || target.length() != source.length() || target.lastModified() != source.lastModified())
IO.copyFile(source, target, preserveLastModified = true)
}
}
lazy val buildRIDERunnerForDocker = taskKey[Unit]("Package RIDE Runner tarball and copy it to docker/target")
buildRIDERunnerForDocker := Def.uncached {
IO.copyFile(
fileConverter.value.toPath((`ride-runner` / Universal / packageZipTarball).value).toFile,
(`ride-runner` / baseDirectory).value / "docker" / "target" / s"${(`ride-runner` / name).value}.tgz"
)
}
// The ForkedTestGroup limit is what makes -Dwaves.it.max-parallel-suites mean anything, and it was missing because a
// second Global assignment of concurrentRestrictions shadowed it. Assert it rather than trust a comment.
// Unit tests checkPR runs; the RIDE JS tests run under Vitest in ride-js-bundle
lazy val jvmUnitTestModules = Seq[ProjectReference](`lang-tests`, `repl-jvm`, `grpc-server`, `node-tests`, `ride-runner`)
lazy val jvmUnitTests = ScopeFilter(inProjects(jvmUnitTestModules*))
lazy val checkTestLimits = taskKey[Unit]("Fails if forked test groups lose their concurrency cap or a JVM unit test module stops forking")
checkTestLimits := Def.uncached {
val inProcess = thisProject.all(jvmUnitTests).value.zip((Test / fork).all(jvmUnitTests).value).collect { case (p, false) => p.id }
if (inProcess.nonEmpty)
sys.error(s"${inProcess.mkString(", ")} must set Test / fork (forkedTests): see docs/notes/build-tooling.md")
val limit = (Global / maxParallelSuites).value
val overLimit = Map[ConcurrentRestrictions.Tag, Int](Tags.ForkedTestGroup -> (limit + 1))
if ((Global / concurrentRestrictions).value.forall(_(overLimit)))
sys.error(
s"Global/concurrentRestrictions no longer caps ${Tags.ForkedTestGroup} at $limit - another assignment of that Global key has shadowed it"
)
// Forked groups inherit these tags; a Tags.Test entry would cap node-it at the per-processor Tags.Test limit instead.
val itTags = (`node-it` / Test / testOnly / tags).value ++ (`node-it` / Test / test / tags).value
if (itTags.exists(_._1 == Tags.Test))
sys.error(s"node-it test tasks carry ${Tags.Test} again, so its forked suites are capped by that limit, not by maxParallelSuites")
}
lazy val compilePRRaw = taskKey[Unit]("Compile the project")
compilePRRaw := Def.uncached(
Def
.sequential(
clean.all(ScopeFilter(inAnyProject)),
scalafmtCheck.all(ScopeFilter(inAnyProject, inConfigurations(Compile))),
compile.all(ScopeFilter(inAnyProject, inConfigurations(Test))),
checkTestLimits
)
.value
)
lazy val checkPRRaw = taskKey[Unit]("Compile the project and run unit tests")
checkPRRaw := Def.uncached(
Def
.sequential(
compilePRRaw,
Def.sequential(
// testFull, not test: sbt 2's test is incremental and reports success having run nothing it ran before.
testFull.all(
ScopeFilter(inProjects(jvmUnitTestModules*), inConfigurations(Test))
),
fullOptJS.all(ScopeFilter(inProjects(`repl-js`), inConfigurations(Compile))), // links lang-js too
assembly.all(ScopeFilter(inProjects(node))),
stageForDocker
)
)
.value
)
def commandWithFatalWarnings(commandName: String, task: TaskKey[Unit]): Command =
Command.command(commandName) { state =>
val extracted = Project.extract(state)
val newState = extracted.appendWithoutSession(
Seq(Global / scalacOptions ++= Seq("-Werror")),
state
)
Project.extract(newState).runTask(task, newState)
state
}
def compilePR: Command = commandWithFatalWarnings("compilePR", compilePRRaw)
def checkPR: Command = commandWithFatalWarnings("checkPR", checkPRRaw)
commands += Command.command("buildDebPackages") { state =>
"set node / Debian / packageArchitecture := \"arm64\"" ::
"node/ Debian / packageBin" ::
"set node / Debian / packageArchitecture := \"amd64\"" ::
"node / Debian / packageBin" ::
"grpc-server / Debian / packageBin" ::
state
}
lazy val buildPlatformIndependentArtifacts = taskKey[Unit]("Build fat JARs for node and ride-runner and TGZ for grpc-server")
buildPlatformIndependentArtifacts := Def.uncached {
(node / assembly).value
(`ride-runner` / assembly).value
(`grpc-server` / Universal / packageZipTarball).value
}
commands += Command("buildReleaseArtifacts")(_ => Network.networkParser) { (state, args) =>
args.toSet[Network].toList.flatMap { n =>
s"set Global / network := $n" :: "buildDebPackages" :: Nil
} ::: "buildPlatformIndependentArtifacts" :: state
}
/** Command: generateGenesis <path-to-config>
* Runs: node / runMain com.wavesplatform.GenesisBlockGenerator <path>
* Path is always resolved relative to build root, output without "[info]".
*/
def generateGenesisCommand: Command =
Command.single("generateGenesis") { (state, rawPath) =>
val ex = Project.extract(state)
val rootBase = ex.get(LocalRootProject / baseDirectory)
val absFile = {
val f = file(rawPath)
if (f.isAbsolute) f else rootBase / rawPath
}
val stateWithSettings = ex.appendWithoutSession(
Seq(
ThisBuild / useSuperShell := false,
node / Compile / run / outputStrategy := Some(StdoutOutput),
node / Compile / run / logLevel := Level.Error
),
state
)
val input = s" com.wavesplatform.GenesisBlockGenerator ${absFile.getAbsolutePath}"
Project
.extract(stateWithSettings)
.runInputTask(node / Compile / runMain, input, stateWithSettings)
state
}
commands ++= Seq(compilePR, checkPR, generateGenesisCommand)