forked from scalapb/ScalaPB
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
251 lines (222 loc) · 8.67 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
import ReleaseTransformations._
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
val Scala211 = "2.11.12"
scalaVersion in ThisBuild := Scala211
crossScalaVersions in ThisBuild := Seq("2.10.6", Scala211, "2.12.4")
scalacOptions in ThisBuild ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 11 => List("-target:jvm-1.7")
case _ => Nil
}
}
javacOptions in ThisBuild ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 11 => List("-target", "7", "-source", "7")
case _ => Nil
}
}
organization in ThisBuild := "com.thesamet.scalapb"
resolvers in ThisBuild +=
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
releaseCrossBuild := true
releasePublishArtifactsAction := PgpKeys.publishSigned.value
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommandAndRemaining(s";++${Scala211};runtimeNative/publishSigned"),
ReleaseStep(action = Command.process("publishSigned", _), enableCrossBuild = true),
setNextVersion,
commitNextVersion,
pushChanges,
ReleaseStep(action = Command.process("sonatypeReleaseAll", _), enableCrossBuild = true)
)
lazy val root =
project.in(file("."))
.settings(
publishArtifact := false,
publish := {},
publishLocal := {}
).aggregate(
runtimeJS,
runtimeJVM,
grpcRuntime,
compilerPlugin,
compilerPluginShaded,
proptest,
scalapbc)
lazy val runtime = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Full).in(file("scalapb-runtime"))
.settings(
name := "scalapb-runtime",
libraryDependencies ++= Seq(
"com.thesamet.scalapb" %%% "lenses" % "0.7.0-test2",
"com.lihaoyi" %%% "fastparse" % "1.0.0",
"com.lihaoyi" %%% "utest" % "0.6.4" % "test"
),
testFrameworks += new TestFramework("utest.runner.Framework"),
unmanagedResourceDirectories in Compile += baseDirectory.value / "../../protobuf"
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies ++= Seq(
"com.thesamet.scalapb" %%% "protobuf-runtime-scala" % "0.7.0.1"
),
(unmanagedSourceDirectories in Compile) += baseDirectory.value / ".." / "non-jvm" / "src" / "main" / "scala"
)
.jvmSettings(
// Add JVM-specific settings here
libraryDependencies ++= Seq(
"com.google.protobuf" % "protobuf-java" % protobufVersion,
"org.scalacheck" %% "scalacheck" % "1.13.5" % "test",
"org.scalatest" %%% "scalatest" % "3.0.5" % "test"
)
)
.jsSettings(
// Add JS-specific settings here
scalacOptions += {
val a = (baseDirectory in LocalRootProject).value.toURI.toString
val g = "https://raw.githubusercontent.com/scalapb/ScalaPB/" + sys.process.Process("git rev-parse HEAD").lines_!.head
s"-P:scalajs:mapSourceURI:$a->$g/"
},
unmanagedResourceDirectories in Compile += baseDirectory.value / "../../third_party"
)
.nativeSettings(
nativeLinkStubs := true // for utest
)
lazy val runtimeJVM = runtime.jvm
lazy val runtimeJS = runtime.js
lazy val runtimeNative = runtime.native
val grpcVersion = "1.11.0"
lazy val grpcRuntime = project.in(file("scalapb-runtime-grpc"))
.dependsOn(runtimeJVM)
.settings(
name := "scalapb-runtime-grpc",
libraryDependencies ++= Seq(
"io.grpc" % "grpc-stub" % grpcVersion,
"io.grpc" % "grpc-protobuf" % grpcVersion,
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"org.mockito" % "mockito-core" % "2.10.0" % "test"
)
)
val shadeTarget = settingKey[String]("Target to use when shading")
shadeTarget in ThisBuild := s"scalapbshade.v${version.value.replaceAll("[.-]","_")}.@0"
lazy val compilerPlugin = project.in(file("compiler-plugin"))
.settings(
sourceGenerators in Compile += Def.task {
val file = (sourceManaged in Compile).value / "scalapb" / "compiler" / "Version.scala"
IO.write(file,
s"""package scalapb.compiler
|object Version {
| val scalapbVersion = "${version.value}"
| val protobufVersion = "${protobufVersion}"
| val grpcJavaVersion = "${grpcVersion}"
|}""".stripMargin)
Seq(file)
}.taskValue,
sourceGenerators in Compile += Def.task {
val src = baseDirectory.value / ".." / "scalapb-runtime" / "shared" / "src" / "main" / "scala" / "scalapb" / "Encoding.scala"
val dest = (sourceManaged in Compile).value / "scalapb" / "compiler" / "internal" /"Encoding.scala"
val s = IO.read(src).replace("package scalapb", "package scalapb.internal")
IO.write(dest, s"// DO NOT EDIT. Copy of $src\n\n" + s)
Seq(dest)
}.taskValue,
libraryDependencies ++= Seq(
"com.thesamet.scalapb" %% "protoc-bridge" % "0.7.3",
"org.scalatest" %% "scalatest" % "3.0.5" % "test"
)
)
// Until https://github.com/scalapb/ScalaPB/issues/150 is fixed, we are
// publishing compiler-plugin bundled with protoc-bridge, and linked against
// shaded protobuf. This is a workaround - this artifact will be removed in
// the future.
lazy val compilerPluginShaded = project.in(file("compiler-plugin-shaded"))
.dependsOn(compilerPlugin)
.settings(
name := "compilerplugin-shaded",
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("scalapb.options.Scalapb**" -> shadeTarget.value).inProject,
ShadeRule.rename("com.google.**" -> shadeTarget.value).inAll
),
assemblyExcludedJars in assembly := {
val toInclude = Seq(
"protobuf-java",
"protoc-bridge"
)
(fullClasspath in assembly).value.filterNot {
c => toInclude.exists(prefix => c.data.getName.startsWith(prefix))
}
},
artifact in (Compile, packageBin) := (artifact in (Compile, assembly)).value,
addArtifact(artifact in (Compile, packageBin), assembly),
pomPostProcess := { (node: scala.xml.Node) =>
new scala.xml.transform.RuleTransformer(new scala.xml.transform.RewriteRule {
override def transform(node: scala.xml.Node): scala.xml.NodeSeq = node match {
case e: scala.xml.Elem if e.label == "dependency" && e.child.exists(child => child.label == "artifactId" && child.text.startsWith("compilerplugin")) =>
scala.xml.Comment(s"compilerplugin has been removed.")
case _ => node
}
}).transform(node).head
}
)
lazy val scalapbc = project.in(file("scalapbc"))
.dependsOn(compilerPlugin)
lazy val proptest = project.in(file("proptest"))
.dependsOn(runtimeJVM, grpcRuntime, compilerPlugin)
.configs( ShortTest )
.settings( inConfig(ShortTest)(Defaults.testTasks): _*)
.settings(
publishArtifact := false,
publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo"))),
libraryDependencies ++= Seq(
"com.github.os72" % "protoc-jar" % "3.5.1.1",
"com.google.protobuf" % "protobuf-java" % protobufVersion,
"io.grpc" % "grpc-netty" % grpcVersion % "test",
"io.grpc" % "grpc-protobuf" % grpcVersion % "test",
"com.thesamet.scalapb" %% "lenses" % "0.7.0-test2",
"org.scalacheck" %% "scalacheck" % "1.13.5" % "test",
"org.scalatest" %% "scalatest" % "3.0.5" % "test"
),
scalacOptions in Compile ++= Seq("-Xmax-classfile-name", "128"),
libraryDependencies += { "org.scala-lang" % "scala-compiler" % scalaVersion.value },
testOptions += Tests.Argument(),
fork in Test := false,
testOptions in ShortTest += Tests.Argument(
// verbosity specified because of ScalaCheck #108.
"-verbosity", "3",
"-minSuccessfulTests", "10")
)
lazy val ShortTest = config("short") extend(Test)
val protobufVersion = "3.5.1"
// For e2e test
val sbtPluginVersion = "0.99.18"
def genVersionFile(out: File, version: String): File = {
out.mkdirs()
val f = out / "Version.scala"
val w = new java.io.FileOutputStream(f)
w.write(s"""|// Generated by ScalaPB's build.sbt.
|
|package scalapb
|
|object Version {
| val sbtPluginVersion = "$sbtPluginVersion"
| val scalapbVersion = "$version"
|}
|""".stripMargin.getBytes("UTF-8"))
w.close()
f
}
val createVersionFile = TaskKey[Unit](
"create-version-file", "Creates a file with the project version to be used by e2e.")
createVersionFile := {
val v = (version in Compile).value
val log = streams.value.log
val base = baseDirectory.value
val f1 = genVersionFile(base / "e2e/project/project", v)
log.info(s"Created $f1")
val f2 = genVersionFile(base / "e2e/project/", v)
log.info(s"Created $f2")
}