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

Add scalaCompilerPlugins to Mill project export #1626

Merged
merged 4 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions modules/cli/src/main/scala/scala/cli/exportCmd/Mill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ final case class Mill(
MillProject(scalaVersion = Some(sv))
}

private def scalaCompilerPlugins(buildOptions: BuildOptions): MillProject =
MillProject(scalaCompilerPlugins =
buildOptions.scalaOptions.compilerPlugins.toSeq.map(_.value.render)
lwronski marked this conversation as resolved.
Show resolved Hide resolved
)

private def scalacOptionsSettings(buildOptions: BuildOptions): MillProject =
MillProject(scalacOptions = buildOptions.scalaOptions.scalacOptions.toSeq.map(_.value.value))

Expand Down Expand Up @@ -187,6 +192,7 @@ final case class Mill(
sourcesSettings(sourcesMain, sourcesTest),
scalaVersionSettings(optionsMain, sourcesMain),
scalacOptionsSettings(optionsMain),
scalaCompilerPlugins(optionsMain),
dependencySettings(optionsMain, optionsTest),
repositorySettings(optionsMain),
if (optionsMain.platform.value == Platform.JS) scalaJsSettings(optionsMain.scalaJsOptions)
Expand Down
19 changes: 19 additions & 0 deletions modules/cli/src/main/scala/scala/cli/exportCmd/MillProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final case class MillProject(
testDeps: Seq[String] = Nil,
scalaVersion: Option[String] = None,
scalacOptions: Seq[String] = Nil,
scalaCompilerPlugins: Seq[String] = Nil,
scalaJsVersion: Option[String] = None,
scalaNativeVersion: Option[String] = None,
nameOpt: Option[String] = None,
Expand Down Expand Up @@ -87,6 +88,23 @@ final case class MillProject(
")" + nl
}

val maybeScalaCompilerPlugins =
if (scalaCompilerPlugins.isEmpty) ""
else {
val depLen = scalaCompilerPlugins.length
"def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Seq(" + nl +
scalaCompilerPlugins
.iterator
.zipWithIndex
.map {
case (dep, idx) =>
val maybeComma = if (idx == depLen - 1) "" else ","
""" ivy"""" + dep + "\"" + maybeComma + nl
}
.mkString + nl +
")" + nl
}

val maybeMain = mainClass.fold("") { mc =>
s"""def mainClass = Some("$mc")""" + nl
}
Expand All @@ -101,6 +119,7 @@ final case class MillProject(
| $maybeScalacOptions
| $extraDecs
| ${maybeDeps(mainDeps)}
| $maybeScalaCompilerPlugins
| $maybeMain
| ${extraDecls.map(" " + _ + nl).mkString}
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ abstract class ExportMillTestDefinitions(val scalaVersionOpt: Option[String])
val output = res.out.text(Charset.defaultCharset())
expect(output.filterNot(_.isWhitespace) == "[\"-deprecation\"]")
}
locally {
// scalacPluginIvyDeps
val res =
os.proc(
root / "mill-proj" / launcher,
"--disable-ticker",
"show",
s"$projectName.scalacPluginIvyDeps"
).call(cwd = root / "mill-proj")
val output = res.out.text(Charset.defaultCharset())
expect(output.contains("com.olegpy"))
expect(output.contains("better-monadic-for"))
}
locally {
// test
val res =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object ExportTestProjects {
|//> using resourceDir "./input"
|//> using lib "org.scala-lang::scala3-compiler:$scalaVersion"
|//> using option "-deprecation"
|//> using plugins "com.olegpy::better-monadic-for:0.3.1"
|
|import scala.io.Source
|
Expand All @@ -28,6 +29,7 @@ object ExportTestProjects {
s"""//> using scala "$scalaVersion"
|//> using resourceDir "./input"
|//> using option "-deprecation"
|//> using plugins "com.olegpy::better-monadic-for:0.3.1"
|
|import scala.io.Source
|
Expand Down