Skip to content

Commit

Permalink
Extract Mill plugins also from build.mill{,.scala} files (#3537)
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas authored Jan 13, 2025
1 parent 721a674 commit fbf5c4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
override def name: String = "Mill"

override def containsBuild(buildRoot: BuildRoot): F[Boolean] =
workspaceAlg
.buildRootDir(buildRoot)
.flatMap(buildRootDir =>
Seq("build.sc", "build.mill", "build.mill.scala")
.map(buildRootDir / _)
.filterA(f => fileAlg.isRegularFile(f))
.map(_.nonEmpty)
)
workspaceAlg.buildRootDir(buildRoot).flatMap(findBuildFile).map(_.nonEmpty)

private def findBuildFile(buildRootDir: File): F[Option[File]] =
List("build.sc", "build.mill", "build.mill.scala")
.map(buildRootDir / _)
.findM(fileAlg.isRegularFile)

private def runMill(buildRootDir: File, millBuildVersion: Option[Version]): F[List[String]] =
millBuildVersion match {
Expand Down Expand Up @@ -103,7 +101,8 @@ final class MillAlg[F[_]](defaultResolver: Resolver)(implicit
buildRootDir: File
): F[Seq[Scope[List[Dependency]]]] =
for {
buildContent <- fileAlg.readFile(buildRootDir / "build.sc")
buildFile <- findBuildFile(buildRootDir)
buildContent <- buildFile.flatTraverse(fileAlg.readFile)
deps = buildContent.toList.map(content =>
Scope(parser.parseMillPluginDeps(content, millVersion), List(defaultResolver))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class MillAlgTest extends FunSuite {
test("getDependencies, version < 0.11") {
val repo = Repo("lihaoyi", "fastparse")
val buildRoot = BuildRoot(repo, ".")
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
val predef = s"$repoDir/scala-steward.sc"
val millCmd = Cmd.execSandboxed(repoDir, "mill", "-i", "-p", predef, "show", extractDeps)
val buildRootDir = workspaceAlg.buildRootDir(buildRoot).unsafeRunSync()
val predef = s"$buildRootDir/scala-steward.sc"
val millCmd = Cmd.execSandboxed(buildRootDir, "mill", "-i", "-p", predef, "show", extractDeps)
val initial =
MockState.empty.copy(commandOutputs = Map(millCmd -> Right(List("""{"modules":[]}"""))))
val state = millAlg.getDependencies(buildRoot).runS(initial).unsafeRunSync()
val expected = initial.copy(
trace = Vector(
Cmd("read", s"$repoDir/.mill-version"),
Cmd("read", s"$repoDir/.config/mill-version"),
Cmd("read", s"$buildRootDir/.mill-version"),
Cmd("read", s"$buildRootDir/.config/mill-version"),
Cmd("write", predef),
millCmd,
Cmd("rm", "-rf", predef)
Expand All @@ -34,10 +34,9 @@ class MillAlgTest extends FunSuite {
test("getDependencies, 0.11 <= version < 0.12") {
val repo = Repo("lihaoyi", "fastparse")
val buildRoot = BuildRoot(repo, ".")
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
val buildRootDir = workspaceAlg.buildRootDir(buildRoot).unsafeRunSync()
val millCmd = Cmd.execSandboxed(
repoDir,
buildRootDir,
"mill",
"--no-server",
"--disable-ticker",
Expand All @@ -46,19 +45,17 @@ class MillAlgTest extends FunSuite {
"show",
extractDeps
)
val initial =
MockState.empty
.copy(
commandOutputs = Map(millCmd -> Right(List("""{"modules":[]}""")))
)
.addFiles(buildRootDir / ".mill-version" -> "0.11.0")
.unsafeRunSync()
val initial = MockState.empty
.copy(commandOutputs = Map(millCmd -> Right(List("""{"modules":[]}"""))))
.addFiles(buildRootDir / ".mill-version" -> "0.11.0", buildRootDir / "build.sc" -> "")
.unsafeRunSync()
val state = millAlg.getDependencies(buildRoot).runS(initial).unsafeRunSync()
val expected = initial.copy(
trace = Vector(
Cmd("read", s"$repoDir/.mill-version"),
Cmd("read", s"$buildRootDir/.mill-version"),
millCmd,
Cmd("read", s"$repoDir/build.sc")
Cmd("test", "-f", s"$buildRootDir/build.sc"),
Cmd("read", s"$buildRootDir/build.sc")
)
)
assertEquals(state, expected)
Expand Down Expand Up @@ -87,8 +84,8 @@ class MillAlgTest extends FunSuite {
val expected = initial.copy(
trace = Vector(
Cmd("read", s"$buildRootDir/.mill-version"),
Cmd("read", s"$buildRootDir/.config/mill-version"),
millCmd,
Cmd("test", "-f", s"$buildRootDir/build.sc"),
Cmd("read", s"$buildRootDir/build.sc")
)
)
Expand Down

0 comments on commit fbf5c4b

Please sign in to comment.