Skip to content

Commit 25ee82e

Browse files
committed
Migrate from deprecated syntax from Mill <0.12
1 parent eea6725 commit 25ee82e

File tree

5 files changed

+92
-144
lines changed

5 files changed

+92
-144
lines changed

build.mill.scala

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import settings.{
1313
CliLaunchers,
1414
FormatNativeImageConf,
1515
HasTests,
16+
Licenses,
1617
LocalRepo,
1718
PublishLocalNoFluff,
1819
ScalaCliCrossSbtModule,
19-
ScalaCliSbtModule,
20-
ScalaCliScalafixModule,
2120
ScalaCliScalafixLegacyModule,
21+
ScalaCliScalafixModule,
2222
jvmPropertiesFileName,
2323
localRepoResourcePath,
2424
platformExecutableJarExtension,
@@ -31,7 +31,7 @@ import deps.alpineVersion
3131
import build.project.website
3232
import coursier.Repository
3333

34-
import java.io.File
34+
import java.io.{File, InputStream}
3535
import java.net.URL
3636
import java.nio.charset.Charset
3737
import java.util.Locale
@@ -43,6 +43,7 @@ import scalalib.{publish => _, _}
4343
import mill.contrib.bloop.Bloop
4444
import mill.testrunner.TestResult
4545
import os.{CommandResult, Path}
46+
import upickle.default.read
4647

4748
import _root_.scala.util.{Properties, Using}
4849
import _root_.scala.annotation.unused
@@ -349,8 +350,7 @@ trait BuildMacros extends ScalaCliCrossSbtModule
349350
val sv = scalaVersion()
350351
def compile(extraSources: os.Path*): CommandResult =
351352
os.proc("scala-cli", "compile", "-S", sv, cpsSource, extraSources).call(
352-
check =
353-
false,
353+
check = false,
354354
mergeErrIntoOut = true,
355355
cwd = Task.workspace
356356
)
@@ -1136,35 +1136,6 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
11361136
}
11371137
def generatedSources: Target[Seq[PathRef]] = super.generatedSources() ++ Seq(constantsFile())
11381138

1139-
def runTests(
1140-
launcherTask: T[PathRef],
1141-
cliKind: String,
1142-
args: String*
1143-
): Task[(String, Seq[TestResult])] = {
1144-
val argsTask = Task.Anon {
1145-
val launcher = launcherTask().path
1146-
val debugReg = "^--debug$|^--debug:([0-9]+)$".r
1147-
val debugPortOpt = args.find(debugReg.matches).flatMap {
1148-
case debugReg(port) => Option(port).orElse(Some("5005"))
1149-
case _ => None
1150-
}
1151-
val debugArgs = debugPortOpt match {
1152-
case Some(port) =>
1153-
System.err.println(
1154-
s"--debug option has been passed. Listening for transport dt_socket at address: $port"
1155-
)
1156-
Seq(s"-Dtest.scala-cli.debug.port=$port")
1157-
case _ => Seq.empty
1158-
}
1159-
val extraArgs = Seq(
1160-
s"-Dtest.scala-cli.path=$launcher",
1161-
s"-Dtest.scala-cli.kind=$cliKind"
1162-
)
1163-
args ++ extraArgs ++ debugArgs
1164-
}
1165-
testTask(argsTask, Task.Anon(Seq.empty[String]))
1166-
}
1167-
11681139
override def test(args: String*): Command[(String, Seq[TestResult])] = jvm(args: _*)
11691140

11701141
def forcedLauncher: Target[PathRef] = Task(persistent = true) {
@@ -1234,16 +1205,65 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
12341205
}
12351206
}
12361207

