From 1af99f568340c6079bc9beba116a396c3067b317 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 23 Jan 2022 12:17:37 +0100 Subject: [PATCH 1/9] Explicit handling of scalac plugins and related enablement options We no longer generate an enablement option for each transitively resolved plugin jar, but instead, only generated an -Xplugin option for each explicitly given plugin. This will fix previously seen warnings for the scalac compiler. --- scalalib/src/ScalaModule.scala | 11 +++++++++- .../mill/scalalib/worker/ZincWorkerImpl.scala | 22 +++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala index 93df5a4796b..d1240746a28 100644 --- a/scalalib/src/ScalaModule.scala +++ b/scalalib/src/ScalaModule.scala @@ -104,6 +104,14 @@ trait ScalaModule extends JavaModule { outer => */ protected def mandatoryScalacOptions = T { Seq.empty[String] } + /** + * Scalac options to active the compiler plugins. + */ + protected def enablePluginScalacOption: Target[Seq[String]] = T { + val resolvedJars = resolveDeps(scalacPluginIvyDeps.map(_.map(_.exclude("*" -> "*"))))() + resolvedJars.iterator.toSeq.map(jar => s"-Xplugin:${jar}") + } + /** * Command-line options to pass to the Scala compiler defined by the user. * Consumers should use `allScalacOptions` to read them. @@ -114,7 +122,8 @@ trait ScalaModule extends JavaModule { outer => * Aggregation of all the options passed to the Scala compiler. * In most cases, instead of overriding this Target you want to override `scalacOptions` instead. */ - def allScalacOptions = T { mandatoryScalacOptions() ++ scalacOptions() } + def allScalacOptions = + T { mandatoryScalacOptions() ++ enablePluginScalacOption() ++ scalacOptions() } def scalaDocOptions: T[Seq[String]] = T { val defaults = diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala index 15515254b4c..e0b331886e5 100644 --- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala +++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala @@ -309,19 +309,19 @@ class ZincWorkerImpl( reporter: Option[CompileProblemReporter] )(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[(os.Path, os.Path)] = { withCompilers( - scalaVersion, - scalaOrganization, - compilerClasspath, - scalacPluginClasspath + scalaVersion = scalaVersion, + scalaOrganization = scalaOrganization, + compilerClasspath = compilerClasspath, + scalacPluginClasspath = scalacPluginClasspath ) { compilers: Compilers => compileInternal( - upstreamCompileOutput, - sources, - compileClasspath, - javacOptions, - scalacOptions = scalacPluginClasspath.map(jar => s"-Xplugin:$jar").toSeq ++ scalacOptions, - compilers, - reporter + upstreamCompileOutput = upstreamCompileOutput, + sources = sources, + compileClasspath = compileClasspath, + javacOptions = javacOptions, + scalacOptions = scalacOptions, + compilers = compilers, + reporter = reporter ) } } From b9a11a7ea8925b1e3d9f3e6f0de6492f0fe40564 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 23 Jan 2022 19:27:24 +0100 Subject: [PATCH 2/9] More thorough review of options processing --- bsp/src/mill/bsp/MillScalaBuildServer.scala | 4 +-- scalalib/src/ScalaModule.scala | 38 ++++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/bsp/src/mill/bsp/MillScalaBuildServer.scala b/bsp/src/mill/bsp/MillScalaBuildServer.scala index e8ccec9f1eb..710e3fd409d 100644 --- a/bsp/src/mill/bsp/MillScalaBuildServer.scala +++ b/bsp/src/mill/bsp/MillScalaBuildServer.scala @@ -37,9 +37,7 @@ trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildServer => ) { case (id, m: JavaModule) => val optionsTask = m match { - case sm: ScalaModule => T.task { - sm.allScalacOptions() ++ sm.scalacPluginClasspath().map(jar => s"-Xplugin:$jar") - } + case sm: ScalaModule => sm.allScalacOptions case _ => T.task { Seq.empty[String] } } diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala index d1240746a28..632166261a6 100644 --- a/scalalib/src/ScalaModule.scala +++ b/scalalib/src/ScalaModule.scala @@ -2,9 +2,8 @@ package mill package scalalib import scala.annotation.nowarn - import mill.define.{Command, Sources, Target, Task} -import mill.api.{DummyInputStream, PathRef, Result, internal} +import mill.api.{DummyInputStream, Loose, PathRef, Result, internal} import mill.modules.Jvm import mill.modules.Jvm.createJar import Lib._ @@ -13,8 +12,8 @@ import mill.api.Loose.Agg import mill.eval.{Evaluator, EvaluatorPathsResolver} import mill.scalalib.api.{CompilationResult, ZincWorkerUtil} import mill.scalalib.bsp.{BspBuildTarget, BspModule} -import scala.jdk.CollectionConverters._ +import scala.jdk.CollectionConverters._ import mainargs.Flag /** @@ -86,7 +85,7 @@ trait ScalaModule extends JavaModule { outer => publish.Artifact.fromDep( _: Dep, scalaVersion(), - mill.scalalib.api.Util.scalaBinaryVersion(scalaVersion()), + ZincWorkerUtil.scalaBinaryVersion(scalaVersion()), platformSuffix() ) } @@ -94,36 +93,45 @@ trait ScalaModule extends JavaModule { outer => /** * Allows you to make use of Scala compiler plugins from maven central */ - def scalacPluginIvyDeps = T { Agg.empty[Dep] } + def scalacPluginIvyDeps: Target[Agg[Dep]] = T { Agg.empty[Dep] } - def scalaDocPluginIvyDeps = T { scalacPluginIvyDeps() } + def scalaDocPluginIvyDeps: Target[Agg[Dep]] = T { scalacPluginIvyDeps() } /** * Mandatory command-line options to pass to the Scala compiler * that shouldn't be removed by overriding `scalacOptions` */ - protected def mandatoryScalacOptions = T { Seq.empty[String] } + protected def mandatoryScalacOptions: Target[Seq[String]] = T { Seq.empty[String] } /** * Scalac options to active the compiler plugins. */ - protected def enablePluginScalacOption: Target[Seq[String]] = T { + private def enablePluginScalacOptions: Target[Seq[String]] = T { val resolvedJars = resolveDeps(scalacPluginIvyDeps.map(_.map(_.exclude("*" -> "*"))))() - resolvedJars.iterator.toSeq.map(jar => s"-Xplugin:${jar}") + resolvedJars.iterator.map(jar => s"-Xplugin:${jar.path}").toSeq + } + + /** + * Scalac options to active the compiler plugins. + */ + private def enableScalaDocPluginScalacOption: Target[Seq[String]] = T { + val resolvedJars = resolveDeps(scalaDocPluginIvyDeps.map(_.map(_.exclude("*" -> "*"))))() + resolvedJars.iterator.map(jar => s"-Xplugin:${jar.path}").toSeq } /** * Command-line options to pass to the Scala compiler defined by the user. * Consumers should use `allScalacOptions` to read them. */ - def scalacOptions = T { Seq.empty[String] } + def scalacOptions: Target[Seq[String]] = T { Seq.empty[String] } /** * Aggregation of all the options passed to the Scala compiler. * In most cases, instead of overriding this Target you want to override `scalacOptions` instead. */ - def allScalacOptions = - T { mandatoryScalacOptions() ++ enablePluginScalacOption() ++ scalacOptions() } + def allScalacOptions: Target[Seq[String]] = T { + mandatoryScalacOptions() ++ enablePluginScalacOptions() ++ scalacOptions() + } def scalaDocOptions: T[Seq[String]] = T { val defaults = @@ -133,7 +141,7 @@ trait ScalaModule extends JavaModule { outer => artifactName() ) else Seq() - allScalacOptions() ++ defaults + mandatoryScalacOptions() ++ enableScalaDocPluginScalacOption() ++ scalacOptions() ++ defaults } /** @@ -232,8 +240,6 @@ trait ScalaModule extends JavaModule { outer => } override def docJar: T[PathRef] = T { - val pluginOptions = - scalaDocPluginClasspath().map(pluginPathRef => s"-Xplugin:${pluginPathRef.path}") val compileCp = Seq( "-classpath", compileClasspath() @@ -252,7 +258,7 @@ trait ScalaModule extends JavaModule { outer => scalaOrganization(), scalaDocClasspath().map(_.path), scalacPluginClasspath().map(_.path), - files ++ options ++ pluginOptions ++ compileCp ++ scalaDocOptions() + files ++ options ++ compileCp ++ scalaDocOptions() ) match { case true => Result.Success(createJar(Agg(javadocDir))(T.dest)) From 52f33dec70f9511bb8a44ce86fc26f8a72b460d6 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 23 Jan 2022 19:49:42 +0100 Subject: [PATCH 3/9] Removed special plugin handling from BloopImpl --- contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala b/contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala index f402ca746ce..ba7ab72e186 100644 --- a/contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala +++ b/contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala @@ -173,19 +173,12 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer val scalaConfig = module match { case s: ScalaModule => T.task { - val pluginCp = s.scalacPluginClasspath() - val pluginOptions = pluginCp.map { pathRef => - s"-Xplugin:${pathRef.path}" - } - - val allScalacOptions = - (s.allScalacOptions() ++ pluginOptions).toList Some( BloopConfig.Scala( organization = s.scalaOrganization(), name = "scala-compiler", version = s.scalaVersion(), - options = allScalacOptions, + options = s.allScalacOptions().toList, jars = s.scalaCompilerClasspath().map(_.path.toNIO).toList, analysis = None, setup = None From 65948e0c26f5ce148c32fa866bc1b1b345337a5f Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 23 Jan 2022 19:56:54 +0100 Subject: [PATCH 4/9] Fix build by explicitly adding plugin enablement Until now, we inferred this option in the ZincWorker, but now, we infer it in ScalaModule from the ivy deps. But here, we use a plugin from modules, which isn't supported out of the box. --- build.sc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build.sc b/build.sc index c84e90a460f..15e5f8c3b34 100755 --- a/build.sc +++ b/build.sc @@ -199,11 +199,16 @@ trait MillInternalModule def scalaVersion = Deps.scalaVersion override def ammoniteVersion = Deps.ammonite.dep.version } + trait MillApiModule extends MillInternalModule with MillMimaConfig trait MillModule extends MillApiModule { outer => - override def scalacPluginClasspath = + override def scalacPluginClasspath = T { super.scalacPluginClasspath() ++ Seq(main.moduledefs.jar()) + } + override def scalacOptions = T { + super.scalacOptions() ++ Seq(s"-Xplugin:${main.moduledefs.jar()}") + } def testArgs = T { Seq.empty[String] } def testIvyDeps: T[Agg[Dep]] = Agg(Deps.utest) @@ -216,8 +221,12 @@ trait MillModule extends MillApiModule { outer => else Seq(outer, main.test) override def ivyDeps: T[Agg[Dep]] = outer.testIvyDeps() override def testFramework = "mill.UTestFramework" - override def scalacPluginClasspath = + override def scalacPluginClasspath = T { super.scalacPluginClasspath() ++ Seq(main.moduledefs.jar()) + } + override def scalacOptions = T { + super.scalacOptions() ++ Seq(s"-Xplugin:${main.moduledefs.jar()}") + } } } From e212a857f67e9e9ac79032c2563c6f636e7266f3 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 23 Jan 2022 20:19:34 +0100 Subject: [PATCH 5/9] Fixed plugin path --- build.sc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/build.sc b/build.sc index 15e5f8c3b34..2331c6c73fe 100755 --- a/build.sc +++ b/build.sc @@ -207,7 +207,7 @@ trait MillModule extends MillApiModule { outer => super.scalacPluginClasspath() ++ Seq(main.moduledefs.jar()) } override def scalacOptions = T { - super.scalacOptions() ++ Seq(s"-Xplugin:${main.moduledefs.jar()}") + super.scalacOptions() ++ Seq(s"-Xplugin:${main.moduledefs.jar().path}") } def testArgs = T { Seq.empty[String] } @@ -221,12 +221,6 @@ trait MillModule extends MillApiModule { outer => else Seq(outer, main.test) override def ivyDeps: T[Agg[Dep]] = outer.testIvyDeps() override def testFramework = "mill.UTestFramework" - override def scalacPluginClasspath = T { - super.scalacPluginClasspath() ++ Seq(main.moduledefs.jar()) - } - override def scalacOptions = T { - super.scalacOptions() ++ Seq(s"-Xplugin:${main.moduledefs.jar()}") - } } } From a4b6334b7c53c4167d1e573c7b439b054f73c8dd Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 23 Jan 2022 21:32:55 +0100 Subject: [PATCH 6/9] ScalaDoc updates --- scalalib/src/ScalaModule.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala index 632166261a6..b5400f8f251 100644 --- a/scalalib/src/ScalaModule.scala +++ b/scalalib/src/ScalaModule.scala @@ -91,7 +91,7 @@ trait ScalaModule extends JavaModule { outer => } /** - * Allows you to make use of Scala compiler plugins from maven central + * Allows you to make use of Scala compiler plugins. */ def scalacPluginIvyDeps: Target[Agg[Dep]] = T { Agg.empty[Dep] } @@ -112,7 +112,7 @@ trait ScalaModule extends JavaModule { outer => } /** - * Scalac options to active the compiler plugins. + * Scalac options to active the compiler plugins for ScalaDoc generation. */ private def enableScalaDocPluginScalacOption: Target[Seq[String]] = T { val resolvedJars = resolveDeps(scalaDocPluginIvyDeps.map(_.map(_.exclude("*" -> "*"))))() From f947653a545d4a9aa89c3043adf1c191b9d81da2 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 23 Jan 2022 21:53:14 +0100 Subject: [PATCH 7/9] Fixed plural form --- scalalib/src/ScalaModule.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala index b5400f8f251..fbc5370df9d 100644 --- a/scalalib/src/ScalaModule.scala +++ b/scalalib/src/ScalaModule.scala @@ -114,7 +114,7 @@ trait ScalaModule extends JavaModule { outer => /** * Scalac options to active the compiler plugins for ScalaDoc generation. */ - private def enableScalaDocPluginScalacOption: Target[Seq[String]] = T { + private def enableScalaDocPluginScalacOptions: Target[Seq[String]] = T { val resolvedJars = resolveDeps(scalaDocPluginIvyDeps.map(_.map(_.exclude("*" -> "*"))))() resolvedJars.iterator.map(jar => s"-Xplugin:${jar.path}").toSeq } @@ -141,7 +141,7 @@ trait ScalaModule extends JavaModule { outer => artifactName() ) else Seq() - mandatoryScalacOptions() ++ enableScalaDocPluginScalacOption() ++ scalacOptions() ++ defaults + mandatoryScalacOptions() ++ enableScalaDocPluginScalacOptions() ++ scalacOptions() ++ defaults } /** From 73099ff5569b335789c9720a008e3a3b267f4144 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 23 Jan 2022 22:00:19 +0100 Subject: [PATCH 8/9] Fixed typos --- scalalib/src/ScalaModule.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala index fbc5370df9d..d34b82536f4 100644 --- a/scalalib/src/ScalaModule.scala +++ b/scalalib/src/ScalaModule.scala @@ -104,7 +104,7 @@ trait ScalaModule extends JavaModule { outer => protected def mandatoryScalacOptions: Target[Seq[String]] = T { Seq.empty[String] } /** - * Scalac options to active the compiler plugins. + * Scalac options to activate the compiler plugins. */ private def enablePluginScalacOptions: Target[Seq[String]] = T { val resolvedJars = resolveDeps(scalacPluginIvyDeps.map(_.map(_.exclude("*" -> "*"))))() @@ -112,7 +112,7 @@ trait ScalaModule extends JavaModule { outer => } /** - * Scalac options to active the compiler plugins for ScalaDoc generation. + * Scalac options to activate the compiler plugins for ScalaDoc generation. */ private def enableScalaDocPluginScalacOptions: Target[Seq[String]] = T { val resolvedJars = resolveDeps(scalaDocPluginIvyDeps.map(_.map(_.exclude("*" -> "*"))))() From 3d480710746a4890c4ebed56730b1ef136fabf51 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 24 Jan 2022 09:03:36 +0100 Subject: [PATCH 9/9] Imports cleanup --- scalalib/src/ScalaModule.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala index d34b82536f4..7bed52ed2ed 100644 --- a/scalalib/src/ScalaModule.scala +++ b/scalalib/src/ScalaModule.scala @@ -3,13 +3,13 @@ package scalalib import scala.annotation.nowarn import mill.define.{Command, Sources, Target, Task} -import mill.api.{DummyInputStream, Loose, PathRef, Result, internal} +import mill.api.{DummyInputStream, PathRef, Result, internal} import mill.modules.Jvm import mill.modules.Jvm.createJar import Lib._ import ch.epfl.scala.bsp4j.{BuildTargetDataKind, ScalaBuildTarget, ScalaPlatform} import mill.api.Loose.Agg -import mill.eval.{Evaluator, EvaluatorPathsResolver} +import mill.eval.EvaluatorPathsResolver import mill.scalalib.api.{CompilationResult, ZincWorkerUtil} import mill.scalalib.bsp.{BspBuildTarget, BspModule} @@ -191,7 +191,7 @@ trait ScalaModule extends JavaModule { outer => } // Keep in sync with [[bspCompileClassesInfo]] - override def compile: T[mill.scalalib.api.CompilationResult] = T.persistent { + override def compile: T[CompilationResult] = T.persistent { val sv = scalaVersion() if (sv == "2.12.4") T.log.error( """Attention: Zinc is known to not work properly for Scala version 2.12.4.