forked from com-lihaoyi/mill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mill
More file actions
230 lines (200 loc) · 7.44 KB
/
build.mill
File metadata and controls
230 lines (200 loc) · 7.44 KB
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
//| mill-version: 1.1.3
//| mill-jvm-opts: ["-XX:NonProfiledCodeHeapSize=250m", "-XX:ReservedCodeCacheSize=500m"]
//| mill-opts: ["--jobs=0.5C", "-DMILL_ENABLE_STATIC_CHECKS=true"]
package build
import coursier.{MavenRepository, Repository}
import millbuild.*
import scala.language.reflectiveCalls
//import com.github.lolgab.mill.mima.Mima
import coursier.maven.MavenRepository
import coursier.VersionConstraint
import mill.util.VcsVersion
//import com.goyeau.mill.scalafix.ScalafixModule
import mill.*
import mill.util.Tasks
import mill.scalalib.*
import mill.javalib.api.JvmWorkerUtil
import mill.scalalib.publish.*
import mill.api.SelectMode
import mill.T
import mill.api.Cross
import scala.util.Properties
import mill.api.{BuildCtx, Evaluator}
import mill.androidlib.AndroidSdkModule
def millVersion: T[String] = Task.Input {
val vcsState = VcsVersion.calcVcsState(Task.log)
// Fall back to SNAPSHOT if no git tag found (e.g., shallow clone in CI)
if (vcsState.lastTag.isEmpty) "SNAPSHOT"
// Ignore local changes when computing the VCS version string in CI,
// since we make those in CI and can promise they are safe, but make
// sure we include local dirty changes when iterating locally.
else if (Task.env.contains("CI")) vcsState.copy(dirtyHash = None).format()
else vcsState.format()
}
def latestUnstableVersion = Task.Input {
val mavenMetadataXml = requests
.get("https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/maven-metadata.xml")
.text()
val xml = scala.xml.XML.loadString(mavenMetadataXml)
(xml \\ "version").map(_.text).last
}
def millLastTag: T[String] = Task.Input {
// Fall back to SNAPSHOT if no git tag found (e.g., shallow clone in CI)
VcsVersion.calcVcsState(Task.log).lastTag.getOrElse("SNAPSHOT")
}
def millDownloadPrefix = Task {
s"${Settings.mavenRepoUrl}/com/lihaoyi/mill-dist"
}
def millDownloadUrlCurrent = Task {
s"${millDownloadPrefix()}/${millVersion()}"
}
def millBinPlatform: T[String] = Task {
val tag = millLastTag()
tag match {
case s"$_.0.0-M$_" | s"$_.0.0-RC$_" => tag
case tag => tag.split('.').head
}
}
def defaultMillJvmVersion0 = Task.Source(BuildCtx.workspaceRoot / "default-mill-jvm-version")
def defaultMillJvmVersion = Task {
os.read(defaultMillJvmVersion0().path).trim()
}
val essentialBridgeScalaVersions =
Seq(Deps.scalaVersion, Deps.scala2Version, Deps.workerScalaVersion212)
// published compiler bridges
val bridgeScalaVersions = Seq(
// Our version of Zinc doesn't work with Scala 2.12.0 and 2.12.4 compiler
// bridges. We skip 2.12.1 because it's so old not to matter, and we need a
// non-supported scala version for testing purposes. We skip 2.13.0-2 because
// scaladoc fails on windows
/*"2.12.0",*/ /*2.12.1",*/ "2.12.2",
"2.12.3", /*"2.12.4",*/ "2.12.5",
"2.12.6",
"2.12.7",
"2.12.8",
"2.12.9",
"2.12.10",
"2.12.11",
"2.12.12",
"2.12.13",
"2.12.14",
"2.12.15",
"2.12.16",
"2.12.17",
"2.12.18",
"2.12.19",
/*"2.13.0", "2.13.1", "2.13.2",*/
"2.13.3",
"2.13.4",
"2.13.5",
"2.13.6",
"2.13.7",
"2.13.16",
"2.13.9",
"2.13.10",
"2.13.11",
"2.13.12",
"2.13.13",
"2.13.14",
"2.13.15",
"2.13.16"
)
// We limit the number of compiler bridges to compile and publish for local
// development and testing, because otherwise it takes forever to compile all
// of them. Compiler bridges not in this set will get downloaded and compiled
// on the fly anyway. For publishing, we publish everything or a specific version
// if given.
val compilerBridgeScalaVersions =
BuildCtx.watchValue(sys.env.get("MILL_COMPILER_BRIDGE_VERSIONS")) match {
case None | Some("") | Some("none") => Seq.empty[String]
case Some("all") => (essentialBridgeScalaVersions ++ bridgeScalaVersions).distinct
case Some("essential") => essentialBridgeScalaVersions
case Some(versions) => versions.split(',').map(_.trim()).filterNot(_.isEmpty).toSeq
}
val bridgeVersion = "0.0.1"
object bridge extends Cross[BridgeModule](compilerBridgeScalaVersions)
trait BridgeModule extends MillPublishCrossScalaModule {
def scalaVersion = crossScalaVersion
def publishVersion = bridgeVersion
def artifactName = "mill-scala-compiler-bridge"
def pomSettings = MillPublishJavaModule.commonPomSettings(artifactName())
def crossFullScalaVersion = true
def mvnDeps = Seq(
mvn"org.scala-sbt:compiler-interface:${Deps.zinc.version}",
mvn"org.scala-sbt:util-interface:${Deps.zinc.version}"
) ++ Seq(
if (JvmWorkerUtil.isScala3(crossScalaVersion))
mvn"org.scala-lang::scala3-compiler:${crossScalaVersion}"
else mvn"org.scala-lang:scala-compiler:${crossScalaVersion}"
)
def resources = Task {
os.copy(generatedSources().head.path / "META-INF", Task.dest / "META-INF")
Seq(PathRef(Task.dest))
}
def compilerBridgeMvnDeps: T[Seq[Dep]] = Seq(
(if (JvmWorkerUtil.isScala3(crossScalaVersion))
mvn"org.scala-lang:scala3-sbt-bridge:${crossScalaVersion}"
else mvn"org.scala-sbt::compiler-bridge:${Deps.zinc.version}").exclude("*" -> "*")
)
def compilerBridgeSourceJars: T[Seq[PathRef]] = Task {
defaultResolver().classpath(
compilerBridgeMvnDeps().map(bindDependency()),
sources = true
)
}
def generatedSources = Task {
compilerBridgeSourceJars().foreach { jar =>
os.unzip(jar.path, Task.dest)
}
Seq(PathRef(Task.dest))
}
}
def formatDep(dep: Dep) = {
val d = Lib.depToDependency(dep, Deps.scalaVersion)
s"${d.module.organization.value}:${d.module.name.value}:${d.versionConstraint.asString}"
}
def listCross(using ctx: mill.api.ModuleCtx) = BuildCtx.watchValue {
// millSourcePath is protected, so we need to access it via reflection
import scala.reflect.Selectable.reflectiveSelectable
os.list(ctx.asInstanceOf[{ def millSourcePath: os.Path }].millSourcePath).map(_.last)
}
val dummyDeps: Seq[Dep] = Seq(
Deps.DocDeps.millScip,
Deps.semanticDbJava_runtime,
Deps.semanticDBscala_runtime,
Deps.TestDeps.scalaTest,
Deps.TestDeps.zioTest,
Deps.acyclic,
mvn"io.get-coursier.jvm.indices:index-darwin-arm64:${Deps.coursierJvmIndexVersion}",
mvn"io.get-coursier.jvm.indices:index-linux-amd64:${Deps.coursierJvmIndexVersion}"
) ++ Deps.transitiveDeps ++ Deps.RuntimeDeps.updateable
implicit object DepSegment extends Cross.ToSegments[Dep]({ dep =>
val depString = formatDep(dep)
// these cross module names cause problems on windows, and anyway they
// are not necessary in order to load the project into IntelliJ anyway
List(depString.replace(':', '_'))
})
/**
* Dummy module(s) to let Dependency/showUpdates or Scala-Steward find
* and bump dependency versions we use at runtime
*/
object dummy extends Cross[DependencyFetchDummy](dummyDeps)
trait DependencyFetchDummy extends ScalaModule with Cross.Module[Dep] {
def scalaVersion = Deps.scala2Version
def compileMvnDeps = Seq(crossValue)
}
val androidDummyDeps: Seq[Dep] = Deps.AndroidDeps.updateable
object dummyAndroid extends Cross[AndroidDependencyFetchDummy](androidDummyDeps)
trait AndroidDependencyFetchDummy extends DependencyFetchDummy {
override def repositoriesTask: Task[Seq[Repository]] = Task.Anon {
super.repositoriesTask() :+ AndroidSdkModule.mavenGoogle
}
}
def visualizeMillModules(evaluator: Evaluator): Command[Unit] = Task.Command(exclusive = true) {
val allPublishModules = build.moduleInternal.modules.collect {
case m: MillPublishJavaModule => m
}
val modulePaths = allPublishModules.map(_.toString + ".compile")
evaluator.evaluate(Seq("visualize") ++ modulePaths, SelectMode.Separated)
()
}