1237-
def jvm(args: String*): Command[(String, Seq[TestResult])] =
1238-
T.command(runTests(Launchers.jvm, "jvm", args: _*))
1239-
def jvmBootstrapped(args: String*): Command[(String, Seq[TestResult])] =
1240-
T.command(runTests(Launchers.jvmBootstrapped, "jvmBootstrapped", args: _*))
1241-
def native(args: String*): Command[(String, Seq[TestResult])] =
1242-
T.command(runTests(Launchers.native, "native", args: _*))
1243-
def nativeStatic(args: String*): Command[(String, Seq[TestResult])] =
1244-
T.command(runTests(Launchers.nativeStatic, "native-static", args: _*))
1245-
def nativeMostlyStatic(args: String*): Command[(String, Seq[TestResult])] =
1246-
T.command(runTests(Launchers.nativeMostlyStatic, "native-mostly-static", args: _*))
1208+
private def extraTestArgs(launcher: os.Path, cliKind: String): Seq[String] =
1209+
Seq(
1210+
s"-Dtest.scala-cli.path=$launcher",
1211+
s"-Dtest.scala-cli.kind=$cliKind"
1212+
)
1213+
1214+
private def debugTestArgs(args: Seq[String]): Seq[String] = {
1215+
val debugReg = "^--debug$|^--debug:([0-9]+)$".r
1216+
val debugPortOpt = args.find(debugReg.matches).flatMap {
1217+
case debugReg(port) => Option(port).orElse(Some("5005"))
1218+
case _ => None
1219+
}
1220+
debugPortOpt match {
1221+
case Some(port) =>
1222+
System.err.println(
1223+
s"--debug option has been passed. Listening for transport dt_socket at address: $port"
1224+
)
1225+
Seq(s"-Dtest.scala-cli.debug.port=$port")
1226+
case _ => Seq.empty
1227+
}
1228+
}
1229+
1230+
private def testArgs(args: Seq[String], launcher: os.Path, cliKind: String): Seq[String] =
1231+
extraTestArgs(launcher, cliKind) ++ debugTestArgs(args)
1232+
1233+
def jvm(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
1234+
testTask(
1235+
Task.Anon(args ++ testArgs(args, Launchers.jvm().path, "jvm")),
1236+
Task.Anon(Seq.empty[String])
1237+
)()
1238+
}
1239+
def jvmBootstrapped(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
1240+
testTask(
1241+
Task.Anon(args ++ testArgs(args, Launchers.jvmBootstrapped().path, "jvmBootstrapped")),
1242+
Task.Anon(Seq.empty[String])
1243+
)()
1244+
}
1245+
def native(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
1246+
testTask(
1247+
Task.Anon(args ++ testArgs(args, Launchers.native().path, "native")),
1248+
Task.Anon(Seq.empty[String])
1249+
)()
1250+
}
1251+
def nativeStatic(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
1252+
testTask(
1253+
Task.Anon(args ++ testArgs(args, Launchers.nativeStatic().path, "native-static")),
1254+
Task.Anon(Seq.empty[String])
1255+
)()
1256+
}
1257+
def nativeMostlyStatic(args: String*): Command[(String, Seq[TestResult])] = Task.Command {
1258+
testTask(
1259+
Task.Anon(args ++ testArgs(
1260+
args,
1261+
Launchers.nativeMostlyStatic().path,
1262+
"native-mostly-static"
1263+
)),
1264+
Task.Anon(Seq.empty[String])
1265+
)()
1266+
}
12471267
}
12481268
}
12491269

@@ -2053,7 +2073,3 @@ object ci extends Module {
20532073
)
20542074
}
20552075
}
2056-
2057-
def updateLicensesFile(): Command[Unit] = T.command {
2058-
settings.updateLicensesFile()
2059-
}

project/deps/package.mill.scala

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package build.project.deps
2-
import Deps.Versions
32
import mill._
43
import scalalib._
54

