forked from epfl-lara/stainless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
228 lines (184 loc) · 8.3 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
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 inoxVersion = "1.0.2-81-g9f77744"
val dottyVersion = "0.1.1-bin-20170429-10a2ce6-NIGHTLY"
lazy val nParallel = {
val p = System.getProperty("parallel")
if (p ne null) {
try {
p.toInt
} catch {
case nfe: NumberFormatException => 1
}
} else {
1
}
}
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 script = taskKey[Unit]("Generate the stainless Bash script")
lazy val scalaVersionSetting: Setting[_] = scalaVersion := "2.11.8"
lazy val artifactSettings: Seq[Setting[_]] = Seq(
version := "0.1",
organization := "ch.epfl.lara",
scalaVersionSetting
)
lazy val commonSettings: Seq[Setting[_]] = artifactSettings ++ Seq(
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature"
),
scalacOptions in (Compile, doc) ++= Seq("-doc-root-content", baseDirectory.value+"/src/main/scala/root-doc.txt"),
// TODO: Reenable site.settings
// site.settings,
// site.sphinxSupport(),
unmanagedJars in Runtime += {
root.base / "unmanaged" / s"scalaz3-$osName-$osArch-${scalaBinaryVersion.value}.jar"
},
resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases",
"uuverifiers" at "http://logicrunch.it.uu.se:4096/~wv/maven",
Resolver.typesafeIvyRepo("releases")
),
libraryDependencies ++= Seq(
//"ch.epfl.lamp" %% "dotty" % "0.1-SNAPSHOT",
"ch.epfl.lara" %% "inox" % inoxVersion,
"ch.epfl.lara" %% "inox" % inoxVersion % "test" classifier "tests",
"org.scalatest" %% "scalatest" % "3.0.1" % "test"
),
concurrentRestrictions in Global += Tags.limit(Tags.Test, nParallel),
sourcesInBase in Compile := false,
Keys.fork in run := true,
testOptions in Test := Seq(Tests.Argument("-oDF")),
testOptions in IntegrationTest := Seq(Tests.Argument("-oDF"))
)
lazy val commonFrontendSettings: Seq[Setting[_]] = Seq(
libraryDependencies ++= Seq(
"ch.epfl.lara" %% "inox" % inoxVersion % "it" classifier "tests" classifier "it",
"org.scalatest" %% "scalatest" % "3.0.1" % "it" // FIXME: Does this override `% "test"` from commonSettings above?
),
sourceGenerators in Compile <+= Def.task {
val libraryFiles = ((root.base / "frontends" / "library") ** "*.scala").getPaths
val main = (sourceManaged in Compile).value / "stainless" / "Main.scala"
IO.write(main, s"""|package stainless
|
|import extraction.xlang.{trees => xt}
|
|object Main extends MainHelpers {
| val libraryFiles = List(
${libraryFiles
.mkString("\"\"\"", "\"\"\",\n \"\"\"", "\"\"\"")
.replaceAll("\\\\" + "u", "\\\\\"\"\"+\"\"\"u")}
| )
|
| def extractFromSource(ctx: inox.Context, compilerOpts: List[String]): (
| List[xt.UnitDef],
| Program { val trees: xt.type }
| ) = frontends.${frontendClass.value}(ctx, List("-classpath", "${extraClasspath.value}") ++ compilerOpts)
|}""".stripMargin)
Seq(main)
}
) ++ Defaults.itSettings ++ inConfig(IntegrationTest)(Defaults.testTasks ++ Seq(
logBuffered := (nParallel > 1),
parallelExecution := (nParallel > 1),
/**
* NOTE: IntelliJ seems to have trouble including sources located outside the base directory of an
* sbt project. You can temporarily disable the following two lines when importing the project.
*/
unmanagedResourceDirectories += (root.base / "frontends" / "benchmarks")
))
val scriptSettings: Seq[Setting[_]] = Seq(
compile <<= (compile in Compile) dependsOn script,
clean := {
clean.value
val scriptFile = root.base / "bin" / name.value
if (scriptFile.exists && scriptFile.isFile) {
scriptFile.delete
}
},
scriptPath := {
val cps = (managedClasspath in Runtime).value ++
(unmanagedClasspath in Runtime).value ++
(internalDependencyClasspath in Runtime).value
val out = (classDirectory in Compile).value
val res = (resourceDirectory in Compile).value
(res.getAbsolutePath +: out.getAbsolutePath +: cps.map(_.data.absolutePath)).mkString(System.getProperty("path.separator"))
},
extraClasspath := {
((classDirectory in Compile).value.getAbsolutePath +: (dependencyClasspath in Compile).value.map(_.data.absolutePath))
.mkString(System.getProperty("path.separator"))
},
script := {
val s = streams.value
try {
val binDir = root.base / "bin"
binDir.mkdirs
val scriptFile = binDir / name.value
if (scriptFile.exists) {
s.log.info("Regenerating '" + scriptFile.getName + "' script")
scriptFile.delete
} else {
s.log.info("Generating '" + scriptFile.getName + "' script")
}
val paths = scriptPath.value
IO.write(scriptFile, s"""|#!/bin/bash --posix
|
|SCALACLASSPATH="$paths"
|
|java -Xmx2G -Xms512M -Xss64M -classpath "$${SCALACLASSPATH}" -Dscala.usejavacp=true stainless.Main $$@ 2>&1 | tee -i last.log
|""".stripMargin)
scriptFile.setExecutable(true)
} catch {
case e: Throwable =>
s.log.error("There was an error while generating the script file: " + e.getLocalizedMessage)
}
}
)
def ghProject(repo: String, version: String) = RootProject(uri(s"${repo}#${version}"))
//lazy val inox = RootProject(file("../inox"))
//lazy val dotty = ghProject("git://github.com/lampepfl/dotty.git", "b3194406d8e1a28690faee12257b53f9dcf49506")
lazy val cafebabe = ghProject("git://github.com/psuter/cafebabe.git", "49dce3c83450f5fa0b5e6151a537cc4b9f6a79a6")
lazy val `stainless-core` = (project in file("core"))
.settings(name := "stainless-core")
.settings(commonSettings)
//.dependsOn(inox % "compile->compile;test->test")
.dependsOn(cafebabe)
lazy val `stainless-scalac` = (project in file("frontends/scalac"))
.settings(
name := "stainless-scalac",
frontendClass := "scalac.ScalaCompiler",
extraClasspath := "", // no need for the classpath extension with scalac
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value)
.dependsOn(`stainless-core`)
//.dependsOn(inox % "it->test,it")
.configs(IntegrationTest)
.settings(commonSettings, commonFrontendSettings, scriptSettings)
lazy val `stainless-dotty-frontend` = (project in file("frontends/dotty"))
.settings(name := "stainless-dotty-frontend")
.dependsOn(`stainless-core`)
.settings(libraryDependencies += "ch.epfl.lamp" % "dotty_2.11" % dottyVersion % "provided")
.settings(commonSettings)
lazy val `stainless-dotty` = (project in file("frontends/stainless-dotty"))
.settings(
name := "stainless-dotty",
frontendClass := "dotc.DottyCompiler")
.dependsOn(`stainless-dotty-frontend`)
// Should truly depend on dotty, overriding the "provided" modifier above:
.settings(libraryDependencies += "ch.epfl.lamp" % "dotty_2.11" % dottyVersion)
.aggregate(`stainless-dotty-frontend`)
//.dependsOn(inox % "it->test,it")
.configs(IntegrationTest)
.settings(commonSettings, commonFrontendSettings, artifactSettings, scriptSettings)
lazy val root = (project in file("."))
.settings(scalaVersionSetting, sourcesInBase in Compile := false)
.dependsOn(`stainless-scalac`, `stainless-dotty`)
.aggregate(`stainless-core`, `stainless-scalac`, `stainless-dotty`)