This repository was archived by the owner on May 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.sbt
More file actions
248 lines (206 loc) · 7.35 KB
/
build.sbt
File metadata and controls
248 lines (206 loc) · 7.35 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
import sbt._
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scala.collection.immutable.Seq
import scalariform.formatter.preferences.AlignSingleLineCaseStatements
import ReleaseTransformations._
import _root_.bintray.BintrayExt
lazy val binaryName = SettingKey[String]("binary-name")
lazy val cSource = SettingKey[File]("c-source")
lazy val build = inputKey[Seq[(BuildInfo, Seq[File])]]("build")
lazy val buildDockerImage = inputKey[Seq[String]]("buildDockerImage")
lazy val buildAll = TaskKey[Seq[(BuildInfo, Seq[File])]]("buildAll")
lazy val buildAllDockerImages = TaskKey[Seq[String]]("buildAllDockerImages")
lazy val publishToBintray = TaskKey[Unit]("publishToBintray")
// FIXME shadow sbt-scalajs' crossProject and CrossType until Scala.js 1.0.0 is released
import sbtcrossproject.{ crossProject, CrossType }
lazy val Names = new {
val rp = "rp"
}
lazy val Versions = new {
val argonaut = "6.2.1"
val fastparse = "1.0.0"
val nodejs = "0.4.2"
val scala = "2.11.12"
val scalaz = "7.2.16"
val scopt = "3.7.0"
val slogging = "0.6.0"
val utest = "0.5.3"
}
ThisBuild / scalaVersion := Versions.scala
ThisBuild / organization := "com.lightbend.rp"
ThisBuild / organizationName := "Lightbend, Inc."
ThisBuild / startYear := Some(2017)
ThisBuild / licenses += ("Apache-2.0", new URL("https://www.apache.org/licenses/LICENSE-2.0.txt"))
lazy val Platform = new {
val isWindows =
sys
.props
.get("os.name")
.map(_.toLowerCase)
.exists(_.contains("win"))
}
lazy val commonSettings = Seq(
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "utest" % Versions.utest % "test"
),
ScalariformKeys.preferences :=
ScalariformKeys.preferences.value
.setPreference(AlignSingleLineCaseStatements, true)
.setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 100),
nativeLinkStubs := true,
testFrameworks += new TestFramework("utest.runner.Framework"),
cSource in Compile := sourceDirectory.value / "main" / "c"
)
lazy val root = (project in file("."))
.aggregate(cliJs, cliNative)
.settings(
name := "reactive-cli-root",
TaskKey[Unit]("ensureRelease") := {
if (Properties.nativeMode != "release") {
sys.error("To release, you must launch sbt with -Dbuild.nativeMode=release")
}
},
releaseProcess := Seq[ReleaseStep](
inquireVersions,
runClean,
releaseStepCommand("ensureRelease"),
releaseStepCommand("update"),
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommand("compile:publishToBintray"),
setNextVersion,
commitNextVersion,
pushChanges
),
buildDockerImage in Compile :=
BuildInfo.buildDockerImage(BuildInfo.builds.evaluated, target.value, streams.value.log),
buildAllDockerImages in Compile :=
BuildInfo.buildDockerImage(BuildInfo.Builds, target.value, streams.value.log),
build in Compile :=
BuildInfo.build(BuildInfo.builds.evaluated, target.value, baseDirectory.value, version.value, streams.value.log),
buildAll in Compile :=
BuildInfo.build(BuildInfo.Builds, target.value, baseDirectory.value, version.value, streams.value.log),
publishToBintray in Compile := {
val info = (buildAll in Compile).value
val log = streams.value.log
for {
(b, files) <- info
file <- files
} {
b.target match {
case tgt @ DebBuildTarget(distributions, components, _, _) =>
BintrayExt.publishDeb(
file,
distributions,
components,
tgt.architecture,
version.value,
bintrayCredentialsFile.value,
log)
case RpmBuildTarget(_, _, _) =>
BintrayExt.publishRpm(file, version.value, bintrayCredentialsFile.value, log)
case TarGzSelfContainedExecutableBuildTarget(_) =>
BintrayExt.publishTarGz(file, version.value, bintrayCredentialsFile.value, log)
}
}
}
)
lazy val cli = crossProject(JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("cli"))
.enablePlugins(AutomateHeaderPlugin)
.settings(
commonSettings,
name := "reactive-cli",
libraryDependencies ++= Seq(
"com.github.scopt" %%% "scopt" % Versions.scopt,
"io.argonaut" %%% "argonaut" % Versions.argonaut,
"biz.enef" %%% "slogging" % Versions.slogging,
"org.scalaz" %%% "scalaz-core" % Versions.scalaz,
"com.lihaoyi" %%% "fastparse" % Versions.fastparse
),
sourceGenerators in Compile += Def.task {
val versionFile = (sourceManaged in Compile).value / "ProgramVersion.scala"
val versionSource =
"""|package com.lightbend.rp.reactivecli
|
|object ProgramVersion {
| val current = "%s"
|}
|"""
.stripMargin
.format(version.value)
.replaceAllLiterally("\n", System.lineSeparator)
IO.write(versionFile, versionSource)
Seq(versionFile)
}
)
.nativeSettings(
nativeMode := Properties.nativeMode,
nativeGC := "none",
nativeLinkingOptions := {
val dynamicLinkerOptions =
Properties
.dynamicLinker
.toVector
.map(dl => s"-Wl,--dynamic-linker=$dl")
dynamicLinkerOptions ++
Seq("-lcurl") ++
sys.props.get("nativeLinkingOptions").fold(Seq.empty[String])(_.split(" ").toVector)
},
Keys.`package` in Compile := {
val cliOut = (nativeLink in Compile).value
val outputDirectory = target.value / "output"
IO.deleteFilesEmptyDirs(Seq(outputDirectory))
IO.createDirectory(outputDirectory / "lib")
IO.createDirectory(outputDirectory / "bin")
IO.copyFile(cliOut, outputDirectory / "bin" / Names.rp)
AdditionalIO.setExecutable(outputDirectory / "bin" / Names.rp)
(outputDirectory / Names.rp).setExecutable(true)
streams.value.log.info(s"Created files in $outputDirectory")
outputDirectory
}
)
.jsSettings(
scalaJSUseMainModuleInitializer := true,
scalaJSModuleKind := ModuleKind.CommonJSModule,
libraryDependencies ++= Seq(
"io.scalajs" %%% "nodejs-lts" % Versions.nodejs
),
Keys.`package` in Compile := {
val output = (fullOptJS in Compile).value.data
val entry =
s"""|__ScalaJSEnv = {
| exitFunction: function(status) {
| process.exit(status);
| }
|};
|
|"""
.stripMargin
.replaceAllLiterally("\n", System.lineSeparator)
val targetDir = (target in Compile).value
val entryFile = targetDir / "rp.js"
IO.write(entryFile, entry + IO.read(output))
entryFile
}
)
lazy val cliJs = cli.js
lazy val cliNative = cli.native
lazy val integrationTest = (project in file("integration-test"))
.enablePlugins(SbtPlugin)
.settings(
publish / skip := true,
scalaVersion := "2.12.8",
// pass in -Ddeckhand.openshift to run scripted test with -Ddeckhand.openshift
scriptedLaunchOpts := { scriptedLaunchOpts.value ++
Seq(
"-Xmx1024M",
"-Dplugin.version=" + version.value,
"-Dreactiveclipath=" + (cliNative / crossTarget).value,
) ++
sys.props.get("deckhand.openshift").toList.map(_ => "-Ddeckhand.openshift")
},
scriptedBufferLog := false
)