forked from scalameta/scalafmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
332 lines (311 loc) · 8.73 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import Dependencies._
import org.scalajs.sbtplugin.cross.CrossProject
lazy val buildSettings = Seq(
organization := "com.geirsson",
version := sys.props.getOrElse("scalafmt.version", version.value),
scalaVersion := scala212,
crossScalaVersions := Seq(scala211, scala212),
scalaCompilerBridgeSource :=
("org.scala-sbt" % "compiler-interface" % "0.13.15" % "component").sources,
updateOptions := updateOptions.value.withCachedResolution(true),
resolvers += Resolver.sonatypeRepo("releases"),
libraryDependencies += scalatest.value % Test,
triggeredMessage in ThisBuild := Watched.clearWhenTriggered,
scalacOptions in (Compile, console) := compilerOptions :+ "-Yrepl-class-based",
assemblyJarName in assembly := "scalafmt.jar",
testOptions in Test += Tests.Argument("-oD")
)
lazy val allSettings = buildSettings ++ publishSettings
name := "scalafmtRoot"
allSettings
noPublish
commands ++= ciCommands
addCommandAlias("downloadIdea", "intellij/updateIdea")
lazy val core = crossProject
.in(file("scalafmt-core"))
.settings(
moduleName := "scalafmt-core",
allSettings,
metaMacroSettings,
buildInfoSettings,
fork.in(run).in(Test) := true,
libraryDependencies ++= Seq(
metaconfig.value,
scalameta.value
),
addCompilerPlugin(paradise)
)
.jsSettings(
libraryDependencies += metaconfigHocon.value
)
.jvmSettings(
libraryDependencies += metaconfigTypesafe.value
)
.enablePlugins(BuildInfoPlugin)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val cli = project
.in(file("scalafmt-cli"))
.settings(
moduleName := "scalafmt-cli",
allSettings,
metaMacroSettings,
mainClass in assembly := Some("org.scalafmt.cli.Cli"),
libraryDependencies ++= Seq(
"com.martiansoftware" % "nailgun-server" % "0.9.1",
"com.github.scopt" %% "scopt" % "3.5.0"
)
)
.dependsOn(coreJVM)
def isOnly(scalaV: String) = Seq(
scalaVersion := scalaV,
crossScalaVersions := Seq(scalaV)
)
lazy val `scalafmt-sbt` = project
.configs(IntegrationTest)
.settings(
allSettings,
Defaults.itSettings,
moduleName := "sbt-scalafmt",
isOnly(scala212),
sbtPlugin := true,
sbtVersion in Global := "1.0.0-M5",
test.in(IntegrationTest) := RunSbtCommand(
Seq(
s"plz $scala212 publishLocal",
"""set sbtVersion in Global := "0.13.15" """,
"such scalafmt-sbt-tests/scripted",
"""set sbtVersion in Global := "1.0.0-M5" """
).mkString("; ", "; ", "")
)(state.value)
)
.dependsOn(cli)
lazy val `scalafmt-sbt-tests` = project
.settings(
allSettings,
noPublish,
isOnly(scala210),
sbtPlugin := true,
ScriptedPlugin.scriptedSettings,
sbtVersion := "0.13.15",
scriptedSbt := "0.13.15",
scriptedLaunchOpts := Seq(
"-Dplugin.version=" + version.value,
"-Dscalafmt.scripted=true",
// .jvmopts is ignored, simulate here
"-XX:MaxPermSize=256m",
"-Xmx2g",
"-Xss2m"
) ++ {
// pass along custom boot properties if specified
val bootProps = "sbt.boot.properties"
sys.props.get(bootProps).map(x => s"-D$bootProps=$x").toList
},
scriptedBufferLog := false
)
lazy val intellij = project
.in(file("scalafmt-intellij"))
.settings(
allSettings,
buildInfoSettings,
noPublish,
noDocs,
ideaBuild := "2016.3.2",
test := {}, // no need to download IDEA to run all tests.
ideaEdition := IdeaEdition.Community,
ideaDownloadDirectory in ThisBuild := baseDirectory.value / "idea",
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.6",
cleanFiles += ideaDownloadDirectory.value
)
.dependsOn(coreJVM, cli)
.enablePlugins(SbtIdeaPlugin)
lazy val tests = project
.in(file("scalafmt-tests"))
.settings(
allSettings,
noPublish,
libraryDependencies ++= Seq(
// Test dependencies
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
"com.lihaoyi" %% "scalatags" % "0.6.3",
scalametaTestkit
)
)
.dependsOn(
cli
)
lazy val benchmarks = project
.in(file("scalafmt-benchmarks"))
.settings(
allSettings,
noPublish,
isOnly(scala212),
moduleName := "scalafmt-benchmarks",
libraryDependencies ++= Seq(
scalametaTestkit,
scalatest.value % Test
),
javaOptions in run ++= Seq(
"-Djava.net.preferIPv4Stack=true",
"-XX:+AggressiveOpts",
"-XX:+UseParNewGC",
"-XX:+UseConcMarkSweepGC",
"-XX:+CMSParallelRemarkEnabled",
"-XX:+CMSClassUnloadingEnabled",
"-XX:ReservedCodeCacheSize=128m",
"-XX:MaxPermSize=1024m",
"-Xss8M",
"-Xms512M",
"-XX:SurvivorRatio=128",
"-XX:MaxTenuringThreshold=0",
"-Xss8M",
"-Xms512M",
"-Xmx2G",
"-server"
)
)
.dependsOn(coreJVM)
.enablePlugins(JmhPlugin)
lazy val readme = scalatex
.ScalatexReadme(projectId = "readme",
wd = file(""),
url = "https://github.com/scalameta/scalafmt/tree/master",
source = "Readme")
.settings(
git.remoteRepo := "git@github.com:scalameta/scalafmt.git",
siteSourceDirectory := target.value / "scalatex",
allSettings,
noPublish,
publish := {
ghpagesPushSite.dependsOn(run.in(Compile).toTask("")).value
},
test := {
run.in(Compile).toTask(" --validate-links").value
},
libraryDependencies ++= Seq(
"com.twitter" %% "util-eval" % "6.41.0"
)
)
.enablePlugins(GhpagesPlugin)
.dependsOn(
coreJVM,
cli
)
def CiCommand(name: String)(commands: List[String]): Command =
Command.command(name) { initState =>
commands.foldLeft(initState) {
case (state, command) => ci(command) :: state
}
}
def ci(command: String) = s"plz ${sys.env("CI_SCALA_VERSION")} $command"
def shouldPublishToBintray: Boolean = {
if (!new File(sys.props("user.home") + "/.bintray/.credentials").exists)
false
else if (sys.props("publish.sonatype") != null) false
else if (sys.env.contains("CI_PULL_REQUEST")) false
else true
}
lazy val noDocs = Seq(
sources in (Compile, doc) := Nil
)
lazy val metaMacroSettings: Seq[Def.Setting[_]] = Seq(
libraryDependencies += scalameta.value,
addCompilerPlugin(paradise),
scalacOptions += "-Xplugin-require:macroparadise"
) ++ noDocs
lazy val compilerOptions = Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Xfuture",
"-Xlint"
)
lazy val publishSettings = Seq(
publishMavenStyle := true,
publishArtifact := true,
bintrayRepository := "maven",
bintrayOrganization := Some("scalameta"),
publishTo := {
if (shouldPublishToBintray) publishTo.in(bintray).value
else {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
},
publishArtifact in Test := false,
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
homepage := Some(url("https://github.com/scalameta/scalafmt")),
autoAPIMappings := true,
apiURL := Some(url("https://olafurpg.github.io/scalafmt/docs/")),
scmInfo := Some(
ScmInfo(
url("https://github.com/scalameta/scalafmt"),
"scm:git:git@github.com:olafurpg/scalafmt.git"
)
),
pomExtra :=
<developers>
<developer>
<id>olafurpg</id>
<name>Ólafur Páll Geirsson</name>
<url>https://geirsson.com</url>
</developer>
</developers>
)
lazy val noPublish = Seq(
publishArtifact := false,
publish := {},
publishLocal := {}
)
lazy val buildInfoSettings: Seq[Def.Setting[_]] = Seq(
buildInfoKeys := Seq[BuildInfoKey](
name,
version,
"nightly" -> version.value,
"stable" -> version.value.replaceAll("\\+.*", ""),
"scala" -> scalaVersion.value,
"coursier" -> coursier,
scalaVersion,
sbtVersion
),
buildInfoPackage := "org.scalafmt",
buildInfoObject := "Versions"
)
def scala210 = "2.10.6"
def scala211 = "2.11.11"
def scala212 = "2.12.2"
def extraSbtBootOptions: Seq[String] = {
// pass along custom boot properties if specified
val bootProps = "sbt.boot.properties"
sys.props.get(bootProps).map(x => s"-D$bootProps=$x").toList
}
def ciCommands = Seq(
CiCommand("ci-fast")(
"test" ::
Nil
),
CiCommand("ci-slow")(
"tests/test:runMain org.scalafmt.ScalafmtProps" ::
Nil
),
Command.command("ci-sbt-scalafmt") { s =>
"scalafmt-sbt/it:test" ::
s
},
CiCommand("ci-publish")(
if (sys.env.contains("CI_PUBLISH")) s"publish" :: Nil
else Nil
)
)