@@ -193,11 +192,10 @@ object Deps {
193192
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_2.13"))
194193
def dependency = ivy"io.get-coursier::dependency:0.3.2"
195194
def dockerClient = ivy"com.spotify:docker-client:8.16.0"
196-
// TODO bump once 0.15.5 is out
197-
def expecty = ivy"com.eed3si9n.expecty::expecty:0.17.0"
198-
def fansi = ivy"com.lihaoyi::fansi:0.5.0"
199-
def giter8 = ivy"org.foundweekends.giter8:giter8:0.16.2"
200-
def guava = ivy"com.google.guava:guava:33.4.8-jre"
195+
def expecty = ivy"com.eed3si9n.expecty::expecty:0.17.0"
196+
def fansi = ivy"com.lihaoyi::fansi:0.5.0"
197+
def giter8 = ivy"org.foundweekends.giter8:giter8:0.16.2"
198+
def guava = ivy"com.google.guava:guava:33.4.8-jre"
201199
def javaClassName =
202200
ivy"org.virtuslab.scala-cli.java-class-name:java-class-name_3:${Versions.javaClassName}"
203201
.exclude(
@@ -218,20 +216,18 @@ object Deps {
218216
ivy"com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-macros:${Versions.jsoniterScalaJava8}"
219217
def jsoniterMacrosJava8 =
220218
ivy"com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-macros:${Versions.jsoniterScalaJava8}"
221-
def jsoup = ivy"org.jsoup:jsoup:${Versions.jsoup}"
222-
def libsodiumjni = ivy"org.virtuslab.scala-cli:libsodiumjni:0.0.4"
223-
def macroParadise = ivy"org.scalamacros:::paradise:2.1.1"
219+
def jsoup = ivy"org.jsoup:jsoup:${Versions.jsoup}"
220+
def libsodiumjni = ivy"org.virtuslab.scala-cli:libsodiumjni:0.0.4"
224221
def metaconfigTypesafe =
225222
ivy"org.scalameta::metaconfig-typesafe-config:0.16.0"
226223
.exclude(("org.scala-lang", "scala-compiler"))
227-
def munit = ivy"org.scalameta::munit:1.1.1"
228-
def nativeTestRunner = ivy"org.scala-native::test-runner:${Versions.scalaNative}"
229-
def nativeTools = ivy"org.scala-native::tools:${Versions.scalaNative}"
230-
def osLib = ivy"com.lihaoyi::os-lib:0.11.3"
231-
def pprint = ivy"com.lihaoyi::pprint:0.9.0"
232-
def pythonInterface = ivy"io.github.alexarchambault.python:interface:0.1.0"
233-
def pythonNativeLibs = ivy"ai.kien::python-native-libs:0.2.4"
234-
def scala3Compiler(sv: String) = ivy"org.scala-lang:scala3-compiler_3:$sv"
224+
def munit = ivy"org.scalameta::munit:1.1.1"
225+
def nativeTestRunner = ivy"org.scala-native::test-runner:${Versions.scalaNative}"
226+
def nativeTools = ivy"org.scala-native::tools:${Versions.scalaNative}"
227+
def osLib = ivy"com.lihaoyi::os-lib:0.11.3"
228+
def pprint = ivy"com.lihaoyi::pprint:0.9.0"
229+
def pythonInterface = ivy"io.github.alexarchambault.python:interface:0.1.0"
230+
def pythonNativeLibs = ivy"ai.kien::python-native-libs:0.2.4"
235231
def scalaAsync = ivy"org.scala-lang.modules::scala-async:1.0.1".exclude("*" -> "*")
236232
def scalac(sv: String) = ivy"org.scala-lang:scala-compiler:$sv"
237233
def scalafmtCli = ivy"org.scalameta:scalafmt-cli_2.13:${Versions.scalafmt}"
@@ -285,7 +281,6 @@ object Deps {
285281
def toolkitTest = ivy"org.scala-lang:toolkit-test:$toolkitVersion"
286282
val typelevelToolkitVersion = "0.1.29"
287283
def typelevelToolkit = ivy"org.typelevel:toolkit:$typelevelToolkitVersion"
288-
def typelevelToolkitTest = ivy"org.typelevel:toolkit-test:$typelevelToolkitVersion"
289284
def usingDirectives = ivy"org.virtuslab:using_directives:1.1.4"
290285
// Lives at https://github.com/VirtusLab/no-crc32-zip-input-stream, see #865
291286
// This provides a ZipInputStream that doesn't verify CRC32 checksums, that users

project/publish/package.mill.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private def computePublishVersion(state: VcsState, simple: Boolean): String =
105105
.getOrElse(state.format())
106106
.stripPrefix("v")
107107

108-
def finalPublishVersion = {
108+
def finalPublishVersion: Target[String] = {
109109
val isCI = System.getenv("CI") != null
110110
if (isCI)
111111
Task(persistent = true) {

project/settings/package.mill.scala

Lines changed: 13 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import mill.scalalib._
2323
import os.{CommandResult, Path}
2424
import upickle.default._
2525

26-
import java.io.{File, InputStream}
26+
import java.io.File
2727
import java.nio.charset.StandardCharsets
2828
import java.util.Locale
2929
import scala.annotation.unused
@@ -62,7 +62,6 @@ def fromPath(name: String): String =
6262
name
6363

6464
def cs: Target[String] = Task(persistent = true) {
65-
6665
val arch = sys.props.getOrElse("os.arch", "").toLowerCase(Locale.ROOT)
6766
val ext = if (Properties.isWin) ".exe" else ""
6867
val csVersion = if (arch == "aarch64" && Properties.isMac) buildCsM1Version else buildCsVersion
@@ -124,19 +123,11 @@ def cs: Target[String] = Task(persistent = true) {
124123
}
125124
}
126125

127-
if (os.isFile(dest))
128-
dest.toString
129-
else
130-
downloadOpt().getOrElse(fromPath("cs")): String
126+
if (os.isFile(dest)) dest.toString
127+
else downloadOpt().getOrElse(fromPath("cs")): String
131128
}
132129

133-
def platformExtension: String =
134-
if (Properties.isWin) ".exe"
135-
else ""
136-
137-
def platformExecutableJarExtension: String =
138-
if (Properties.isWin) ".bat"
139-
else ""
130+
def platformExecutableJarExtension: String = if (Properties.isWin) ".bat" else ""
140131

141132
lazy val arch = sys.props("os.arch").toLowerCase(java.util.Locale.ROOT) match {
142133
case "amd64" => "x86_64"
@@ -153,12 +144,6 @@ def platformSuffix: String = {
153144

154145
def localRepoResourcePath = "local-repo.zip"
155146

156-
def getGhToken(): String =
157-
Option(System.getenv("UPLOAD_GH_TOKEN"))
158-
.getOrElse {
159-
sys.error("UPLOAD_GH_TOKEN not set")
160-
}
161-
162147
trait CliLaunchers extends SbtModule { self =>
163148

164149
def launcherTypeResourcePath: os.RelPath =
@@ -200,7 +185,7 @@ trait CliLaunchers extends SbtModule { self =>
200185
private def staticLibDirName = "native-libs"
201186

202187
private def copyCsjniutilTo(cs: String, destDir: os.Path, workspace: os.Path): Unit = {
203-
val jniUtilsVersion = Deps.jniUtils.dep.version
188+
val jniUtilsVersion = Deps.jniUtils.dep.versionConstraint.asString
204189
val libRes = os.proc(
205190
cs,
206191
"fetch",
@@ -213,7 +198,7 @@ trait CliLaunchers extends SbtModule { self =>
213198
os.copy.over(libPath, destDir / "csjniutils.lib")
214199
}
215200
private def copyLibsodiumjniTo(cs: String, destDir: os.Path, workspace: os.Path): Unit = {
216-
val libsodiumjniVersion = Deps.libsodiumjni.dep.version
201+
val libsodiumjniVersion = Deps.libsodiumjni.dep.versionConstraint.asString
217202
val (classifier, ext) = sys.props.get("os.arch") match {
218203
case Some("x86_64" | "amd64") =>
219204
if (Properties.isWin) ("x86_64-pc-win32", "lib")
@@ -445,7 +430,7 @@ trait CliLaunchers extends SbtModule { self =>
445430
stdin = os.Inherit,
446431
stdout = os.Inherit
447432
)
448-
Task.log.outputStream.println(s"Config generated in ${outputDir.relativeTo(Task.workspace)}")
433+
Task.log.streams.out.println(s"Config generated in ${outputDir.relativeTo(Task.workspace)}")
449434
}
450435

451436
@unused
@@ -595,7 +580,6 @@ trait PublishLocalNoFluff extends PublishModule {
595580
}
596581

597582
trait LocalRepo extends Module {
598-
599583
def stubsModules: Seq[PublishLocalNoFluff]
600584
def version: T[String]
601585

@@ -615,12 +599,12 @@ trait LocalRepo extends Module {
615599
VcsVersion.vcsState()
616600
}
617601
def localRepoZip: Target[PathRef] = Task {
618-
val repoVer = vcsState().format()
619-
val ver = version()
620-
val something = localRepo()
621-
val repoDir = Task.workspace / "out" / "repo" / ver
622-
val destDir = Task.dest / ver / "repo.zip"
623-
val dest = destDir / "repo.zip"
602+
val repoVer = vcsState().format()
603+
val ver = version()
604+
localRepo()
605+
val repoDir = Task.workspace / "out" / "repo" / ver
606+
val destDir = Task.dest / ver / "repo.zip"
607+
val dest = destDir / "repo.zip"
624608

625609
import java.io._
626610
import java.util.zip._
@@ -836,7 +820,6 @@ trait ScalaCliScalafixLegacyModule extends ScalaCliScalafixModule {
836820
}
837821

838822
trait ScalaCliCrossSbtModule extends CrossSbtModule with ScalaCliModule
839-
trait ScalaCliSbtModule extends SbtModule with ScalaCliModule
840823

841824
trait ScalaCliModule extends ScalaModule {
842825
def javacOptions: Target[Seq[String]] = super.javacOptions() ++ Seq(
@@ -865,49 +848,3 @@ case class Licenses(licenses: List[License])
865848
object Licenses {
866849
implicit val rw: ReadWriter[Licenses] = macroRW
867850
}
868-
869-
def updateLicensesFile() = T.task {
870-
val url = "https://github.com/spdx/license-list-data/raw/master/json/licenses.json"
871-
var is: InputStream = null
872-
val b =
873-
try {
874-
is = new java.net.URL(url).openStream()
875-
is.readAllBytes()
876-
}
877-
finally if (is != null) is.close()
878-
val content = new String(b, "UTF-8")
879-
880-
val licenses = read[Licenses](content).licenses
881-
882-
System.err.println(s"Found ${licenses.length} licenses")
883-
884-
val licensesCode = licenses
885-
.sortBy(_.licenseId)
886-
.map { license =>
887-
s""" License("${license.licenseId}", "${license.name.replace(
888-
"\"",
889-
"\\\""
890-
)}", "${license.reference}")"""
891-
}
892-
.mkString(",\n")
893-
894-
val genSource =
895-
s"""package scala.build.internal
896-
|
897-
|object Licenses {
898-
| // format: off
899-
| val list = Seq(
900-
|$licensesCode
901-
| )
902-
| // format: on
903-
|
904-
| lazy val map = list.map(l => l.id -> l).toMap
905-
|}
906-
|""".stripMargin
907-
908-
val dest =
909-
os.rel / "modules" / "build" / "src" / "main" / "scala" / "scala" / "build" / "internal" / "Licenses.scala"
910-
os.write.over(Task.workspace / dest, genSource)
911-
912-
System.err.println(s"Wrote $dest")
913-
}

0 commit comments

Comments
 (0)