-
Notifications
You must be signed in to change notification settings - Fork 422
/
Copy pathbuild.sbt
344 lines (306 loc) · 12.2 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
import com.typesafe.sbt.packager.archetypes.TemplateWriter
import sbt.Keys.{sourceGenerators, _}
import sbt._
import sbt.internal.inc.ReflectUtilities
import sbtassembly.MergeStrategy
import sbtcrossproject.CrossPlugin.autoImport.crossProject
enablePlugins(JavaServerAppPackaging, JDebPackaging, SystemdPlugin, GitVersioning)
scalafmtOnCompile in ThisBuild := true
Global / cancelable := true
Global / coverageExcludedPackages := ".*"
val versionSource = Def.task {
// WARNING!!!
// Please, update the fallback version every major and minor releases.
// This version is used then building from sources without Git repository
// In case of not updating the version nodes build from headless sources will fail to connect to newer versions
val FallbackVersion = (0, 16, 3)
val versionFile = (sourceManaged in Compile).value / "com" / "wavesplatform" / "Version.scala"
val versionExtractor = """(\d+)\.(\d+)\.(\d+).*""".r
val (major, minor, patch) = version.value match {
case versionExtractor(ma, mi, pa) => (ma.toInt, mi.toInt, pa.toInt)
case _ => FallbackVersion
}
IO.write(
versionFile,
s"""package com.wavesplatform
|
|object Version {
| val VersionString = "${version.value}"
| val VersionTuple = ($major, $minor, $patch)
|}
|""".stripMargin
)
Seq(versionFile)
}
val network = SettingKey[Network]("network")
network := { Network(sys.props.get("network")) }
name := "waves"
normalizedName := s"${name.value}${network.value.packageSuffix}"
git.useGitDescribe := true
git.uncommittedSignifier := Some("DIRTY")
logBuffered := false
inThisBuild(
Seq(
scalaVersion := "2.12.8",
organization := "com.wavesplatform",
crossPaths := false,
scalacOptions ++= Seq("-feature", "-deprecation", "-language:higherKinds", "-language:implicitConversions", "-Ywarn-unused:-implicits", "-Xlint")
))
resolvers ++= Seq(
Resolver.bintrayRepo("ethereum", "maven"),
Resolver.bintrayRepo("dnvriend", "maven"),
Resolver.sbtPluginRepo("releases")
)
val java9Options = Seq(
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-modules=java.xml.bind",
"--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED"
)
fork in run := true
javaOptions in run ++= java9Options
Test / fork := true
Test / javaOptions ++= java9Options
Jmh / javaOptions ++= java9Options
val aopMerge: MergeStrategy = new MergeStrategy {
val name = "aopMerge"
import scala.xml._
import scala.xml.dtd._
def apply(tempDir: File, path: String, files: Seq[File]): Either[String, Seq[(File, String)]] = {
val dt = DocType("aspectj", PublicID("-//AspectJ//DTD//EN", "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"), Nil)
val file = MergeStrategy.createMergeTarget(tempDir, path)
val xmls: Seq[Elem] = files.map(XML.loadFile)
val aspectsChildren: Seq[Node] = xmls.flatMap(_ \\ "aspectj" \ "aspects" \ "_")
val weaverChildren: Seq[Node] = xmls.flatMap(_ \\ "aspectj" \ "weaver" \ "_")
val options: String = xmls.map(x => (x \\ "aspectj" \ "weaver" \ "@options").text).mkString(" ").trim
val weaverAttr = if (options.isEmpty) Null else new UnprefixedAttribute("options", options, Null)
val aspects = new Elem(null, "aspects", Null, TopScope, false, aspectsChildren: _*)
val weaver = new Elem(null, "weaver", weaverAttr, TopScope, false, weaverChildren: _*)
val aspectj = new Elem(null, "aspectj", Null, TopScope, false, aspects, weaver)
XML.save(file.toString, aspectj, "UTF-8", xmlDecl = false, dt)
IO.append(file, IO.Newline.getBytes(IO.defaultCharset))
Right(Seq(file -> path))
}
}
inTask(assembly)(
Seq(
test := {},
assemblyJarName := s"waves-all-${version.value}.jar",
assemblyMergeStrategy := {
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat
case PathList("META-INF", "aop.xml") => aopMerge
case other => (assemblyMergeStrategy in assembly).value(other)
}
))
inConfig(Compile)(
Seq(
mainClass := Some("com.wavesplatform.Application"),
publishArtifact in packageDoc := false,
publishArtifact in packageSrc := false,
sourceGenerators += versionSource
))
inConfig(Test)(
Seq(
logBuffered := false,
parallelExecution := false,
testListeners := Seq.empty, // Fix for doubled test reports
testOptions += Tests.Argument("-oIDOF", "-u", "target/test-reports"),
testOptions += Tests.Setup(_ => sys.props("sbt-testing") = "true")
))
inConfig(Linux)(
Seq(
maintainer := "wavesplatform.com",
packageSummary := "Waves node",
packageDescription := "Waves node"
))
bashScriptExtraDefines += s"""addJava "-Dwaves.directory=/var/lib/${normalizedName.value}""""
val linuxScriptPattern = "bin/(.+)".r
val batScriptPattern = "bin/([^.]+)\\.bat".r
inConfig(Universal)(
Seq(
mappings += (baseDirectory.value / s"waves-${network.value}.conf" -> "doc/waves.conf.sample"),
mappings := {
val scriptSuffix = network.value.packageSuffix
mappings.value.map {
case m @ (file, batScriptPattern(script)) =>
if (script.endsWith(scriptSuffix)) m else (file, s"bin/$script$scriptSuffix.bat")
case m @ (file, linuxScriptPattern(script)) =>
if (script.endsWith(scriptSuffix)) m else (file, s"bin/$script$scriptSuffix")
case other => other
}
},
javaOptions ++= Seq(
// -J prefix is required by the bash script
"-J-server",
// JVM memory tuning for 2g ram
"-J-Xms128m",
"-J-Xmx2g",
"-J-XX:+ExitOnOutOfMemoryError",
// Java 9 support
"-J-XX:+IgnoreUnrecognizedVMOptions",
"-J--add-modules=java.xml.bind",
// from https://groups.google.com/d/msg/akka-user/9s4Yl7aEz3E/zfxmdc0cGQAJ
"-J-XX:+UseG1GC",
"-J-XX:+UseNUMA",
"-J-XX:+AlwaysPreTouch",
// probably can't use these with jstack and others tools
"-J-XX:+PerfDisableSharedMem",
"-J-XX:+ParallelRefProcEnabled",
"-J-XX:+UseStringDeduplication"
)
))
val packageSource = Def.setting {
sourceDirectory.value / "package"
}
val upstartScript = Def.task {
val src = packageSource.value / "upstart.conf"
val dest = (target in Debian).value / "upstart" / s"${packageName.value}.conf"
val result = TemplateWriter.generateScript(src.toURI.toURL, linuxScriptReplacements.value)
IO.write(dest, result)
dest
}
linuxPackageMappings ++= Seq(
(upstartScript.value, s"/etc/init/${packageName.value}.conf")
).map(packageMapping(_).withConfig().withPerms("644"))
linuxScriptReplacements += "detect-loader" ->
"""is_systemd() {
| which systemctl >/dev/null 2>&1 && \
| systemctl | grep -- -\.mount >/dev/null 2>&1
|}
|is_upstart() {
| /sbin/init --version | grep upstart >/dev/null 2>&1
|}
|""".stripMargin
inConfig(Debian)(
Seq(
linuxStartScriptTemplate := (packageSource.value / "systemd.service").toURI.toURL,
debianPackageDependencies += "java8-runtime-headless",
serviceAutostart := false,
maintainerScripts := maintainerScriptsFromDirectory(packageSource.value / "debian", Seq("preinst", "postinst", "postrm", "prerm"))
))
commands += Command.command("packageAll") { state =>
"clean" :: "assembly" :: "debian:packageBin" :: state
}
// https://stackoverflow.com/a/48592704/4050580
def allProjects: List[ProjectReference] = ReflectUtilities.allVals[Project](this).values.toList map { p =>
p: ProjectReference
}
addCommandAlias(
"checkPR",
""";
|set scalacOptions in ThisBuild ++= Seq("-Xfatal-warnings");
|Global / checkPRRaw;
|set scalacOptions in ThisBuild -= "-Xfatal-warnings";
""".stripMargin
)
lazy val checkPRRaw = taskKey[Unit]("Build a project and run unit tests")
checkPRRaw in Global := {
try {
clean.all(ScopeFilter(inProjects(allProjects: _*), inConfigurations(Compile))).value
} finally {
test.all(ScopeFilter(inProjects(langJVM, node, commonJVM), inConfigurations(Test))).value
(langJS / Compile / fastOptJS).value
compile.all(ScopeFilter(inProjects(generator, benchmark), inConfigurations(Test))).value
}
}
lazy val common = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.settings(
libraryDependencies ++= Dependencies.scalatest
)
lazy val commonJS = common.js
lazy val commonJVM = common.jvm
lazy val lang =
crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.settings(
version := "1.0.0",
coverageExcludedPackages := ".*",
// the following line forces scala version across all dependencies
scalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(true))),
test in assembly := {},
addCompilerPlugin(Dependencies.kindProjector),
addCompilerPlugin(Dependencies.betterFor),
libraryDependencies ++=
Dependencies.cats ++
Dependencies.fp ++
Dependencies.scalacheck ++
Dependencies.scorex ++
Dependencies.scalatest ++
Dependencies.scalactic ++
Dependencies.monix.value ++
Dependencies.fastparse.value,
resolvers += Resolver.bintrayIvyRepo("portable-scala", "sbt-plugins"),
resolvers += Resolver.sbtPluginRepo("releases")
)
.jsSettings(
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
},
libraryDependencies ++= Seq(
"org.rudogma" %%% "supertagged" % "1.4",
"com.chuusai" %%% "shapeless" % "2.3.3"
)
)
.jvmSettings(
coverageExcludedPackages := "",
publishMavenStyle := true,
credentials += Credentials(Path.userHome / ".sbt" / ".credentials"),
publishTo := Some("Sonatype Nexus" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"),
name := "RIDE Compiler",
normalizedName := "lang",
description := "The RIDE smart contract language compiler",
homepage := Some(url("https://docs.wavesplatform.com/en/technical-details/waves-contracts-language-description/maven-compiler-package.html")),
licenses := Seq(("MIT", url("https://github.com/wavesplatform/Waves/blob/master/LICENSE"))),
organization := "com.wavesplatform",
organizationName := "Waves Platform",
organizationHomepage := Some(url("https://wavesplatform.com")),
scmInfo := Some(ScmInfo(url("https://github.com/wavesplatform/Waves"), "[email protected]:wavesplatform/Waves.git", None)),
developers := List(Developer("petermz", "Peter Zhelezniakov", "[email protected]", url("https://wavesplatform.com"))),
libraryDependencies ++= Dependencies.meta ++
Seq(
"org.scala-js" %% "scalajs-stubs" % "1.0.0-RC1" % "provided",
"com.github.spullara.mustache.java" % "compiler" % "0.9.5"
) ++ Dependencies.logging.map(_ % "test") // scrypto logs an error if a signature verification was failed
)
lazy val langJS = lang.js.dependsOn(commonJS)
lazy val langJVM = lang.jvm.dependsOn(commonJVM)
lazy val node = project
.in(file("."))
.settings(
addCompilerPlugin(Dependencies.kindProjector),
coverageExcludedPackages := "",
libraryDependencies ++=
Dependencies.network ++
Dependencies.db ++
Dependencies.http ++
Dependencies.akka ++
Dependencies.serialization ++
Dependencies.testKit.map(_ % "test") ++
Dependencies.logging ++
Dependencies.matcher ++
Dependencies.metrics ++
Dependencies.fp ++
Dependencies.meta ++
Dependencies.ficus ++
Dependencies.scorex ++
Dependencies.commons_net ++
Dependencies.monix.value,
dependencyOverrides ++= Seq(
Dependencies.AkkaActor,
Dependencies.AkkaStream,
Dependencies.AkkaHTTP
)
)
.dependsOn(langJVM, commonJVM)
lazy val discovery = project
lazy val it = project
.dependsOn(node)
lazy val generator = project
.dependsOn(it)
.settings(libraryDependencies += "com.github.scopt" %% "scopt" % "3.6.0")
lazy val benchmark = project
.enablePlugins(JmhPlugin)
.dependsOn(node % "compile->compile;test->test", langJVM % "compile->compile;test->test")
lazy val dexgenerator = project
.dependsOn(it)
.settings(libraryDependencies += "com.github.scopt" %% "scopt" % "3.6.0")