forked from scala-native/scala-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
485 lines (442 loc) · 14.8 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
import java.io.File.pathSeparator
import scala.util.Try
import scalanative.tools.OptimizerReporter
import scalanative.sbtplugin.ScalaNativePluginInternal._
import scalanative.io.packageNameFromPath
val toolScalaVersion = "2.10.6"
val libScalaVersion = "2.11.11"
val libCrossScalaVersions = Seq("2.11.8", "2.11.11")
lazy val baseSettings = Seq(
organization := "org.scala-native",
version := nativeVersion
)
addCommandAlias(
"rebuild",
Seq(
"clean",
"cleanCache",
"cleanLocal",
"dirty-rebuild"
).mkString(";", ";", "")
)
addCommandAlias(
"dirty-rebuild",
Seq(
"nscplugin/publishLocal",
"nativelib/publishLocal",
"publishLocal"
).mkString(";", ";", "")
)
addCommandAlias(
"test-all",
Seq(
"sandbox/run",
"demoNative/run",
"tests/run",
"tools/test",
"benchmarks/run --test",
"scripted"
).mkString(";", ";", "")
)
lazy val publishSnapshot =
taskKey[Unit]("Publish snapshot to sonatype on every commit to master.")
lazy val setUpTestingCompiler = Def.task {
val nscpluginjar = (Keys.`package` in nscplugin in Compile).value
val nativelibjar = (Keys.`package` in nativelib in Compile).value
val scalalibjar = (Keys.`package` in scalalib in Compile).value
val javalibjar = (Keys.`package` in javalib in Compile).value
val testingcompilercp =
(fullClasspath in testingCompiler in Compile).value.files
val testingcompilerjar = (Keys.`package` in testingCompiler in Compile).value
sys.props("scalanative.nscplugin.jar") = nscpluginjar.getAbsolutePath
sys.props("scalanative.testingcompiler.cp") =
(testingcompilercp :+ testingcompilerjar) map (_.getAbsolutePath) mkString pathSeparator
sys.props("scalanative.nativeruntime.cp") =
Seq(nativelibjar, scalalibjar, javalibjar) mkString pathSeparator
sys.props("scalanative.nativelib.dir") =
((crossTarget in Compile).value / "nativelib").getAbsolutePath
}
// to publish plugin (we only need to do this once, it's already done!)
// follow: http://www.scala-sbt.org/0.13/docs/Bintray-For-Plugins.html
// then add a new package
// name: sbt-scala-native, license: BSD-like, version control: git@github.com:scala-native/scala-native.git
// to be available without a resolver
// follow: http://www.scala-sbt.org/0.13/docs/Bintray-For-Plugins.html#Linking+your+package+to+the+sbt+organization
lazy val bintrayPublishSettings = Seq(
bintrayRepository := "sbt-plugins",
bintrayOrganization := Some("scala-native")
) ++ publishSettings
lazy val mavenPublishSettings = Seq(
publishMavenStyle := true,
pomIncludeRepository := { x =>
false
},
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (version.value.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
publishSnapshot := Def.taskDyn {
val travis = Try(sys.env("TRAVIS")).getOrElse("false") == "true"
val pr = Try(sys.env("TRAVIS_PULL_REQUEST"))
.getOrElse("false") != "false"
val branch = Try(sys.env("TRAVIS_BRANCH")).getOrElse("")
val snapshot = version.value.trim.endsWith("SNAPSHOT")
(travis, pr, branch, snapshot) match {
case (true, false, "master", true) =>
println("on master, going to publish a snapshot")
publish
case _ =>
println(
"not going to publish a snapshot due to: " +
s"travis = $travis, pr = $pr, " +
s"branch = $branch, snapshot = $snapshot")
Def.task()
}
}.value,
credentials ++= {
for {
realm <- sys.env.get("MAVEN_REALM")
domain <- sys.env.get("MAVEN_DOMAIN")
user <- sys.env.get("MAVEN_USER")
password <- sys.env.get("MAVEN_PASSWORD")
} yield {
Credentials(realm, domain, user, password)
}
}.toSeq
) ++ publishSettings
lazy val publishSettings = Seq(
publishArtifact in Compile := true,
publishArtifact in Test := false,
homepage := Some(url("http://www.scala-native.org")),
startYear := Some(2015),
licenses := Seq(
"BSD-like" -> url("http://www.scala-lang.org/downloads/license.html")),
developers += Developer(
email = "denys.shabalin@epfl.ch",
id = "densh",
name = "Denys Shabalin",
url = url("http://den.sh")
),
scmInfo := Some(
ScmInfo(
browseUrl = url("https://github.com/scala-native/scala-native"),
connection = "scm:git:git@github.com:scala-native/scala-native.git"
)),
pomExtra := (
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/scala-native/scala-native/issues</url>
</issueManagement>
)
)
lazy val noPublishSettings = Seq(
publishArtifact := false,
packagedArtifacts := Map.empty,
publish := {},
publishLocal := {},
publishSnapshot := {
println("no publish")
}
)
lazy val toolSettings =
baseSettings ++
Seq(
scalaVersion := toolScalaVersion,
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature",
"-encoding",
"utf8"
),
javacOptions ++= Seq("-encoding", "utf8")
)
lazy val libSettings =
(baseSettings ++ ScalaNativePlugin.projectSettings.tail) ++ Seq(
scalaVersion := libScalaVersion,
resolvers := Nil,
scalacOptions ++= Seq(
"-encoding",
"utf8"
)
)
lazy val gcSettings =
if (!System.getenv.containsKey("SCALANATIVE_GC")) {
println("Using default gc")
Seq.empty
} else {
val gc = System.getenv.get("SCALANATIVE_GC")
println(s"Using gc based on SCALANATIVE_GC=$gc")
Seq(nativeGC in Compile := gc)
}
lazy val projectSettings =
ScalaNativePlugin.projectSettings ++ Seq(
scalaVersion := libScalaVersion,
resolvers := Nil
) ++ gcSettings
lazy val util =
project
.in(file("util"))
.settings(toolSettings)
.settings(mavenPublishSettings)
lazy val nir =
project
.in(file("nir"))
.settings(toolSettings)
.settings(mavenPublishSettings)
.dependsOn(util)
lazy val tools =
project
.in(file("tools"))
.settings(toolSettings)
.settings(mavenPublishSettings)
.settings(
libraryDependencies ++= Seq(
"com.lihaoyi" %% "fastparse" % "0.4.2",
"com.lihaoyi" %% "scalaparse" % "0.4.2",
"org.scalacheck" %% "scalacheck" % "1.13.4" % "test",
compilerPlugin(
"org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full),
"org.scalatest" %% "scalatest" % "3.0.0" % "test"
),
fullClasspath in Test := ((fullClasspath in Test) dependsOn setUpTestingCompiler).value,
publishLocal := publishLocal
.dependsOn(publishLocal in nir)
.dependsOn(publishLocal in util)
.value,
// Running tests in parallel results in `FileSystemAlreadyExistsException`
parallelExecution in Test := false
)
.dependsOn(nir, util, testingCompilerInterface % Test)
lazy val nscplugin =
project
.in(file("nscplugin"))
.settings(baseSettings)
.settings(mavenPublishSettings)
.settings(
scalaVersion := libScalaVersion,
crossScalaVersions := libCrossScalaVersions,
crossVersion := CrossVersion.full,
unmanagedSourceDirectories in Compile ++= Seq(
(scalaSource in (nir, Compile)).value,
(scalaSource in (util, Compile)).value
),
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value
)
)
lazy val sbtPluginSettings =
toolSettings ++
bintrayPublishSettings ++
ScriptedPlugin.scriptedSettings ++
Seq(
sbtPlugin := true,
scriptedLaunchOpts ++=
Seq("-Xmx1024M",
"-XX:MaxPermSize=256M",
"-Dplugin.version=" + version.value)
)
lazy val sbtScalaNative =
project
.in(file("sbt-scala-native"))
.settings(sbtPluginSettings)
.settings(
addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.1.0"),
moduleName := "sbt-scala-native",
sbtTestDirectory := (baseDirectory in ThisBuild).value / "scripted-tests",
// publish the other projects before running scripted tests.
scripted := scripted
.dependsOn(publishLocal in util,
publishLocal in nir,
publishLocal in tools,
publishLocal in nscplugin,
publishLocal in nativelib,
publishLocal in javalib,
publishLocal in scalalib)
.evaluated,
publishLocal := publishLocal.dependsOn(publishLocal in tools).value
)
.dependsOn(tools)
lazy val nativelib =
project
.in(file("nativelib"))
.settings(libSettings)
.settings(mavenPublishSettings)
.settings(
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
)
lazy val javalib =
project
.in(file("javalib"))
.settings(libSettings)
.settings(mavenPublishSettings)
.settings(
sources in doc in Compile := Nil, // doc generation currently broken
// This is required to have incremental compilation to work in javalib.
// We put our classes on scalac's `javabootclasspath` so that it uses them
// when compiling rather than the definitions from the JDK.
scalacOptions in Compile := {
val previous = (scalacOptions in Compile).value
val javaBootClasspath =
scala.tools.util.PathResolver.Environment.javaBootClassPath
val classDir = (classDirectory in Compile).value.getAbsolutePath()
val separator = sys.props("path.separator")
"-javabootclasspath" +: s"$classDir$separator$javaBootClasspath" +: previous
}
)
.dependsOn(nativelib)
lazy val assembleScalaLibrary = taskKey[Unit](
"Checks out scala standard library from submodules/scala and then applies overrides.")
lazy val scalalib =
project
.in(file("scalalib"))
.settings(libSettings)
.settings(mavenPublishSettings)
.settings(
assembleScalaLibrary := {
import org.eclipse.jgit.api._
val s = streams.value
val trgDir = target.value / "scalaSources" / scalaVersion.value
if (!trgDir.exists) {
s.log.info(s"Fetching Scala source version ${scalaVersion.value}")
// Make parent dirs and stuff
IO.createDirectory(trgDir)
// Clone scala source code
new CloneCommand()
.setDirectory(trgDir)
.setURI("https://github.com/scala/scala.git")
.call()
}
// Checkout proper ref. We do this anyway so we fail if
// something is wrong
val git = Git.open(trgDir)
s.log.info(s"Checking out Scala source version ${scalaVersion.value}")
git.checkout().setName(s"v${scalaVersion.value}").call()
IO.delete(file("scalalib/src/main/scala"))
IO.copyDirectory(trgDir / "src" / "library" / "scala",
file("scalalib/src/main/scala/scala"))
val epoch :: major :: _ = scalaVersion.value.split("\\.").toList
IO.copyDirectory(file(s"scalalib/overrides-$epoch.$major/scala"),
file("scalalib/src/main/scala/scala"),
overwrite = true)
// Remove all java code, as it's not going to be available
// in the NIR anyway. This also resolves issues wrt overrides
// of code that was previously in Java but is in Scala now.
(file("scalalib/src/main/scala") ** "*.java").get.foreach(IO.delete)
},
compile in Compile := (compile in Compile)
.dependsOn(assembleScalaLibrary)
.value,
publishLocal := publishLocal.dependsOn(assembleScalaLibrary).value
)
.dependsOn(nativelib, javalib)
lazy val demoJVM =
project
.in(file("demo/jvm"))
.settings(noPublishSettings)
.settings(
fork in run := true,
javaOptions in run ++= Seq("-Xms64m", "-Xmx64m")
)
lazy val demoNative =
project
.in(file("demo/native"))
.settings(projectSettings)
.settings(noPublishSettings)
.enablePlugins(ScalaNativePlugin)
lazy val tests =
project
.in(file("unit-tests"))
.settings(projectSettings)
.settings(noPublishSettings)
.settings(
// nativeOptimizerReporter := OptimizerReporter.toDirectory(
// crossTarget.value),
sourceGenerators in Compile += Def.task {
val dir = (scalaSource in Compile).value
val suites = (dir ** "*Suite.scala").get
.flatMap(IO.relativizeFile(dir, _))
.map(file => packageNameFromPath(file.toPath))
.filter(_ != "tests.Suite")
.mkString("Seq(", ", ", ")")
val file = (sourceManaged in Compile).value / "tests" / "Discover.scala"
IO.write(file,
s"""
package tests
object Discover {
val suites: Seq[tests.Suite] = $suites
}
""")
Seq(file)
}.taskValue,
envVars in run ++= Map(
"USER" -> "scala-native",
"HOME" -> baseDirectory.value.getAbsolutePath,
"SCALA_NATIVE_ENV_WITH_EQUALS" -> "1+1=2",
"SCALA_NATIVE_ENV_WITHOUT_VALUE" -> ""
)
)
.enablePlugins(ScalaNativePlugin)
lazy val sandbox =
project
.in(file("sandbox"))
.settings(projectSettings)
.settings(noPublishSettings)
.settings(
// nativeOptimizerReporter := OptimizerReporter.toDirectory(
// crossTarget.value)
)
.enablePlugins(ScalaNativePlugin)
lazy val benchmarks =
project
.in(file("benchmarks"))
.settings(projectSettings)
.settings(noPublishSettings)
.settings(
nativeMode := "release",
sourceGenerators in Compile += Def.task {
val dir = (scalaSource in Compile).value
val benchmarks = (dir ** "*Benchmark.scala").get
.flatMap(IO.relativizeFile(dir, _))
.map(file => packageNameFromPath(file.toPath))
.filter(_ != "benchmarks.Benchmark")
.mkString("Seq(new ", ", new ", ")")
val file = (sourceManaged in Compile).value / "benchmarks" / "Discover.scala"
IO.write(
file,
s"""
package benchmarks
object Discover {
val discovered: Seq[benchmarks.Benchmark[_]] = $benchmarks
}
"""
)
Seq(file)
}.taskValue
)
.enablePlugins(ScalaNativePlugin)
lazy val testingCompilerInterface =
project
.in(file("testing-compiler-interface"))
.settings(libSettings)
.settings(
crossPaths := false,
crossVersion := CrossVersion.Disabled,
autoScalaLibrary := false
)
lazy val testingCompiler =
project
.in(file("testing-compiler"))
.settings(libSettings)
.settings(noPublishSettings)
.settings(
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value
)
)
.dependsOn(testingCompilerInterface, nativelib)