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

Explicit handling of scalac plugins and related enablement options #1705

Merged
merged 9 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion scalalib/src/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
lefou marked this conversation as resolved.
Show resolved Hide resolved
val resolvedJars = resolveDeps(scalacPluginIvyDeps.map(_.map(_.exclude("*" -> "*"))))()
resolvedJars.iterator.toSeq.map(jar => s"-Xplugin:${jar}")
lefou marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Command-line options to pass to the Scala compiler defined by the user.
* Consumers should use `allScalacOptions` to read them.
Expand All @@ -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 =
Expand Down
22 changes: 11 additions & 11 deletions scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand Down