-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
build.mill
218 lines (193 loc) · 7.1 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
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.15"
val jna = ivy"net.java.dev.jna:jna:5.15.0"
val geny = ivy"com.lihaoyi::geny::1.1.1"
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 OsLibModule
extends CrossScalaModule
with PublishModule
with AcyclicModule
with SafeDeps
with PlatformScalaModule { outer =>
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 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 {
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 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)
}
}
}
}