-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sbt
247 lines (232 loc) · 7.59 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
import scalapb.compiler.Version._
import sbtrelease.ReleaseStateTransformations._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
val Scala212 = "2.12.20"
val argonautVersion = settingKey[String]("")
val scalapbJsonCommonVersion = settingKey[String]("")
val tagName = Def.setting {
s"v${if (releaseUseGlobalVersion.value) (ThisBuild / version).value else version.value}"
}
val tagOrHash = Def.setting {
if (isSnapshot.value) sys.process.Process("git rev-parse HEAD").lineStream_!.head
else tagName.value
}
val unusedWarnings = Seq("-Ywarn-unused:imports")
lazy val macros = project
.in(file("macros"))
.settings(
commonSettings,
name := UpdateReadme.scalapbArgonautMacrosName,
libraryDependencies ++= Seq(
"io.github.scalapb-json" %%% "scalapb-json-macros" % scalapbJsonCommonVersion.value,
),
)
.dependsOn(
scalapbArgonautJVM,
)
lazy val tests = crossProject(JVMPlatform)
.in(file("tests"))
.settings(
commonSettings,
noPublish,
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.19" % "test",
)
.configure(_ dependsOn macros)
.dependsOn(
scalapbArgonaut % "test->test"
)
lazy val testsJVM = tests.jvm
val scalapbScala3Sources = Def.setting(
scalaBinaryVersion.value match {
case "2.12" =>
false
case _ =>
true
}
)
val scalapbArgonaut = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("core"))
.enablePlugins(BuildInfoPlugin)
.settings(
commonSettings,
name := UpdateReadme.scalapbArgonautName,
(Compile / packageSrc / mappings) ++= (Compile / managedSources).value.map { f =>
// https://github.com/sbt/sbt-buildinfo/blob/v0.7.0/src/main/scala/sbtbuildinfo/BuildInfoPlugin.scala#L58
val buildInfoDir = "sbt-buildinfo"
val path = if (f.getAbsolutePath.contains(buildInfoDir)) {
(file(buildInfoPackage.value) / f
.relativeTo((Compile / sourceManaged).value / buildInfoDir)
.get
.getPath).getPath
} else {
f.relativeTo((Compile / sourceManaged).value).get.getPath
}
(f, path)
},
buildInfoPackage := "scalapb_argonaut",
buildInfoObject := "ScalapbArgonautBuildInfo",
buildInfoKeys := Seq[BuildInfoKey](
"scalapbVersion" -> scalapbVersion,
argonautVersion,
scalapbJsonCommonVersion,
scalaVersion,
version
)
)
.jvmSettings(
(Test / PB.targets) ++= Seq[protocbridge.Target](
PB.gens.java -> (Test / sourceManaged).value,
scalapb.gen(
javaConversions = true,
scala3Sources = scalapbScala3Sources.value
) -> (Test / sourceManaged).value
),
libraryDependencies ++= Seq(
"com.github.scalaprops" %%% "scalaprops-shapeless" % "0.6.0" % "test",
"com.google.protobuf" % "protobuf-java-util" % "3.25.5" % "test",
"com.google.protobuf" % "protobuf-java" % "3.25.5" % "protobuf"
)
)
.jsSettings(
buildInfoKeys ++= Seq[BuildInfoKey](
"scalajsVersion" -> scalaJSVersion
),
scalacOptions += {
val a = (LocalRootProject / baseDirectory).value.toURI.toString
val g = "https://raw.githubusercontent.com/scalapb-json/scalapb-argonaut/" + tagOrHash.value
if (scalaBinaryVersion.value == "3") {
"-scalajs-mapSourceURI:$a->$g/"
} else {
"-P:scalajs:mapSourceURI:$a->$g/"
}
},
)
.platformsSettings(JVMPlatform, JSPlatform)(
Seq(Compile, Test).map { x =>
x / unmanagedSourceDirectories += {
baseDirectory.value.getParentFile / "jvm-js" / "src" / Defaults.nameForSrc(
x.name
) / "scala",
}
},
)
.platformsSettings(JSPlatform, NativePlatform)(
(Test / PB.targets) ++= Seq[protocbridge.Target](
scalapb.gen(
javaConversions = false,
scala3Sources = scalapbScala3Sources.value
) -> (Test / sourceManaged).value
)
)
commonSettings
val noPublish = Seq(
PgpKeys.publishLocalSigned := {},
PgpKeys.publishSigned := {},
publishLocal := {},
publish := {},
Compile / publishArtifact := false
)
noPublish
lazy val commonSettings = Def.settings(
scalapropsCoreSettings,
(Compile / unmanagedResources) += (LocalRootProject / baseDirectory).value / "LICENSE.txt",
scalaVersion := Scala212,
crossScalaVersions := Seq(Scala212, "2.13.15", "3.3.4"),
scalacOptions ++= {
if (scalaBinaryVersion.value == "3") {
Nil
} else {
unusedWarnings ++ Seq(
"-Xsource:3"
)
}
},
Seq(Compile, Test).flatMap(c => c / console / scalacOptions --= unusedWarnings),
scalacOptions ++= Seq("-feature", "-deprecation", "-language:existentials"),
description := "Json/Protobuf convertors for ScalaPB",
licenses += ("MIT", url("https://opensource.org/licenses/MIT")),
organization := "io.github.scalapb-json",
Project.inConfig(Test)(sbtprotoc.ProtocPlugin.protobufConfigSettings),
Compile / PB.targets := Nil,
(Test / PB.protoSources) := Seq(baseDirectory.value.getParentFile / "shared/src/test/protobuf"),
scalapbJsonCommonVersion := "0.10.0",
argonautVersion := "6.3.10",
libraryDependencies ++= Seq(
"com.github.scalaprops" %%% "scalaprops" % "0.9.1" % "test",
"io.github.scalapb-json" %%% "scalapb-json-common" % scalapbJsonCommonVersion.value,
"com.thesamet.scalapb" %%% "scalapb-runtime" % scalapbVersion % "protobuf,test",
"io.argonaut" %%% "argonaut" % argonautVersion.value,
"com.lihaoyi" %%% "utest" % "0.8.4" % "test"
),
testFrameworks += new TestFramework("utest.runner.Framework"),
(Global / pomExtra) := {
<url>https://github.com/scalapb-json/scalapb-argonaut</url>
<scm>
<connection>scm:git:github.com/scalapb-json/scalapb-argonaut.git</connection>
<developerConnection>scm:git:[email protected]:scalapb-json/scalapb-argonaut.git</developerConnection>
<url>github.com/scalapb-json/scalapb-argonaut.git</url>
<tag>{tagOrHash.value}</tag>
</scm>
<developers>
<developer>
<id>xuwei-k</id>
<name>Kenji Yoshida</name>
<url>https://github.com/xuwei-k</url>
</developer>
</developers>
},
publishTo := sonatypePublishToBundle.value,
(Compile / doc / scalacOptions) ++= {
val t = tagOrHash.value
Seq(
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath,
"-doc-source-url",
s"https://github.com/scalapb-json/scalapb-argonaut/tree/${t}€{FILE_PATH}.scala"
)
},
compileOrder := {
if (scalaBinaryVersion.value == "3") {
// https://github.com/scala/scala3/issues/10956
// https://github.com/scala/scala3/issues/6138
CompileOrder.JavaThenScala
} else {
compileOrder.value
}
},
ReleasePlugin.extraReleaseCommands,
commands += Command.command("updateReadme")(UpdateReadme.updateReadmeTask),
releaseCrossBuild := true,
releaseTagName := tagName.value,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
UpdateReadme.updateReadmeProcess,
tagRelease,
ReleaseStep(
action = { state =>
val extracted = Project extract state
extracted
.runAggregated(extracted.get(thisProjectRef) / (Global / PgpKeys.publishSigned), state)
},
enableCrossBuild = true
),
releaseStepCommand("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
UpdateReadme.updateReadmeProcess,
pushChanges
)
)
val scalapbArgonautJVM = scalapbArgonaut.jvm
val scalapbArgonautJS = scalapbArgonaut.js
commonSettings
publishArtifact := false
publish := {}
publishLocal := {}
PgpKeys.publishSigned := {}
PgpKeys.publishLocalSigned := {}