forked from wavesplatform/Waves
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
279 lines (248 loc) · 9.75 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
import com.typesafe.sbt.packager.archetypes.TemplateWriter
import sbt.Keys.{sourceGenerators, _}
import sbt._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import sbt.internal.inc.ReflectUtilities
import sbtassembly.MergeStrategy
enablePlugins(JavaServerAppPackaging, JDebPackaging, SystemdPlugin, GitVersioning)
scalafmtOnCompile in ThisBuild := true
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, 14, 0)
val versionFile = (sourceManaged in Compile).value / "com" / "localplatform" / "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.localplatform
|
|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 := "local"
normalizedName := s"${name.value}${network.value.packageSuffix}"
git.useGitDescribe := true
git.uncommittedSignifier := Some("DIRTY")
logBuffered := false
inThisBuild(
Seq(
scalaVersion := "2.12.6",
organization := "com.localplatform",
crossPaths := false,
scalacOptions ++= Seq("-feature", "-deprecation", "-language:higherKinds", "-language:implicitConversions", "-Ywarn-unused:-implicits", "-Xlint")
))
resolvers += Resolver.bintrayRepo("ethereum", "maven")
fork in run := true
javaOptions in run ++= Seq(
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-modules=java.xml.bind"
)
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"local-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.localplatform.Application"),
publishArtifact in packageDoc := false,
publishArtifact in packageSrc := false,
sourceGenerators += versionSource
))
inConfig(Test)(
Seq(
logBuffered := false,
parallelExecution := false,
testOptions += Tests.Argument("-oIDOF", "-u", "target/test-reports"),
testOptions += Tests.Setup(_ => sys.props("sbt-testing") = "true")
))
inConfig(Linux)(
Seq(
maintainer := "localplatform.com",
packageSummary := "Local node",
packageDescription := "Local node"
))
bashScriptExtraDefines += s"""addJava "-Dlocal.directory=/var/lib/${normalizedName.value}""""
val linuxScriptPattern = "bin/(.+)".r
val batScriptPattern = "bin/([^.]+)\\.bat".r
inConfig(Universal)(
Seq(
mappings += (baseDirectory.value / s"local-${network.value}.conf" -> "doc/local.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""")
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), inConfigurations(Test))).value
compile.all(ScopeFilter(inProjects(generator, benchmark), inConfigurations(Test))).value
}
}
lazy val lang =
crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.settings(
version := "0.0.1",
// the following line forces scala version across all dependencies
scalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(true))),
test in assembly := {},
addCompilerPlugin(Dependencies.kindProjector),
libraryDependencies ++=
Dependencies.cats ++
Dependencies.fp ++
Dependencies.scalacheck ++
Dependencies.scorex ++
Dependencies.scalatest ++
Dependencies.scalactic ++
Dependencies.monix.value ++
Dependencies.scodec.value ++
Dependencies.fastparse.value,
resolvers += Resolver.bintrayIvyRepo("portable-scala", "sbt-plugins")
)
.jsSettings(
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
}
)
.jvmSettings(
libraryDependencies ++= Seq(
"org.scala-js" %% "scalajs-stubs" % "0.6.22" % "provided"
) ++ Dependencies.logging.map(_ % "test") // scrypto logs an error if a signature verification was failed
)
lazy val langJS = lang.js
lazy val langJVM = lang.jvm
lazy val node = project
.in(file("."))
.settings(
addCompilerPlugin(Dependencies.kindProjector),
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
)
.dependsOn(langJVM)
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")