-
-
Notifications
You must be signed in to change notification settings - Fork 390
/
Copy pathpackage.mill
299 lines (268 loc) · 12.3 KB
/
package.mill
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
package build.example
// imports
import scala.util.chaining._
import com.github.lolgab.mill.mima.Mima
import coursier.maven.MavenRepository
import de.tobiasroeser.mill.vcs.version.VcsVersion
import com.goyeau.mill.scalafix.ScalafixModule
import mill._
import mill.api.JarManifest
import mill.main.Tasks
import mill.scalalib._
import mill.scalalib.api.ZincWorkerUtil
import mill.scalalib.publish._
import mill.util.Jvm
import mill.resolve.SelectMode
import mill.contrib.buildinfo.BuildInfo
import mill.T
import mill.define.Cross
// plugins and dependencies
import $meta._
import $file.ci.shared
import $file.ci.upload
object `package` extends RootModule with Module {
def exampleModules: Seq[ExampleCrossModule] = millInternal
.modules
.collect { case m: ExampleCrossModule => m }
object android extends Module {
object javalib extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "javalib"))
object kotlinlib extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "kotlinlib"))
}
object javalib extends Module {
object basic extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "basic"))
object module extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "module"))
object dependencies extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "dependencies"))
object testing extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "testing"))
object linting extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "linting"))
object migrating extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "migrating"))
object publishing extends Cross[ExampleCrossModuleJava](build.listIn(millSourcePath / "publishing"))
object web extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "web"))
}
object kotlinlib extends Module {
object basic extends Cross[ExampleCrossModuleKotlin](build.listIn(millSourcePath / "basic"))
object module extends Cross[ExampleCrossModuleKotlin](build.listIn(millSourcePath / "module"))
object dependencies extends Cross[ExampleCrossModuleKotlin](build.listIn(millSourcePath / "dependencies"))
object testing extends Cross[ExampleCrossModuleKotlin](build.listIn(millSourcePath / "testing"))
object linting extends Cross[ExampleCrossModuleKotlin](build.listIn(millSourcePath / "linting"))
object publishing extends Cross[ExampleCrossModuleKotlin](build.listIn(millSourcePath / "publishing"))
object web extends Cross[ExampleCrossModuleKotlin](build.listIn(millSourcePath / "web"))
}
object scalalib extends Module {
object basic extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "basic"))
object module extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "module"))
object dependencies extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "dependencies"))
object testing extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "testing"))
object linting extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "linting"))
object publishing extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "publishing"))
object web extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "web"))
object native extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "native"))
}
object javascriptlib extends Module {
object basic extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "basic"))
}
object pythonlib extends Module {
object basic extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "basic"))
}
object cli extends Module{
object builtins extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "builtins"))
}
object fundamentals extends Module {
object dependencies extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "dependencies"))
object tasks extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "tasks"))
object modules extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "modules"))
object cross extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "cross"))
object `out-dir` extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "out-dir"))
object libraries extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "libraries"))
}
object depth extends Module {
object large extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "large"))
object sandbox extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "sandbox"))
object javahome extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "javahome"))
}
object extending extends Module {
object imports extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "imports"))
object metabuild extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "metabuild"))
object plugins extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "plugins"))
object jvmcode extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "jvmcode"))
object python extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "python"))
object typescript extends Cross[ExampleCrossModule](build.listIn(millSourcePath / "typescript"))
}
trait ExampleCrossModuleKotlin extends ExampleCrossModuleJava {
override def lineTransform(line: String) = this.millModuleSegments.parts.last match {
case "1-test-suite" => line
.replace("mill bar.test bar.BarTests.hello", "kotest_filter_tests='hello' kotest_filter_specs='bar.BarTests' ./mill bar.test")
.replace("compiling 1 ... source...", "Compiling 1 ... source...")
case _ => line
}
}
trait ExampleCrossModuleJava extends ExampleCrossModule {
def upstreamCross(s: String) = s match {
case "basic" => Some(scalalib.basic)
case "testing" => Some(scalalib.testing)
case "dependencies" => Some(scalalib.dependencies)
case "web" => Some(scalalib.web)
case _ => None
}
val upstreamOpt = upstreamCross(this.millModuleSegments.parts.dropRight(1).last)
.flatMap(_.valuesToModules.get(List(crossValue)))
def testRepoRoot = Task {
os.copy(super.testRepoRoot().path, T.dest, mergeFolders = true)
for(suffix <- Seq("build.sc", "build.mill", "build.mill.scala")){
for (lines <- buildScLines() if os.exists(T.dest / suffix)) {
os.write.over(T.dest / suffix, lines.mkString("\n"))
}
}
PathRef(T.dest)
}
def resources = upstreamOpt match {
case None => T{ Seq(super.testRepoRoot()) }
case Some(upstream) => T{
os.copy.over(super.testRepoRoot().path, T.dest)
val upstreamRoot = upstream.testRepoRoot().path
val suffix = Seq("build.sc", "build.mill").find(s => os.exists(upstreamRoot / s)).head
for(lines <- buildScLines()) {
os.write.over(T.dest / suffix, lines.mkString("\n"))
}
Seq(PathRef(T.dest))
}
}
def buildScLines = upstreamOpt match {
case None => T { None }
case Some(upstream) => T {
Some {
val upstreamRoot = upstream.testRepoRoot().path
val suffix = Seq("build.sc", "build.mill").find(s => os.exists(upstreamRoot / s)).head
val upstreamLines = os.read.lines(upstream.testRepoRoot().path / suffix)
val lines = os.read.lines(super.testRepoRoot().path / suffix)
import collection.mutable
val groupedLines = mutable.Map.empty[String, mutable.Buffer[String]]
var current = Option.empty[String]
lines.foreach {
case s"//// SNIPPET:$name" =>
current = Some(name)
groupedLines(name) = mutable.Buffer()
case s => current.foreach(groupedLines(_).append(lineTransform(s)))
}
current = None
upstreamLines.flatMap {
case s"//// SNIPPET:$name" =>
if (name != "END") {
current = Some(name)
groupedLines(name)
} else {
current = None
Nil
}
case s => if (current.nonEmpty) None else Some(lineTransform(s))
}
}
}
}
def lineTransform(line: String) = line
}
trait ExampleCrossModule extends build.integration.IntegrationTestModule {
// disable scalafix because these example modules don't have sources causing it to misbehave
def fix(args: String*): Command[Unit] = T.command {}
def testRepoRoot: T[PathRef] = Task.Source(millSourcePath)
def sources0 = Task.Sources(millSourcePath)
def sources = Task{
sources0()
.flatMap(pathRef => os.walk(pathRef.path))
.filter(os.isFile)
.filterNot(p =>
(p.ext == "java" || p.ext == "kt") &&
(p.segments.contains("linting") || p.segments.contains("10-external-module-aliases"))
)
.map(PathRef(_))
}
def resources = Seq(testRepoRoot())
def runClasspath = build.main.test.runClasspath()
def localRunClasspath = build.testkit.localRunClasspath()
def forkEnv = Map(
"LANG" -> "C"
)
/**
* Parses a `build.mill` for specific comments and return the split-by-type content
*/
def parsed: T[Seq[(String, String)]] = Task {
mill.testkit.ExampleParser(testRepoRoot().path)
}
def rendered = Task {
var seenCode = false
val examplePath = millSourcePath.subRelativeTo(T.workspace)
os.write(
T.dest / "example.adoc",
parsed()
.filter(_._2.nonEmpty)
.map {
case (s"see:$path", txt) =>
s"""
|.$path ({mill-example-url}/$examplePath/$path[browse])
|[source,scala,subs="attributes,verbatim"]
|----
|$txt
|----""".stripMargin
case ("scala", txt) =>
val title =
if (seenCode) ""
else {
val label = build.millLastTag()
val exampleDashed = examplePath.segments.mkString("-")
val download = s"{mill-download-url}/$label-$exampleDashed.zip[download]"
val browse = s"{mill-example-url}/$examplePath[browse]"
s".build.mill ($download, $browse)"
}
seenCode = true
s"""
|$title
|[source,scala,subs="attributes,verbatim"]
|----
|
|$txt
|----
|""".stripMargin
case ("comment", txt) => txt + "\n"
case ("example", txt) =>
s"""
|[source,bash,subs="attributes,verbatim"]
|----
|$txt
|----""".stripMargin
}
.mkString("\n")
)
PathRef(T.dest / "example.adoc")
}
}
def repoInfo = Map(
"acyclic" -> ("com-lihaoyi/acyclic", "1ec221f377794db39e8ff9b43415f81c703c202f"),
"fansi" -> ("com-lihaoyi/fansi", "169ac96d7c6761a72590d312a433cf12c572573c"),
"jimfs" -> ("google/jimfs", "5b60a42eb9d3cd7a2073d549bd0cb833f5a7e7e9"),
"commons-io" -> ("apache/commons-io", "b91a48074231ef813bc9b91a815d77f6343ff8f0"),
"netty" -> ("netty/netty", "20a790ed362a3c11e0e990b58598e4ac6aa88bef"),
"mockito" -> ("mockito/mockito", "97f3574cc07fdf36f1f76ba7332ac57675e140b1"),
"gatling" -> ("gatling/gatling", "3870fda86e6bca005fbd53108c60a65db36279b6"),
"arrow" -> ("arrow-kt/arrow", "bc9bf92cc98e01c21bdd2bf8640cf7db0f97204a")
)
object thirdparty extends Cross[ThirdPartyModule](build.listIn(millSourcePath / "thirdparty"))
trait ThirdPartyModule extends ExampleCrossModule {
val (repoPath, repoHash) = repoInfo(crossValue)
def repoSlug = repoPath.split("/").last
def testRepoRoot = Task {
shared.downloadTestRepo(repoPath, repoHash, T.dest)
val wrapperFolder = T.dest / s"$repoSlug-$repoHash"
os.makeDir(T.dest / "merged")
os.copy(wrapperFolder, T.dest / "merged", mergeFolders = true)
os.remove.all(wrapperFolder)
os.copy(
super.testRepoRoot().path,
T.dest / "merged",
mergeFolders = true,
replaceExisting = true
)
os.remove.all(T.dest / "merged" / ".mill-version")
os.remove.all(T.dest / "merged" / "build.sc")
PathRef(T.dest / "merged")
}
}
}