-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sc
330 lines (280 loc) · 10.1 KB
/
build.sc
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
import mill._
import mill.define._
import mill.scalalib._
import mill.scalalib.publish._
import mill.scalalib.scalafmt._
import coursier.MavenRepository
import java.nio.file.attribute.PosixFilePermission
import java.net.{URI, URL, URLClassLoader}
import mill.api.{Ctx, Result}
import mill.modules.Jvm
import mill.scalalib.api.CompilationResult
import mill.scalalib.Lib
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
import mill.contrib.buildinfo.BuildInfo
import $ivy.`com.lihaoyi::mill-contrib-scoverage:$MILL_VERSION`
import mill.contrib.scoverage.ScoverageModule
import mill.contrib.scoverage.ScoverageReport
import $ivy.`com.goyeau::mill-scalafix::0.2.8`
import com.goyeau.mill.scalafix.ScalafixModule
import $ivy.`io.github.davidgregory084::mill-tpolecat::0.3.0`
import io.github.davidgregory084.TpolecatModule
import $ivy.`com.github.tototoshi::scala-csv:1.3.6`
import com.github.tototoshi.csv._
trait PublishSettingsModule extends PublishModule {
def publishVersion = "0.1.0-SNAPSHOT"
def pomSettings = PomSettings(
description = artifactName(),
organization = "io.github.davidgregory084",
url = "https://github.com/DavidGregory084/inc",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github("DavidGregory084", "inc"),
developers = Seq(
Developer("DavidGregory084", "David Gregory", "https://github.com/DavidGregory084")
)
)
}
trait ScalaSettingsModule
extends TpolecatModule
with ScalafmtModule
with ScalafixModule
with PublishSettingsModule {
def scalaVersion = "2.13.8"
def catsVersion = T { "2.7.0" }
def munitVersion = T { "0.7.29" }
def pprintVersion = T { "0.7.0" }
def scalacPluginIvyDeps = Agg(
ivy"com.olegpy::better-monadic-for:0.3.1",
ivy"org.typelevel:::kind-projector:0.13.2",
ivy"org.scalameta:::semanticdb-scalac:4.5.0"
)
def scalafixIvyDeps = Agg(
ivy"com.github.liancheng::organize-imports:0.6.0"
)
def scalacOptions = T {
super.scalacOptions().filterNot(Set("-Xfatal-warnings")) ++ Seq(
"-Yno-imports",
"-Yrangepos"
// "-opt:l:method",
// "-opt:l:inline",
// Inlining Float.parseFloat and Double.parseDouble causes
// IllegalAccessError to jdk.internal.math.FloatingDecimal on JDK11
// "-opt-inline-from:**:!java.lang.Double:!java.lang.Float"
)
}
trait Test extends Tests with TestModule.Munit {
def ivyDeps = Agg(
ivy"org.scalameta::munit-scalacheck::${munitVersion()}",
ivy"io.chrisdavenport::cats-scalacheck:0.3.1",
ivy"com.lihaoyi::pprint:${pprintVersion()}",
ivy"com.github.pathikrit::better-files:3.9.1",
ivy"org.scalacheck::scalacheck:1.15.4"
)
def scalacOptions = T { super.scalacOptions().filterNot(Set("-Yno-imports")) }
}
}
object decompiled extends JavaModule {
def moduleDeps = Seq(rts)
}
object common extends ScalaSettingsModule with ScoverageModule {
def borerVersion = T { "1.7.2" }
def scoverageVersion = "1.4.11"
def ivyDeps = T {
super.ivyDeps() ++ Agg(
ivy"io.bullet::borer-core:${borerVersion()}",
ivy"io.bullet::borer-derivation:${borerVersion()}",
ivy"com.lihaoyi::pprint:${pprintVersion()}",
ivy"com.lihaoyi::sourcecode:0.2.8",
ivy"org.typelevel::cats-core:${catsVersion()}",
ivy"org.typelevel::paiges-core:0.4.2",
ivy"com.typesafe.scala-logging::scala-logging:3.9.4"
)
}
object test extends super.Test with ScoverageTests
}
object rts extends JavaModule with PublishSettingsModule
object parser extends ScalaSettingsModule with ScoverageModule {
def scoverageVersion = "1.4.11"
def moduleDeps = Seq(common)
def ivyDeps = Agg(ivy"com.lihaoyi::fastparse:2.3.3")
object test extends super.Test with ScoverageTests {
override def moduleDeps =
super.moduleDeps :+ common.test
}
}
object resolver extends ScalaSettingsModule with ScoverageModule {
def scoverageVersion = "1.4.11"
def moduleDeps = Seq(common)
object test extends super.Test with ScoverageTests {
override def moduleDeps =
super.moduleDeps :+ common.test
}
}
object typechecker extends ScalaSettingsModule with ScoverageModule {
def scoverageVersion = "1.4.11"
def moduleDeps = Seq(common)
object test extends super.Test with ScoverageTests {
override def moduleDeps =
super.moduleDeps :+ common.test
}
}
object codegen extends ScalaSettingsModule with ScoverageModule {
def scoverageVersion = "1.4.11"
def moduleDeps = Seq(common, rts)
def asmVersion = T { "9.2" }
def ivyDeps = Agg(
ivy"org.ow2.asm:asm:${asmVersion()}",
ivy"org.ow2.asm:asm-commons:${asmVersion()}",
ivy"org.ow2.asm:asm-util:${asmVersion()}"
)
object test extends super.Test with ScoverageTests {
override def moduleDeps =
super.moduleDeps :+ common.test
}
}
object main extends ScalaSettingsModule with ScoverageModule with BuildInfo {
def mainClass = Some("inc.main.Main")
def scoverageVersion = "1.4.11"
def moduleDeps = Seq(common, rts, parser, resolver, typechecker, codegen)
def jlineVersion = T { "3.21.0" }
def ivyDeps = Agg(
ivy"org.jline:jline-terminal:${jlineVersion()}",
ivy"org.jline:jline-terminal-jansi:${jlineVersion()}",
ivy"org.apache.logging.log4j:log4j-slf4j-impl:2.17.2",
ivy"com.github.scopt::scopt:4.0.1",
ivy"com.lihaoyi::pprint:${pprintVersion()}",
// PPrint definitely requires scala-reflect
ivy"org.scala-lang:scala-reflect:${scalaVersion()}"
)
def scalacOptions = T {
super.scalacOptions().filterNot(Set("-Yno-imports"))
}
def buildInfoPackageName = Some("inc.main")
def buildInfoObjectName = "Build"
def buildInfoMembers = T { Map("version" -> publishVersion()) }
// def shrinkBinary = T {
// val r8Conf = millSourcePath / up / "r8.conf"
// val outFile = T.dest / "out-r8.jar"
// Lib.resolveDependencies(
// repositories ++ Seq(MavenRepository("https://storage.googleapis.com/r8-releases/raw")),
// Lib.depToDependencyJava(_),
// Seq(ivy"com.android.tools:r8:2.1.66"),
// ).flatMap { dependencies =>
// try Result.Success(Jvm.runSubprocess(
// mainClass = "com.android.tools.r8.R8",
// classPath = dependencies.map(_.path),
// mainArgs = Seq(
// "--debug",
// "--classfile",
// "--pg-conf", r8Conf.toString,
// "--output", outFile.toString,
// "--lib", System.getProperty("java.home"),
// assembly().path.toString
// ),
// workingDir = T.dest
// )) catch {
// case e: Exception =>
// Result.Failure("shrinking with r8 failed")
// }
// }.map { _ =>
// PathRef(outFile)
// }
// }
def generateRunScript() = T.command {
// val shellScript = prependShellScript()
// val lineSep = if (!shellScript.endsWith("\n")) "\n\r\n" else ""
// val script = millSourcePath / up / "inc"
// if (exists! script) rm!(script)
// if (shellScript.isEmpty) {
// cp(shrinkBinary().path, script)
// } else {
// write(script, shellScript + lineSep)
// write.append(script, os.read.inputStream(shrinkBinary().path))
// if (!scala.util.Properties.isWin) {
// os.perms.set(
// script,
// os.perms(script) +
// PosixFilePermission.GROUP_EXECUTE +
// PosixFilePermission.OWNER_EXECUTE +
// PosixFilePermission.OTHERS_EXECUTE
// )
// }
// }
val script = millSourcePath / os.up / "inc"
os.copy.over(assembly().path, script)
}
object test extends super.Test with ScoverageTests {
override def moduleDeps =
super.moduleDeps :+ common.test
}
}
trait IncWorker {
def compile(files: Seq[PathRef], args: String*)(implicit ctx: Ctx): Result[Unit]
}
class IncWorkerImpl(classpath: Seq[PathRef]) extends IncWorker {
def compile(files: Seq[PathRef], args: String*)(implicit ctx: Ctx): Result[Unit] = {
val classpathUrls = classpath.map(_.path.toIO.toURI().toURL()).toArray[URL]
val classLoader = new URLClassLoader(classpathUrls, null)
val clazz = classLoader.loadClass("inc.main.Main")
val mainMethod = clazz.getMethod("main", classOf[Array[String]])
files
.map { f =>
Result.create(
mainMethod.invoke(null, (args :+ f.path.toIO.getAbsolutePath()).toArray[String])
)
}
.collectFirst {
case r @ Result.Exception(_, _) => r
case r @ Result.Aborted => Result.Aborted
case r @ Result.Skipped => Result.Skipped
case r @ Result.Failure(res, _) => Result.Failure(res, None)
}
.getOrElse(Result.Success())
}
}
trait IncModule extends ScalaModule {
override def moduleDeps =
super.moduleDeps :+ main
override def scalaVersion = main.scalaVersion()
override def allSourceFiles = T.sources {
for {
sources <- allSources()
if os.exists(sources.path)
path <- if (os.isDir(sources.path)) os.walk(sources.path) else Seq(sources.path)
if os.isFile(path) && !path.last.startsWith(".") && path.ext.toLowerCase == "inc"
} yield PathRef(path)
}
def incWorker: Worker[IncWorker] = T.worker {
new IncWorkerImpl(compileClasspath().toSeq)
}
override def compile: T[CompilationResult] = T.task {
val ctx = T.ctx()
val dest = ctx.dest
val classes = dest / "classes"
os.makeDir.all(classes)
val classpathString = compileClasspath()
.map(_.path.toIO.toURI().toURL())
.mkString(java.io.File.separator)
val compileResults = incWorker().compile(
allSourceFiles(),
"--classpath",
classpathString,
"--destination",
classes.toString,
"--exit-on-error",
"false"
)
val analysisFile = dest / "inc.analysis.dummy"
os.write(target = analysisFile, data = "", createFolders = true)
compileResults.map { _ => CompilationResult(analysisFile, PathRef(classes)) }
}
trait Test extends Tests with TestModule.Junit4
}
object bench extends IncModule {
override def allSources = T.sources { millSourcePath }
object test extends super.Test
}
object scoverage extends ScoverageReport {
override def scalaVersion = "2.13.8"
override def scoverageVersion = "1.4.11"
}