-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sbt
216 lines (198 loc) · 6.05 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
import sbtcrossproject.CrossPlugin.autoImport.crossProject
lazy val tagName = Def.setting {
s"v${if (releaseUseGlobalVersion.value) (ThisBuild / version).value else version.value}"
}
lazy val tagOrHash = Def.setting {
if (isSnapshot.value) sys.process.Process("git rev-parse HEAD").lineStream_!.head
else tagName.value
}
commonSettings
noPublishSettings
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.settings(commonSettings)
.settings(
name := coreName,
moduleName := coreName,
libraryDependencies ++= {
if (scalaBinaryVersion.value == "3") {
Seq(
"com.github.scalaprops" %%% "scalaprops-gen" % scalapropsVersion.value,
"org.typelevel" %%% "shapeless3-deriving" % "3.4.3"
)
} else {
Seq(
"com.github.scalaprops" %%% "scalaprops-core" % scalapropsVersion.value,
"com.chuusai" %%% "shapeless" % "2.3.12"
)
}
}
)
.jsSettings(
scalacOptions += {
val a = (LocalRootProject / baseDirectory).value.toURI.toString
val g = "https://raw.githubusercontent.com/scalaprops/scalaprops-shapeless/" + tagOrHash.value
val key = scalaBinaryVersion.value match {
case "3" =>
"-scalajs-mapSourceURI"
case _ =>
"-P:scalajs:mapSourceURI"
}
s"${key}:$a->$g/"
},
Test / scalaJSStage := FastOptStage
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native
lazy val test = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.dependsOn(core)
.settings(commonSettings)
.settings(
libraryDependencies += "com.github.scalaprops" %%% "scalaprops" % scalapropsVersion.value % "test"
)
.settings(noPublishSettings)
.jsSettings(
Test / scalaJSStage := FastOptStage
)
.nativeSettings(
scalapropsNativeSettings
)
lazy val testJVM = test.jvm
lazy val testJS = test.js
lazy val testNative = test.native
lazy val coreName = "scalaprops-shapeless"
def Scala212 = "2.12.20"
def Scala3 = "3.3.4"
lazy val commonSettings = Def.settings(
scalaVersion := Scala212,
crossScalaVersions := Scala212 :: "2.13.15" :: Scala3 :: Nil,
publishTo := sonatypePublishToBundle.value,
releaseTagName := tagName.value,
releaseCrossBuild := true,
commands += Command.command("updateReadme")(updateReadmeTask),
organization := "com.github.scalaprops",
scalapropsVersion := "0.9.1"
) ++ compileSettings ++ publishSettings ++ scalapropsCoreSettings
lazy val unusedWarnings = Seq("-Ywarn-unused")
lazy val compileSettings = Seq(
(Compile / doc / scalacOptions) ++= {
val tag = tagOrHash.value
Seq(
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath,
"-doc-source-url",
s"https://github.com/scalaprops/scalaprops-shapeless/tree/${tag}€{FILE_PATH}.scala"
)
},
scalacOptions ++= {
if (scalaBinaryVersion.value == "3") {
Nil
} else {
unusedWarnings ++ Seq(
"-Xlint"
)
}
},
scalacOptions ++= {
scalaBinaryVersion.value match {
case "2.12" =>
Seq(
"-Yno-adapted-args",
"-Xsource:3",
"-language:higherKinds",
"-Xfuture"
)
case "2.13" =>
Seq("-Xsource:3-cross")
case _ =>
Nil
}
},
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-language:existentials",
"-language:implicitConversions"
)
) ++ Seq(Compile, Test).flatMap(c => c / console / scalacOptions --= unusedWarnings)
lazy val publishSettings = Seq(
homepage := Some(url("https://github.com/scalaprops/scalaprops-shapeless")),
licenses := Seq(
"Apache 2.0" -> url("http://opensource.org/licenses/Apache-2.0")
),
scmInfo := Some(
ScmInfo(
url("https://github.com/scalaprops/scalaprops-shapeless.git"),
"scm:git:github.com/scalaprops/scalaprops-shapeless.git",
Some("scm:git:git@github.com:scalaprops/scalaprops-shapeless.git")
)
),
developers := List(
Developer(
"xuwei-k",
"Kenji Yoshida",
"",
url("https://github.com/xuwei-k")
)
),
publishMavenStyle := true,
pomIncludeRepository := { _ => false }
)
lazy val noPublishSettings = Seq(
publish := {},
publishLocal := {},
PgpKeys.publishSigned := {},
PgpKeys.publishLocalSigned := {},
publishArtifact := false
)
lazy val updateReadmeTask = { state: State =>
val extracted = Project.extract(state)
val v = extracted get version
val org = extracted get organization
val modules = coreName :: Nil
val snapshotOrRelease = if (extracted get isSnapshot) "snapshots" else "releases"
val readme = "README.md"
val readmeFile = file(readme)
val newReadme = Predef
.augmentString(IO.read(readmeFile))
.lines
.map { line =>
val matchReleaseOrSnapshot = line.contains("SNAPSHOT") == v.contains("SNAPSHOT")
if (line.startsWith("libraryDependencies") && matchReleaseOrSnapshot) {
val i = modules.map("\"" + _ + "\"").indexWhere(line.contains)
s"""libraryDependencies += "$org" %% "${modules(i)}" % "$v""""
} else line
}
.mkString("", "\n", "\n")
IO.write(readmeFile, newReadme)
val git = new sbtrelease.Git(extracted get baseDirectory)
git.add(readme) ! state.log
git.commit(message = "update " + readme, sign = false, signOff = false) ! state.log
sys.process.Process("git diff HEAD^") ! state.log
state
}
lazy val updateReadmeProcess: ReleaseStep = updateReadmeTask
import ReleaseTransformations._
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
updateReadmeProcess,
tagRelease,
ReleaseStep(
action = { state =>
val extracted = Project extract state
extracted.runAggregated(extracted.get(thisProjectRef) / (Global / PgpKeys.publishSigned), state)
},
enableCrossBuild = true
),
releaseStepCommandAndRemaining("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
updateReadmeProcess,
pushChanges
)
// build.sbt shamelessly inspired by https://github.com/fthomas/refined/blob/master/build.sbt