forked from epfl-lara/stainless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
428 lines (362 loc) · 16.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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
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 circeVersion = "0.14.1"
// The number of test suites (e.g. VerificationSuite, UncheckedSuite) run in parallel
// Note that this does not dictate the parallelism per test case (e.g. verification/valid/AbstractPost.scala,
// verification/valid/AbstractRefinementMap$.scala) which is instead set with -Dtestcase-parallelism=<...>
lazy val nTestSuiteParallelism = {
val p = System.getProperty("testsuite-parallelism")
if (p ne null) {
try {
p.toInt
} catch {
case nfe: NumberFormatException => 1
}
} else {
1
}
}
// The Scala version with which Stainless is compiled.
// Note: in case of version bump, do not forget to update the `test` files in `sbt-plugin` (for `sbt scripted`)!
val stainlessScalaVersion = "3.5.0"
// Stainless supports Scala 3.3 programs.
val frontendDottyVersion = stainlessScalaVersion
// The Stainless libraries use Scala 2.13 and Scala 3.3, and is compatible only with Scala 3.3.
val stainlessLibScalaVersion = stainlessScalaVersion
scalaVersion := stainlessScalaVersion
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 := stainlessScalaVersion,
buildInfoPackage := "stainless",
buildInfoKeys := stainlessBuildInfoKeys,
buildInfoOptions := Seq(BuildInfoOption.BuildTime),
)
lazy val commonSettings: Seq[Setting[_]] = artifactSettings ++ Seq(
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature"
),
resolvers ++= Resolver.sonatypeOssRepos("releases"),
resolvers += ("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",
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
("io.get-coursier" %% "coursier" % "2.0.16").cross(CrossVersion.for3Use2_13),
"com.typesafe" % "config" % "1.3.4",
"org.scalatest" %% "scalatest" % "3.2.9" % "test"
),
// There is a conflict with the cross version of scala-xml.
// Coursier depends on 2.13 while scalatest on 3.0.
// We can get away by excluding 3.0 and using the 2.13 version instead.
// Note that we leverage excludeDependencies that also excludes the dependency brought by the dependsOn inox.
excludeDependencies ++= Seq(
ExclusionRule("org.scala-lang.modules", "scala-xml_3")
),
// disable documentation packaging in universal:stage to speedup development
Compile / packageDoc / mappings := Seq(),
Compile / sourcesInBase := false,
run / Keys.fork := true,
run / javaOptions ++= Seq(
"-Xss256M",
"-Xms1024M",
"-XX:MaxMetaspaceSize=1G",
"-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")),
)
lazy val stainlessLibSettings: Seq[Setting[_]] = artifactSettings ++ Seq(
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature"
),
// disable documentation packaging in universal:stage to speedup development
Compile / packageDoc / mappings := Seq(),
Compile / sourcesInBase := false,
run / Keys.fork := true,
run / javaOptions ++= Seq(
"-Xss256M",
"-Xms1024M",
"-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"))
)
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
def libraryFiles(baseDir: File): Seq[(String, File)] = {
// Note baseDir.value is either frontends/scalac or frontends/dotty, so we need to go up two levels with / .. / .. /
val libFiles = ((baseDir / ".." / ".." / "frontends" / "library" / "stainless") ** "*.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
}
def commonFrontendSettings(compilerVersion: String): 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.
* NOTE 2: baseDirectory.value is either frontends/scalac or frontends/dotty, so we need to go up two levels with / .. / .. /
*/
IntegrationTest / unmanagedResourceDirectories += (baseDirectory.value / ".." / ".." / "frontends" / "benchmarks"),
Compile / unmanagedSourceDirectories += (baseDirectory.value / ".." / ".." / "frontends" / "common" / "src" / "main" / "scala"),
Test / unmanagedSourceDirectories += (baseDirectory.value / ".." / ".." / "frontends" / "common" / "src" / "test" / "scala"),
IntegrationTest / unmanagedSourceDirectories += (baseDirectory.value / ".." / ".." / "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(baseDirectory.value)) 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 compilerVersion = "$compilerVersion"
|
| override protected def displayVersion(reporter: inox.Reporter): Unit = {
| super.displayVersion(reporter)
| reporter.info(s"Bundled Scala compiler: $$compilerVersion")
| }
|
| val defaultPaths = List(${removeSlashU(libraryFiles(baseDirectory.value).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(Nil, libPaths)
|
|}""".stripMargin)
Seq(main)
}) ++
inConfig(IntegrationTest)(Defaults.testTasks ++ Seq(
logBuffered := (nTestSuiteParallelism > 1),
parallelExecution := (nTestSuiteParallelism > 1),
))
Global / concurrentRestrictions := Seq(
Tags.limit(Tags.Test, nTestSuiteParallelism)
)
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 cafebabe = ghProject("https://github.com/epfl-lara/cafebabe.git", "616e639b34379e12b8ac202849de3ebbbd0848bc")
// 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")
lazy val `stainless-library` = (project in file("frontends") / "library")
.disablePlugins(AssemblyPlugin)
.settings(stainlessLibSettings, publishMavenSettings)
.settings(
name := "stainless-library",
scalaVersion := stainlessLibScalaVersion,
// don't publish binaries - stainless-library is only consumed as a sources component
packageBin / publishArtifact := false,
crossVersion := CrossVersion.binary,
Compile / scalaSource := baseDirectory.value / "stainless"
)
lazy val `stainless-algebra` = (project in file("frontends") / "algebra")
.disablePlugins(AssemblyPlugin)
.settings(stainlessLibSettings, publishMavenSettings)
.settings(
name := "stainless-algebra",
version := "0.1.2",
scalaVersion := stainlessLibScalaVersion,
// don't publish binaries - stainless-algebra is only consumed as a sources component
packageBin / publishArtifact := false,
crossVersion := CrossVersion.binary,
Compile / scalaSource := baseDirectory.value / "stainless"
)
.dependsOn(`stainless-library`)
lazy val `stainless-dotty` = (project in file("frontends/dotty"))
.enablePlugins(JavaAppPackaging)
.enablePlugins(BuildInfoPlugin)
.settings(commonSettings, commonFrontendSettings(frontendDottyVersion))
.settings(scriptSettings, assemblySettings)
.settings(noPublishSettings)
.settings(
name := "stainless-dotty",
frontendClass := "dotc.DottyCompiler",
libraryDependencies += "org.scala-lang" %% "scala3-compiler" % frontendDottyVersion,
buildInfoKeys ++= Seq[BuildInfoKey]("useJavaClassPath" -> false),
// We include Scala library to be certain we also include scala-parser-combinators (which is not shipped with the Scala std library)
assemblyPackageScala / assembleArtifact := true,
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)
lazy val `stainless-dotty-plugin` = (project in file("frontends") / "stainless-dotty-plugin")
.settings(artifactSettings, publishMavenSettings, assemblySettings)
.settings(
name := "stainless-dotty-plugin",
crossVersion := CrossVersion.full, // because compiler api is not binary compatible
Compile / packageBin := (`stainless-dotty` / Compile / assembly).value
)
lazy val `stainless-dotty-standalone` = (project in file("frontends") / "stainless-dotty-standalone")
.enablePlugins(BuildInfoPlugin)
.enablePlugins(JavaAppPackaging)
.settings(artifactSettings, assemblySettings)
.settings(
name := "stainless-dotty-standalone",
buildInfoKeys ++= Seq[BuildInfoKey]("useJavaClassPath" -> true),
assembly / mainClass := Some("stainless.Main"),
assembly / assemblyJarName := (name.value + "-" + version.value + ".jar"),
Runtime / unmanagedJars := (`stainless-dotty` / Runtime / unmanagedJars).value,
assemblyPackageScala / assembleArtifact := true,
assembly / assemblyExcludedJars := {
val cp = (assembly / fullClasspath).value
cp filter {_.data.getName.startsWith("scalaz3")}
},
)
.dependsOn(`stainless-dotty`)
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" -> Seq(frontendDottyVersion),
"stainlessScalaVersion" -> stainlessScalaVersion,
"stainlessLibScalaVersion" -> stainlessLibScalaVersion,
),
)
.settings(
scripted := scripted.tag(Tags.Test).evaluated,
scriptedLaunchOpts ++= Seq(
"-Xmx768m",
"-Dplugin.version=" + version.value,
"-Ddotty.version=" + frontendDottyVersion
),
scriptedBufferLog := false,
scriptedDependencies := {
publishLocal.value
(`stainless-library` / update).value
(`stainless-library` / publishLocal).value
(`stainless-dotty-plugin` / publishLocal).value
}
)
lazy val root = (project in file("."))
.disablePlugins(AssemblyPlugin)
.settings(artifactSettings, noPublishSettings)
.settings(
Compile / sourcesInBase := false,
)
.dependsOn(`stainless-library`, `stainless-dotty`, `sbt-stainless`)
.aggregate(`stainless-core`, `stainless-library`, `stainless-dotty`, `sbt-stainless`, `stainless-dotty-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