forked from effekt-lang/effekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
225 lines (176 loc) · 6.7 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
import sbtcrossproject.CrossProject
import scalariform.formatter.preferences.AlignSingleLineCaseStatements.MaxArrowIndent
import scalariform.formatter.preferences._
import scala.sys.process.Process
// 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 assembleBinary = taskKey[Unit]("Assembles the effekt binary in bin/effekt")
lazy val effektVersion = "0.1.16"
lazy val noPublishSettings = Seq(
publish := {},
publishLocal := {},
)
lazy val commonSettings = Seq(
scalaVersion := "3.1.2",
scalacOptions ++= Seq(
"-encoding", "utf8",
"-deprecation",
"-unchecked",
// "-Xlint",
"-Xfatal-warnings",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions"
),
scalariformPreferences := scalariformPreferences.value
.setPreference(AlignSingleLineCaseStatements, true)
.setPreference(DoubleIndentClassDeclaration, true)
.setPreference(DanglingCloseParenthesis, Force)
.setPreference(NewlineAtEndOfFile, true)
.setPreference(MaxArrowIndent, 20)
)
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.2"
)
lazy val testingDependencies = Seq(
"org.scala-sbt" %% "io" % "1.6.0" % "test",
"org.scalatest" %% "scalatest" % "3.2.9" % "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 := false,
Test / watchTriggers += baseDirectory.value.toGlob / "libraries" / "**" / "*.effekt",
// show duration of the tests
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-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",
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("npm pack").!!
Process(s"npm install -g effekt-${effektVersion}.tgz").!!
},
generateLicenses := {
Process("mvn 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 version ${effektVersion} --no-git-tag-version --allow-same-version").!!
Process(s"mvn versions:set -DnewVersion=${effektVersion} -DgenerateBackupPoms=false").!!
},
Compile / sourceGenerators += versionGenerator.taskValue
)
.jsSettings(
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
// include all resource files in the virtual file system
Compile / sourceGenerators += stdLibGenerator.taskValue
)
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" / "js" / "monadic"
val resources = baseDir ** "*.*"
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).replaceAllLiterally("$", "$$")
s"""file(raw\"\"\"$filename\"\"\").write(raw\"\"\"$content\"\"\")"""
}
val scalaCode =
s"""
package effekt.util
import effekt.util.paths._
object Resources {
def load() = {
${virtuals.mkString("\n\n")}
}
}
"""
IO.write(sourceFile, scalaCode)
}
Seq(sourceFile)
}