From 16019d60ee66289dae8cdf10adb45b294e842c77 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 28 Aug 2024 14:05:32 +0800 Subject: [PATCH] Make Scalafix look for config in `T.workspace` rather than `os.pwd` (#199) --- .../goyeau/mill/scalafix/ScalafixModule.scala | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala b/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala index 289fe92..2448490 100644 --- a/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala +++ b/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala @@ -6,14 +6,14 @@ import mill.{Agg, T} import mill.api.{Logger, PathRef, Result} import mill.scalalib.{Dep, ScalaModule} import mill.define.Command -import os.* + import scalafix.interfaces.Scalafix import scalafix.interfaces.ScalafixError.* import scala.compat.java8.OptionConverters.* import scala.jdk.CollectionConverters.* trait ScalafixModule extends ScalaModule { - def scalafixConfig: T[Option[Path]] = T(None) + def scalafixConfig: T[Option[os.Path]] = T(None) def scalafixIvyDeps: T[Agg[Dep]] = Agg.empty[Dep] def scalafixScalaBinaryVersion: T[String] = "2.12" @@ -31,7 +31,8 @@ trait ScalafixModule extends ScalaModule { scalacOptions(), scalafixIvyDeps(), scalafixConfig(), - args* + args, + T.workspace ) } } @@ -40,21 +41,47 @@ object ScalafixModule { def fixAction( log: Logger, repositories: Seq[Repository], - sources: Seq[Path], - classpath: Seq[Path], + sources: Seq[os.Path], + classpath: Seq[os.Path], scalaVersion: String, scalaBinaryVersion: String, scalacOptions: Seq[String], scalafixIvyDeps: Agg[Dep], - scalafixConfig: Option[Path], + scalafixConfig: Option[os.Path], args: String* + ): Result[Unit] = fixAction( + log, + repositories, + sources, + classpath, + scalaVersion, + scalaBinaryVersion, + scalacOptions, + scalafixIvyDeps, + scalafixConfig, + args, + os.pwd + ) + + def fixAction( + log: Logger, + repositories: Seq[Repository], + sources: Seq[os.Path], + classpath: Seq[os.Path], + scalaVersion: String, + scalaBinaryVersion: String, + scalacOptions: Seq[String], + scalafixIvyDeps: Agg[Dep], + scalafixConfig: Option[os.Path], + args: Seq[String], + wd: os.Path ): Result[Unit] = if (sources.nonEmpty) { val scalafix = Scalafix .fetchAndClassloadInstance(scalaBinaryVersion, repositories.map(CoursierUtils.toApiRepository).asJava) .newArguments() .withParsedArguments(args.asJava) - .withWorkingDirectory(pwd.toNIO) + .withWorkingDirectory(wd.toNIO) .withConfig(scalafixConfig.map(_.toNIO).asJava) .withClasspath(classpath.map(_.toNIO).asJava) .withScalaVersion(scalaVersion)