-
Notifications
You must be signed in to change notification settings - Fork 24
/
build.sbt
285 lines (225 loc) · 8.89 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
import sbtcrossproject.CrossProject
import scala.sys.process.Process
import benchmarks._
import EffektVersion.effektVersion
// additional targets that can be used in sbt
lazy val deploy = taskKey[Unit]("Builds the jar and moves it to the bin folder")
lazy val generateLicenses = taskKey[Unit]("Analyses dependencies and downloads all licenses")
lazy val updateVersions = taskKey[Unit]("Update version in package.json and pom.xml")
lazy val install = taskKey[Unit]("Installs the current version locally")
lazy val assembleJS = taskKey[Unit]("Assemble the JS file in out/effekt.js")
lazy val assembleBinary = taskKey[Unit]("Assembles the effekt binary in bin/effekt")
lazy val generateDocumentation = taskKey[Unit]("Generates some documentation.")
lazy val bumpMinorVersion = taskKey[Unit]("Bumps the minor version number (used in CI).")
lazy val noPublishSettings = Seq(
publish := {},
publishLocal := {},
)
lazy val commonSettings = Seq(
scalaVersion := "3.3.1",
semanticdbEnabled := true,
scalacOptions ++= Seq(
"-encoding", "utf8",
"-deprecation",
"-unchecked",
// "-Xlint",
// "-Xcheck-macros",
"-Xfatal-warnings",
// we can use scalafix's organize imports once the next Scala version is out.
// https://github.com/scalacenter/scalafix/pull/1800
// "-Wunused:imports",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions"
)
)
enablePlugins(ScalaJSPlugin)
lazy val replDependencies = Seq(
"jline" % "jline" % "2.14.6",
"org.rogach" %% "scallop" % "4.1.0",
)
lazy val lspDependencies = Seq(
"org.eclipse.lsp4j" % "org.eclipse.lsp4j" % "0.12.0",
"com.google.code.gson" % "gson" % "2.8.9"
)
lazy val testingDependencies = Seq(
"org.scala-sbt" %% "io" % "1.6.0" % Test,
"org.scalameta" %% "munit" % "0.7.29" % Test
)
lazy val kiama: CrossProject = crossProject(JSPlatform, JVMPlatform).in(file("kiama"))
.settings(commonSettings)
.settings(noPublishSettings)
.settings(
name := "kiama"
)
.jvmSettings(
libraryDependencies ++= (replDependencies ++ lspDependencies)
)
lazy val root = project.in(file("effekt"))
.aggregate(effekt.js, effekt.jvm)
.settings(noPublishSettings)
.settings(Seq(
Compile / run := (effekt.jvm / Compile / run).evaluated
))
lazy val effekt: CrossProject = crossProject(JSPlatform, JVMPlatform).in(file("effekt"))
.settings(
name := "effekt",
version := effektVersion
)
.settings(commonSettings)
.dependsOn(kiama)
// .enablePlugins(NativeImagePlugin)
.jvmSettings(
libraryDependencies ++= (replDependencies ++ lspDependencies ++ testingDependencies),
// Test configuration
// ------------------
Test / parallelExecution := true,
Test / watchTriggers += baseDirectory.value.toGlob / "libraries" / "**" / "*.effekt",
// show duration of the tests
Test / testOptions += Tests.Argument(TestFrameworks.MUnit, "-oD"),
// disable tests for assembly to speed up build
assembly / test := {},
// Options to compile Effekt with native-image
// -------------------------------------------
// nativeImageOptions ++= Seq(
// "--no-fallback",
// "--initialize-at-build-time",
// "--report-unsupported-elements-at-runtime",
// "-H:+ReportExceptionStackTraces",
// "-H:IncludeResourceBundles=jline.console.completer.CandidateListCompletionHandler",
// "-H:ReflectionConfigurationFiles=../../native-image/reflect-config.json",
// "-H:DynamicProxyConfigurationFiles=../../native-image/dynamic-proxies.json"
// ),
// Assembling one big jar-file and packaging it
// --------------------------------------------
assembly / mainClass := Some("effekt.Server"),
assembly / assemblyJarName := "effekt.jar",
// we use the lib folder as resource directory to include it in the JAR
Compile / unmanagedResourceDirectories += (ThisBuild / baseDirectory).value / "libraries",
Compile / unmanagedResourceDirectories += (ThisBuild / baseDirectory).value / "licenses",
// cli flag so sbt doesn't crash when effekt does
addCommandAlias("run", "runMain effekt.Server --no-exit-on-error"),
assembleBinary := {
val jarfile = assembly.value
// prepend shebang to make jar file executable
val binary = (ThisBuild / baseDirectory).value / "bin" / "effekt"
IO.delete(binary)
IO.append(binary, "#! /usr/bin/env java -jar\n")
IO.append(binary, IO.readBytes(jarfile))
},
deploy := {
generateLicenses.value
updateVersions.value
assembleBinary.value
},
install := {
assembleBinary.value
Process(s"${npm.value} pack").!!
Process(s"${npm.value} install -g effekt-lang-effekt-${effektVersion}.tgz").!!
},
generateLicenses := {
Process(s"${mvn.value} license:download-licenses license:add-third-party").!!
val kiamaFolder = (ThisBuild / baseDirectory).value / "kiama"
val licenseFolder = (ThisBuild / baseDirectory).value / "licenses"
IO.copyFile(kiamaFolder / "LICENSE", licenseFolder / "kiama-license.txt")
IO.copyFile(kiamaFolder / "README.md", licenseFolder / "kiama-readme.txt")
},
updateVersions := {
Process(s"${npm.value} version ${effektVersion} --no-git-tag-version --allow-same-version").!!
Process(s"${mvn.value} versions:set -DnewVersion=${effektVersion} -DgenerateBackupPoms=false").!!
},
bumpMinorVersion := {
val versionPattern = """(\d+)\.(\d+)\.(\d+)""".r
val newVersion = effektVersion match {
case versionPattern(major, minor, patch) =>
s"$major.${minor.toInt + 1}.0"
case _ =>
sys.error(s"Invalid version format: $effektVersion")
}
val versionFile = (ThisBuild / baseDirectory).value / "project" / "EffektVersion.scala"
IO.write(versionFile,
s"""// Don't change this file without changing the CI too!
|import sbt.*
|import sbt.Keys.*
|object EffektVersion { lazy val effektVersion = "$newVersion" }
|""".stripMargin)
println(newVersion)
},
generateDocumentation := TreeDocs.replacer.value,
Compile / sourceGenerators += versionGenerator.taskValue,
Compile / sourceGenerators += TreeDocs.generator.taskValue,
collectBenchmarks := benchmarks.collect.value,
buildBenchmarks := benchmarks.build.value,
bench := benchmarks.measure.value
)
.jsSettings(
assembleJS := {
(Compile / clean).value
(Compile / compile).value
val jsFile = (Compile / fullOptJS).value.data
val outputFile = (ThisBuild / baseDirectory).value / "out" / "effekt.js"
IO.copyFile(jsFile, outputFile)
},
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.8.2" % "test",
testFrameworks += new TestFramework("utest.runner.Framework"),
// include all resource files in the virtual file system
Compile / sourceGenerators += stdLibGenerator.taskValue
)
lazy val platform = Def.task {
val platformString = System.getProperty("os.name").toLowerCase
if (platformString.contains("win")) "windows"
else if (platformString.contains("mac")) "macos"
else if (platformString.contains("linux")) "linux"
else sys error s"Unknown platform ${platformString}"
}
lazy val npm = Def.task {
if (platform.value == "windows") "npm.cmd" else "npm"
}
lazy val mvn = Def.task {
if (platform.value == "windows") "mvn.cmd" else "mvn"
}
lazy val versionGenerator = Def.task {
val sourceDir = (Compile / sourceManaged).value
val sourceFile = sourceDir / "effekt" / "util" / "Version.scala"
IO.write(sourceFile,
s"""package effekt.util
|
|object Version {
| val effektVersion = \"${effektVersion}\"
|}
|""".stripMargin)
Seq(sourceFile)
}
/**
* This generator is used by the JS version of our compiler to bundle the
* Effekt standard into the JS files and make them available in the virtual fs.
*/
lazy val stdLibGenerator = Def.task {
val baseDir = (ThisBuild / baseDirectory).value / "libraries"
val resources = baseDir.glob("common" || "js") ** "*.*"
val sourceDir = (Compile / sourceManaged).value
val sourceFile = sourceDir / "Resources.scala"
if (!sourceFile.exists() || sourceFile.lastModified() < baseDir.lastModified()) {
val virtuals = resources.get.map { file =>
val filename = file.relativeTo(baseDir).get
val content = IO.read(file).replace("$", "$$").replace("\"\"\"", "!!!MULTILINEMARKER!!!")
s"""loadIntoFile(raw\"\"\"$filename\"\"\", raw\"\"\"$content\"\"\")"""
}
val scalaCode =
s"""
package effekt.util
import effekt.util.paths._
object Resources {
def loadIntoFile(filename: String, contents: String): Unit =
file(filename).write(contents.replace("!!!MULTILINEMARKER!!!", "\\"\\"\\""))
def load() = {
${virtuals.mkString("\n\n")}
}
}
"""
IO.write(sourceFile, scalaCode)
}
Seq(sourceFile)
}