-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathbuild.mill
272 lines (241 loc) · 9.4 KB
/
build.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
package build
// plugins
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import $ivy.`com.github.lolgab::mill-mima::0.1.1`
// imports
import mill._, scalalib._, scalanativelib._, publish._
import mill.scalalib.api.ZincWorkerUtil
import com.github.lolgab.mill.mima._
import de.tobiasroeser.mill.vcs.version.VcsVersion
val communityBuildDottyVersion = sys.props.get("dottyVersion").toList
val scala213Version = "2.13.14"
val scalaVersions = Seq(
"3.3.1",
"2.12.17",
scala213Version
) ++ communityBuildDottyVersion
object Deps {
val acyclic = ivy"com.lihaoyi:::acyclic:0.3.18"
val jna = ivy"net.java.dev.jna:jna:5.15.0"
val geny = ivy"com.lihaoyi::geny::1.1.1"
val ant = ivy"org.apache.ant:ant:1.10.15"
val sourcecode = ivy"com.lihaoyi::sourcecode::0.4.2"
val utest = ivy"com.lihaoyi::utest::0.8.4"
val expecty = ivy"com.eed3si9n.expecty::expecty::0.16.0"
def scalaReflect(scalaVersion: String) = ivy"org.scala-lang:scala-reflect:$scalaVersion"
def scalaLibrary(version: String) = ivy"org.scala-lang:scala-library:${version}"
}
trait AcyclicModule extends ScalaModule {
def acyclicDep: T[Agg[Dep]] = T {
Agg.from(Option.when(!ZincWorkerUtil.isScala3(scalaVersion()))(Deps.acyclic))
}
def acyclicOptions: T[Seq[String]] = T {
Option.when(!ZincWorkerUtil.isScala3(scalaVersion()))("-P:acyclic:force").toSeq
}
def compileIvyDeps = acyclicDep
def scalacPluginIvyDeps = acyclicDep
def scalacOptions = super.scalacOptions() ++ acyclicOptions()
}
trait SafeDeps extends ScalaModule {
def mapDependencies: Task[coursier.Dependency => coursier.Dependency] = T.task {
val sd = Deps.scalaLibrary(scala213Version)
super.mapDependencies().andThen { d =>
// enforce up-to-date Scala 2.13.x version
if (d.module == sd.dep.module && d.version.startsWith("2.13.")) sd.dep
else d
}
}
}
trait MiMaChecks extends Mima {
def mimaPreviousVersions =
Seq(
"0.9.0",
"0.9.1",
"0.9.2",
"0.9.3",
"0.10.0",
"0.10.1",
"0.10.2",
"0.10.3",
"0.10.4",
"0.10.5",
"0.10.6"
)
override def mimaBinaryIssueFilters: T[Seq[ProblemFilter]] = Seq(
ProblemFilter.exclude[ReversedMissingMethodProblem]("os.PathConvertible.isCustomFs"),
// this is fine, because ProcessLike is sealed (and its subclasses should be final)
ProblemFilter.exclude[ReversedMissingMethodProblem]("os.ProcessLike.joinPumperThreadsHook")
)
override def mimaExcludeAnnotations: T[Seq[String]] = Seq(
"os.experimental"
)
}
trait OsLibPublishModule extends PublishModule {
def publishVersion = VcsVersion.vcsState().format()
def pomSettings = PomSettings(
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/com-lihaoyi/os-lib",
licenses = Seq(License.MIT),
versionControl = VersionControl.github(
owner = "com-lihaoyi",
repo = "os-lib"
),
developers = Seq(
Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")
)
)
}
trait OsLibModule
extends OsLibPublishModule
with CrossScalaModule
with AcyclicModule
with SafeDeps
with PlatformScalaModule { outer =>
trait OsLibTestModule extends ScalaModule with TestModule.Utest with SafeDeps {
def ivyDeps = Agg(Deps.utest, Deps.sourcecode)
// we check the textual output of system commands and expect it in english
def forkEnv = super.forkEnv() ++ Map(
"LC_ALL" -> "C",
"TEST_SUBPROCESS_ENV" -> "value",
"OS_TEST_RESOURCE_FOLDER" -> os.jvm(crossValue).test.resources().head.path.toString
)
}
}
trait OsModule extends OsLibModule { outer =>
def ivyDeps = Agg(Deps.geny)
override def compileIvyDeps = T {
val scalaReflectOpt = Option.when(!ZincWorkerUtil.isDottyOrScala3(scalaVersion()))(
Deps.scalaReflect(scalaVersion())
)
super.compileIvyDeps() ++ scalaReflectOpt
}
def artifactName = "os-lib"
val scalaDocExternalMappings = Seq(
".*scala.*::scaladoc3::https://scala-lang.org/api/3.x/",
".*java.*::javadoc::https://docs.oracle.com/javase/8/docs/api/",
s".*geny.*::scaladoc3::https://javadoc.io/doc/com.lihaoyi/geny_3/${Deps.geny.dep.version}/"
).mkString(",")
def conditionalScalaDocOptions: T[Seq[String]] = T {
if (ZincWorkerUtil.isDottyOrScala3(scalaVersion()))
Seq(
s"-external-mappings:${scalaDocExternalMappings}"
)
else Seq()
}
def scalaDocOptions = super.scalaDocOptions() ++ conditionalScalaDocOptions()
def generatedSources = T {
val conversions = for (i <- Range.inclusive(2, 22)) yield {
val ts = Range.inclusive(1, i).map(n => s"T$n").mkString(", ")
val fs = Range.inclusive(1, i).map(n => s"f$n: T$n => R").mkString(", ")
val vs = Range.inclusive(1, i).map(n => s"f$n(t._$n)").mkString(", ")
s""" implicit def tuple${i}Conversion[$ts]
| (t: ($ts))
| (implicit $fs): R = {
| this.flatten($vs)
| }
|""".stripMargin
}
_root_.os.write(
T.dest / "os" / "GeneratedTupleConversions.scala",
s"""package os
|trait GeneratedTupleConversions[R]{
| protected def flatten(vs: R*): R
| ${conversions.mkString("\n")}
|}
|
|""".stripMargin,
createFolders = true
)
Seq(PathRef(T.dest))
}
}
object os extends Module {
object jvm extends Cross[OsJvmModule](scalaVersions)
trait OsJvmModule extends OsModule with MiMaChecks {
def moduleDeps = super.moduleDeps ++ Seq(os.zip)
object test extends ScalaTests with OsLibTestModule {
override def ivyDeps = T { super.ivyDeps() ++ Agg(Deps.expecty) }
// we check the textual output of system commands and expect it in english
def forkEnv = super.forkEnv() ++ Map(
"TEST_JAR_WRITER_ASSEMBLY" -> testJarWriter.assembly().path.toString,
"TEST_JAR_READER_ASSEMBLY" -> testJarReader.assembly().path.toString,
"TEST_JAR_EXIT_ASSEMBLY" -> testJarExit.assembly().path.toString,
"TEST_SPAWN_EXIT_HOOK_ASSEMBLY" -> testSpawnExitHook.assembly().path.toString,
"TEST_SPAWN_EXIT_HOOK_ASSEMBLY2" -> testSpawnExitHook2.assembly().path.toString
)
object testJarWriter extends JavaModule
object testJarReader extends JavaModule
object testJarExit extends JavaModule
object testSpawnExitHook extends ScalaModule{
def scalaVersion = OsJvmModule.this.scalaVersion()
def moduleDeps = Seq(OsJvmModule.this)
}
object testSpawnExitHook2 extends JavaModule
}
object nohometest extends ScalaTests with OsLibTestModule
}
object zip extends JavaModule with OsLibPublishModule {
def apacheAntZipOriginalSource: T[PathRef] = Task(persistent = true) {
if (!_root_.os.exists(Task.dest / "unzipped")) {
val antVersion = Deps.ant.version
_root_.os.unzip.stream(
requests.get.stream(
s"https://repo1.maven.org/maven2/org/apache/ant/ant/$antVersion/ant-$antVersion-sources.jar"
),
Task.dest / "unzipped"
)
}
PathRef(Task.dest / "unzipped" / "org/apache/tools/zip")
}
/**
* Shades Apache Ant
* [[`org.apache.tools.zip` https://ant.apache.org/manual/api/org/apache/tools/zip/package-summary.html package]] to
* provide Unix file permission and symbolic link support for `os.zip` and `os.unzip`
*
* A third party dependency is needed since JDK's own
* [[`jdk.zipfs` https://docs.oracle.com/en/java/javase/14/docs/api/jdk.zipfs/module-summary.html]] does not support
* symbolic links and only supports file permissions since JDK 14.
*
* Apache Ant `org.apache.tools.zip` was chosen over Apache Commons Compress due to the former not having any
* third party dependency, only depending on Java core libraries while the later also depends on Apache Commons IO.
*
* To avoid classpath conflicts, the dependency is shaded and compiled from source. Only the `org.apache.tools.zip`
* package, not the entire Ant codebase, is needed. This only adds < 100kb to Os-Lib jar size.
*/
def generatedSources = T {
val pkg = "os.shaded_org_apache_tools_zip"
val zipSrc = T.dest / "os/shaded_org_apache_tools_zip"
_root_.os.makeDir.all(zipSrc)
// Move from "package org.apache.tools.zip" to "package os.shaded_org_apache_tools_zip"
// Make all classes package private (private [os]) by removing any `public` access modifier
_root_.os.walk.stream(apacheAntZipOriginalSource().path)
.filter(_.ext == "java")
.foreach { p =>
val content = _root_.os.read(p)
.replaceAll("org.apache.tools.zip", pkg)
_root_.os.write(zipSrc / p.last, content)
}
Seq(PathRef(T.dest))
}
}
/*object native extends Cross[OsNativeModule](scalaVersions)
trait OsNativeModule extends OsModule with ScalaNativeModule {
def scalaNativeVersion = "0.5.2"
object test extends ScalaNativeTests with OsLibTestModule {
def nativeLinkStubs = true
}
object nohometest extends ScalaNativeTests with OsLibTestModule
}*/
object watch extends Module {
object jvm extends Cross[WatchJvmModule](scalaVersions)
trait WatchJvmModule extends OsLibModule {
def artifactName = "os-lib-watch"
def moduleDeps = super.moduleDeps ++ Seq(os.jvm())
def ivyDeps = Agg(Deps.jna)
object test extends ScalaTests with OsLibTestModule {
def moduleDeps = super.moduleDeps ++ Seq(os.jvm().test)
}
}
}
}