forked from epfl-lara/stainless
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
407 lines (343 loc) · 15.5 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
import sbt.ScriptedPlugin
enablePlugins(GitVersioning)
enablePlugins(GitBranchPrompt)
git.useGitDescribe := true
Global / excludeLintKeys += buildInfoKeys
Global / excludeLintKeys += buildInfoOptions
Global / excludeLintKeys += buildInfoPackage
Global / excludeLintKeys += testOptions
Global / excludeLintKeys += publishArtifact
val osInf = Option(System.getProperty("os.name")).getOrElse("")
val isUnix = osInf.indexOf("nix") >= 0 || osInf.indexOf("nux") >= 0
val isWindows = osInf.indexOf("Win") >= 0
val isMac = osInf.indexOf("Mac") >= 0
val osName = if (isWindows) "win" else if (isMac) "mac" else "unix"
val osArch = System.getProperty("sun.arch.data.model")
val dottyLibrary = "dotty-compiler_2.12"
val dottyVersion = "0.12.0-RC1-nonbootstrapped"
val circeVersion = "0.14.1"
lazy val nParallel = {
val p = System.getProperty("parallel")
if (p ne null) {
try {
p.toInt
} catch {
case nfe: NumberFormatException => 1
}
} else {
1
}
}
val SupportedScalaVersions = Seq("2.13.6")
scalaVersion := "2.13.6"
lazy val frontendClass = settingKey[String]("The name of the compiler wrapper used to extract stainless trees")
// FIXME @nv: dotty compiler needs the scala-library and dotty-library (and maybe some other
// dependencies?) so we set them here through stainless' compile-time dependencies.
lazy val extraClasspath = taskKey[String]("Classpath extensions passed directly to the underlying compiler")
lazy val scriptPath = taskKey[String]("Classpath used in the stainless Bash script")
lazy val stainlessBuildInfoKeys = Seq[BuildInfoKey](
name,
version,
scalaVersion,
sbtVersion,
)
lazy val noPublishSettings: Seq[Setting[_]] = Seq(
publish := {},
publishM2 := {},
publish / skip := true,
)
lazy val baseSettings: Seq[Setting[_]] = Seq(
organization := "ch.epfl.lara",
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html"))
)
lazy val artifactSettings: Seq[Setting[_]] = baseSettings ++ Seq(
scalaVersion := "2.13.6",
crossScalaVersions := SupportedScalaVersions,
buildInfoPackage := "stainless",
buildInfoKeys := stainlessBuildInfoKeys,
buildInfoOptions := Seq(BuildInfoOption.BuildTime),
)
lazy val commonSettings: Seq[Setting[_]] = artifactSettings ++ Seq(
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature"
),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases").withAllowInsecureProtocol(true),
("uuverifiers" at "http://logicrunch.research.it.uu.se/maven").withAllowInsecureProtocol(true),
),
libraryDependencies ++= Seq(
// "ch.epfl.lara" %% "inox" % inoxVersion,
// "ch.epfl.lara" %% "inox" % inoxVersion % "test" classifier "tests",
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.3",
"uuverifiers" %% "princess" % "2020-03-12",
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.get-coursier" %% "coursier" % "2.0.0-RC4-1",
"com.typesafe" % "config" % "1.3.4",
"org.scalatest" %% "scalatest" % "3.2.7" % "test",
),
// disable documentation packaging in universal:stage to speedup development
Compile / packageDoc / mappings := Seq(),
Global / concurrentRestrictions += Tags.limitAll(nParallel),
Compile / sourcesInBase := false,
run / Keys.fork := true,
run / javaOptions ++= Seq(
"-Xss256M",
"-Xms1024M",
"-XX:MaxMetaspaceSize=512M",
"-XX:+UseCodeCacheFlushing",
"-XX:ReservedCodeCacheSize=256M",
),
/* run / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", */
Test / testOptions := Seq(Tests.Argument("-oDF")),
IntegrationTest / testOptions := Seq(Tests.Argument("-oDF")),
ThisBuild / maxErrors := 5
)
lazy val assemblySettings: Seq[Setting[_]] = {
def isNativeLib(file: String): Boolean =
file.endsWith("dll") || file.endsWith("so") || file.endsWith("jnilib")
Seq(
assembly / assemblyMergeStrategy := {
// The BuildInfo class file from the current project comes after the one from `stainless-scalac`,
// hence the following merge strategy picks the standalone BuildInfo over the usual one.
case "stainless/BuildInfo.class" => MergeStrategy.last
case "stainless/BuildInfo$.class" => MergeStrategy.last
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case PathList("scala", "collection", "compat", _*) => MergeStrategy.first
case PathList("scala", "annotation", _*) => MergeStrategy.first
case PathList("scala", "util", _*) => MergeStrategy.first
case PathList("stainless", _*) => MergeStrategy.first
case path if path.endsWith("scala-collection-compat.properties") => MergeStrategy.first
case "reflect.properties" => MergeStrategy.first
case file if isNativeLib(file) => MergeStrategy.first
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
},
)
}
lazy val libFilesFile = "libfiles.txt" // file storing list of library file names
lazy val regenFilesFile = false
lazy val libraryFiles: Seq[(String, File)] = {
val libFiles = ((root.base / "frontends" / "library") ** "*.scala").get
val dropCount = (libFiles.head.getPath indexOfSlice "library") + ("library".size + 1 /* for separator */)
val res : Seq[(String, File)] = libFiles.map(file => (file.getPath drop dropCount, file)) // Drop the prefix of the path (i.e. everything before "library")
if (regenFilesFile) {
val fileNames : Seq[String] = res.map(_._1)
println(fileNames)
reflect.io.File(libFilesFile).writeAll(fileNames.mkString("\n"))
}
res
}
lazy val commonFrontendSettings: Seq[Setting[_]] = Defaults.itSettings ++ Seq(
/**
* NOTE: IntelliJ seems to have trouble including sources located outside the base directory of an
* sbt project. You can temporarily disable the following four lines when importing the project.
*/
IntegrationTest / unmanagedResourceDirectories += (root.base / "frontends" / "benchmarks"),
Compile / unmanagedSourceDirectories += (root.base.getAbsoluteFile / "frontends" / "common" / "src" / "main" / "scala"),
Test / unmanagedSourceDirectories += (root.base.getAbsoluteFile / "frontends" / "common" / "src" / "test" / "scala"),
IntegrationTest / unmanagedSourceDirectories += (root.base.getAbsoluteFile / "frontends" / "common" / "src" / "it" / "scala"),
// We have to use managed resources here to keep sbt's source watcher happy
Compile / resourceGenerators += Def.task {
for ((libPath, libFile) <- libraryFiles) yield {
val resourceFile = (Compile / resourceManaged).value / libPath
IO.write(resourceFile, IO.read(libFile))
resourceFile
}
}.taskValue,
assembly / test := {}, // Skip the test during assembly
Compile / sourceGenerators += Def.task {
val main = (Compile / sourceManaged).value / "stainless" / "Main.scala"
def removeSlashU(in: String): String =
in.replaceAll("\\\\" + "u", "\\\\\"\"\"+\"\"\"u")
.replaceAll("\\\\" + "U", "\\\\\"\"\"+\"\"\"U")
IO.write(main,
s"""|package stainless
|
|object Main extends MainHelpers {
|
| val extraClasspath = \"\"\"${removeSlashU(extraClasspath.value)}\"\"\"
| val extraCompilerArguments = List("-classpath", \"\"\"${removeSlashU(extraClasspath.value)}\"\"\")
|
| val defaultPaths = List(${removeSlashU(libraryFiles.map(_._1).mkString("\"\"\"", "\"\"\",\n \"\"\"", "\"\"\""))})
| val libPaths = try {
| val source = scala.io.Source.fromFile(\"${libFilesFile}\")
| try source.getLines().toList finally source.close()
| } catch {
| case (_:Throwable) => defaultPaths
| }
|
| override val factory = new frontends.${frontendClass.value}.Factory(extraCompilerArguments, libPaths)
|
|}""".stripMargin)
Seq(main)
}) ++
inConfig(IntegrationTest)(Defaults.testTasks ++ Seq(
logBuffered := (nParallel > 1),
parallelExecution := (nParallel > 1)
))
val scriptSettings: Seq[Setting[_]] = Seq(
extraClasspath := {
((Compile / classDirectory).value.getAbsolutePath +: (Compile / dependencyClasspath).value.map(_.data.absolutePath))
.mkString(System.getProperty("path.separator"))
}
)
def ghProject(repo: String, version: String) = RootProject(uri(s"${repo}#${version}"))
// lazy val inox = RootProject(file("../inox"))
lazy val inox = ghProject("https://github.com/epfl-lara/inox.git", "e74baa7fdb9a941f4e4ce8e880b96a32a96c8b59")
lazy val cafebabe = ghProject("https://github.com/epfl-lara/cafebabe.git", "7efbf6341ecc7474e7a8c6999d97bf3d810fa5c8")
//lazy val dotty = ghProject("git://github.com/lampepfl/dotty.git", "b3194406d8e1a28690faee12257b53f9dcf49506")
// Allow integration test to use facilities from regular tests
lazy val IntegrationTest = config("it") extend(Test)
lazy val `stainless-core` = (project in file("core"))
.disablePlugins(AssemblyPlugin)
.enablePlugins(BuildInfoPlugin)
//.enablePlugins(SphinxPlugin)
.settings(name := "stainless-core")
.settings(commonSettings, publishMavenSettings)
//.settings(site.settings)
.dependsOn(inox % "compile->compile;test->test")
.dependsOn(cafebabe % "compile->compile;test->test")
lazy val `stainless-library` = (project in file("frontends") / "library")
.disablePlugins(AssemblyPlugin)
.settings(commonSettings, publishMavenSettings)
.settings(
name := "stainless-library",
// don't publish binaries - stainless-library is only consumed as a sources component
packageBin / publishArtifact := false,
crossVersion := CrossVersion.binary,
Compile / scalaSource := baseDirectory.value
)
lazy val `stainless-algebra` = (project in file("frontends") / "algebra")
.disablePlugins(AssemblyPlugin)
.settings(commonSettings, publishMavenSettings)
.settings(
name := "stainless-algebra",
version := "0.1.2",
// don't publish binaries - stainless-algebra is only consumed as a sources component
packageBin / publishArtifact := false,
crossVersion := CrossVersion.binary,
Compile / scalaSource := baseDirectory.value,
)
.dependsOn(`stainless-library`)
lazy val `stainless-scalac` = (project in file("frontends") / "scalac")
.enablePlugins(JavaAppPackaging)
.enablePlugins(BuildInfoPlugin)
.settings(commonSettings, commonFrontendSettings)
.settings(scriptSettings, assemblySettings)
.settings(noPublishSettings)
.settings(
name := "stainless-scalac",
frontendClass := "scalac.ScalaCompiler",
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value,
buildInfoKeys ++= Seq[BuildInfoKey]("useJavaClassPath" -> false),
assembly / assemblyOption := (assembly / assemblyOption).value.copy(includeScala = false),
assembly / assemblyExcludedJars := {
val cp = (assembly / fullClasspath).value
// Don't include scalaz3 dependency because it is OS dependent
cp filter {_.data.getName.startsWith("scalaz3")}
},
)
.dependsOn(`stainless-core`)
.dependsOn(inox % "test->test;it->test,it")
.configs(IntegrationTest)
// Following https://github.com/sbt/sbt-assembly#q-despite-the-concerned-friends-i-still-want-publish-fat-jars-what-advice-do-you-have
lazy val `stainless-scalac-plugin` = (project in file("frontends") / "stainless-scalac-plugin")
.settings(artifactSettings, publishMavenSettings, assemblySettings)
.settings(
name := "stainless-scalac-plugin",
crossVersion := CrossVersion.full, // because compiler api is not binary compatible
Compile / packageBin := (`stainless-scalac` / Compile / assembly).value
)
lazy val `stainless-scalac-standalone` = (project in file("frontends") / "stainless-scalac-standalone")
.enablePlugins(BuildInfoPlugin)
.enablePlugins(JavaAppPackaging)
.settings(artifactSettings, assemblySettings)
.settings(
name := "stainless-scalac-standalone",
buildInfoKeys ++= Seq[BuildInfoKey]("useJavaClassPath" -> true),
assembly / mainClass := Some("stainless.Main"),
assembly / assemblyJarName := (name.value + "-" + version.value + ".jar"),
Runtime / unmanagedJars := (`stainless-scalac` / Runtime / unmanagedJars).value
)
.dependsOn(`stainless-scalac`)
// lazy val `stainless-dotty-frontend` = (project in file("frontends/dotty"))
// .settings(commonSettings)
// .settings(noPublishSettings)
// .settings(name := "stainless-dotty-frontend")
// .dependsOn(`stainless-core`)
// .settings(libraryDependencies += "ch.epfl.lamp" % dottyLibrary % dottyVersion % "provided")
// lazy val `stainless-dotty` = (project in file("frontends/stainless-dotty"))
// .enablePlugins(JavaAppPackaging)
// .enablePlugins(BuildInfoPlugin)
// .settings(commonSettings, commonFrontendSettings)
// .settings(artifactSettings, scriptSettings)
// .settings(noPublishSettings)
// .settings(
// name := "stainless-dotty",
// frontendClass := "dotc.DottyCompiler",
// )
// .dependsOn(inox % "test->test;it->test,it")
// .dependsOn(`stainless-dotty-frontend`)
// .aggregate(`stainless-dotty-frontend`)
// // Should truly depend on dotty, overriding the "provided" modifier above:
// .settings(libraryDependencies += "ch.epfl.lamp" % dottyLibrary % dottyVersion)
// .configs(IntegrationTest)
lazy val `sbt-stainless` = (project in file("sbt-plugin"))
.enablePlugins(BuildInfoPlugin)
.enablePlugins(SbtPlugin)
.settings(baseSettings)
.settings(publishSbtSettings)
.settings(
// Note: sbt-stainless is itself compiled with Scala 2.12 (as is SBT 1.x)
description := "Plugin integrating Stainless in sbt",
sbtPlugin := true,
publishMavenStyle := false,
buildInfoUsePackageAsPath := true,
buildInfoPackage := "ch.epfl.lara.sbt.stainless",
buildInfoKeys ++= Seq[BuildInfoKey](
BuildInfoKey.map(version) { case (_, v) => "stainlessVersion" -> v },
"supportedScalaVersions" -> SupportedScalaVersions,
),
)
.settings(
scripted := scripted.tag(Tags.Test).evaluated,
scriptedLaunchOpts ++= Seq(
"-Xmx768m",
"-XX:MaxMetaspaceSize=384m",
"-Dplugin.version=" + version.value,
"-Dscala.version=" + sys.props.get("scripted.scala.version").getOrElse((`stainless-scalac` / scalaVersion).value)
),
scriptedBufferLog := false,
scriptedDependencies := {
publishLocal.value
(`stainless-library` / update).value
(`stainless-library` / publishLocal).value
(`stainless-scalac-plugin` / publishLocal).value
}
)
lazy val root = (project in file("."))
.disablePlugins(AssemblyPlugin)
.settings(artifactSettings, noPublishSettings)
.settings(
Compile / sourcesInBase := false,
)
.dependsOn(`stainless-scalac`, `stainless-library`/*, `stainless-dotty`*/, `sbt-stainless`)
.aggregate(`stainless-core`, `stainless-library`, `stainless-scalac`/*, `stainless-dotty`*/, `sbt-stainless`, `stainless-scalac-plugin`)
def commonPublishSettings = Seq(
bintrayOrganization := Some("epfl-lara")
)
// by default sbt-bintray publishes all sbt plugins in Ivy style
def publishSbtSettings = commonPublishSettings ++ Seq(
bintrayRepository := "sbt-plugins"
)
// by default sbt-bintray publishes all artifacts but sbt plugins in Maven style
def publishMavenSettings = commonPublishSettings ++ Seq(
bintrayRepository := "maven"
)
// FIXME assembly should be disabled at the top level, but isn't
// FIXME assembly is not compatible with dotty -- some conflict with scala versions?