Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Mill plugins also from build.mill{,.scala} files #3537

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading