Skip to content

Commit 1391af1

Browse files
committed
Run Mill 0.11 with --disable-ticker instead of --ticker false
Running Mill 0.11 with `--ticker=false` (which has been added in #3511) produces the following error: ``` Parsing exception Position 1:9, found "=false" ``` The `--ticker <bool>` option has been added to Mill in 0.12.0 if I'm reading [this commit](com-lihaoyi/mill@0c44ffa) correctly. We therefore need to use `--disable-ticker` with Mill 0.11 and `--ticker false` with Mill >= 0.12.
1 parent 26f9dd0 commit 1391af1

File tree

2 files changed

+50
-21
lines changed

2 files changed

+50
-21
lines changed

modules/core/src/main/scala/org/scalasteward/core/buildtool/mill/MillAlg.scala

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,23 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
4545
.map(_.nonEmpty)
4646
)
4747

48-
private def runMill(buildRootDir: File) = {
49-
val options =
50-
List("--no-server", "--ticker=false", "--import", cliPluginCoordinate, "show", extractDeps)
51-
val command = Nel("mill", options)
52-
processAlg.execSandboxed(command, buildRootDir)
53-
}
54-
private def runMillUnder011(buildRootDir: File, millBuildVersion: Option[Version]) = {
55-
val predef = buildRootDir / "scala-steward.sc"
56-
val predefContent = content(millBuildVersion)
57-
val command = Nel("mill", List("-i", "-p", predef.toString, "show", extractDeps))
58-
fileAlg.createTemporarily(predef, predefContent).surround {
59-
processAlg.execSandboxed(command, buildRootDir)
48+
private def runMill(buildRootDir: File, millBuildVersion: Option[Version]): F[List[String]] =
49+
millBuildVersion match {
50+
case Some(v) if v >= Version("0.11") =>
51+
val noTicker =
52+
if (v >= Version("0.12")) List("--ticker", "false") else List("--disable-ticker")
53+
val options =
54+
"--no-server" :: noTicker ++ List("--import", cliPluginCoordinate, "show", extractDeps)
55+
val command = Nel("mill", options)
56+
processAlg.execSandboxed(command, buildRootDir)
57+
case _ =>
58+
val predef = buildRootDir / "scala-steward.sc"
59+
val predefContent = content(millBuildVersion)
60+
val command = Nel("mill", List("-i", "-p", predef.toString, "show", extractDeps))
61+
fileAlg.createTemporarily(predef, predefContent).surround {
62+
processAlg.execSandboxed(command, buildRootDir)
63+
}
6064
}
61-
}
6265

6366
override def getDependencies(buildRoot: BuildRoot): F[List[Scope.Dependencies]] =
6467
for {
@@ -79,9 +82,7 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
7982
millBuildVersion: Option[Version]
8083
): F[List[Scope.Dependencies]] =
8184
for {
82-
extracted <-
83-
if (isMillVersionGreaterOrEqual011(millBuildVersion)) runMill(buildRootDir)
84-
else runMillUnder011(buildRootDir, millBuildVersion)
85+
extracted <- runMill(buildRootDir, millBuildVersion)
8586
parsed <- F.fromEither(
8687
parser.parseModules(extracted.dropWhile(!_.startsWith("{")).mkString("\n"))
8788
)
@@ -113,9 +114,6 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
113114
}
114115

115116
object MillAlg {
116-
private[mill] def isMillVersionGreaterOrEqual011(millVersion: Option[Version]): Boolean =
117-
millMinVersion(millVersion).flatMap(_.toIntOption).exists(_ >= 11)
118-
119117
private[mill] def millMinVersion(millVersion: Option[Version]): Option[String] =
120118
millVersion.flatMap(_.value.trim.split("[.]", 3).take(2).lastOption)
121119

modules/core/src/test/scala/org/scalasteward/core/buildtool/mill/MillAlgTest.scala

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MillAlgTest extends FunSuite {
3131
assertEquals(state, expected)
3232
}
3333

34-
test("getDependencies, version >= 0.11") {
34+
test("getDependencies, 0.11 <= version < 0.12") {
3535
val repo = Repo("lihaoyi", "fastparse")
3636
val buildRoot = BuildRoot(repo, ".")
3737
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
@@ -40,7 +40,7 @@ class MillAlgTest extends FunSuite {
4040
repoDir,
4141
"mill",
4242
"--no-server",
43-
"--ticker=false",
43+
"--disable-ticker",
4444
"--import",
4545
"ivy:org.scala-steward::scala-steward-mill-plugin::0.18.0",
4646
"show",
@@ -65,6 +65,37 @@ class MillAlgTest extends FunSuite {
6565
assertEquals(state, expected)
6666
}
6767

68+
test("getDependencies, 0.12 <= version") {
69+
val repo = Repo("mill-alg", "test-3")
70+
val buildRoot = BuildRoot(repo, ".")
71+
val buildRootDir = workspaceAlg.buildRootDir(buildRoot).unsafeRunSync()
72+
val millCmd = Cmd.execSandboxed(
73+
buildRootDir,
74+
"mill",
75+
"--no-server",
76+
"--ticker",
77+
"false",
78+
"--import",
79+
"ivy:org.scala-steward::scala-steward-mill-plugin::0.18.0",
80+
"show",
81+
extractDeps
82+
)
83+
val initial = MockState.empty
84+
.copy(commandOutputs = Map(millCmd -> Right(List("""{"modules":[]}"""))))
85+
.addFiles(buildRootDir / ".mill-version" -> "0.12.5", buildRootDir / "build.sc" -> "")
86+
.unsafeRunSync()
87+
val state = millAlg.getDependencies(buildRoot).runS(initial).unsafeRunSync()
88+
val expected = initial.copy(
89+
trace = Vector(
90+
Cmd("read", s"$buildRootDir/.mill-version"),
91+
Cmd("read", s"$buildRootDir/.config/mill-version"),
92+
millCmd,
93+
Cmd("read", s"$buildRootDir/build.sc")
94+
)
95+
)
96+
assertEquals(state, expected)
97+
}
98+
6899
test("predef-content") {
69100
assert(MillAlg.content(None).contains("_mill$MILL_BIN_PLATFORM"))
70101
assert(MillAlg.content(Some(Version("0.6.1"))).contains("_mill0.6"))

0 commit comments

Comments
 (0)