Skip to content

Commit 1867d48

Browse files
committed
Add scalaCompilerPlugins to Mill project export
1 parent a3ca664 commit 1867d48

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

modules/cli/src/main/scala/scala/cli/exportCmd/Mill.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ final case class Mill(
4646
MillProject(scalaVersion = Some(sv))
4747
}
4848

49+
private def scalaCompilerPlugins(buildOptions: BuildOptions): MillProject =
50+
MillProject(scalaCompilerPlugins =
51+
buildOptions.scalaOptions.compilerPlugins.toSeq.map(_.value.render)
52+
)
53+
4954
private def scalacOptionsSettings(buildOptions: BuildOptions): MillProject =
5055
MillProject(scalacOptions = buildOptions.scalaOptions.scalacOptions.toSeq.map(_.value.value))
5156

@@ -187,6 +192,7 @@ final case class Mill(
187192
sourcesSettings(sourcesMain, sourcesTest),
188193
scalaVersionSettings(optionsMain, sourcesMain),
189194
scalacOptionsSettings(optionsMain),
195+
scalaCompilerPlugins(optionsMain),
190196
dependencySettings(optionsMain, optionsTest),
191197
repositorySettings(optionsMain),
192198
if (optionsMain.platform.value == Platform.JS) scalaJsSettings(optionsMain.scalaJsOptions)

modules/cli/src/main/scala/scala/cli/exportCmd/MillProject.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final case class MillProject(
1212
testDeps: Seq[String] = Nil,
1313
scalaVersion: Option[String] = None,
1414
scalacOptions: Seq[String] = Nil,
15+
scalaCompilerPlugins: Seq[String] = Nil,
1516
scalaJsVersion: Option[String] = None,
1617
scalaNativeVersion: Option[String] = None,
1718
nameOpt: Option[String] = None,
@@ -87,6 +88,23 @@ final case class MillProject(
8788
")" + nl
8889
}
8990

91+
val maybeScalaCompilerPlugins =
92+
if (scalaCompilerPlugins.isEmpty) ""
93+
else {
94+
val depLen = scalaCompilerPlugins.length
95+
"def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Seq(" + nl +
96+
scalaCompilerPlugins
97+
.iterator
98+
.zipWithIndex
99+
.map {
100+
case (dep, idx) =>
101+
val maybeComma = if (idx == depLen - 1) "" else ","
102+
""" ivy"""" + dep + "\"" + maybeComma + nl
103+
}
104+
.mkString + nl +
105+
")" + nl
106+
}
107+
90108
val maybeMain = mainClass.fold("") { mc =>
91109
s"""def mainClass = Some("$mc")""" + nl
92110
}
@@ -101,6 +119,7 @@ final case class MillProject(
101119
| $maybeScalacOptions
102120
| $extraDecs
103121
| ${maybeDeps(mainDeps)}
122+
| $maybeScalaCompilerPlugins
104123
| $maybeMain
105124
| ${extraDecls.map(" " + _ + nl).mkString}
106125
|

modules/integration/src/test/scala/scala/cli/integration/ExportMillTestDefinitions.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ abstract class ExportMillTestDefinitions(val scalaVersionOpt: Option[String])
7676
val output = res.out.text(Charset.defaultCharset())
7777
expect(output.filterNot(_.isWhitespace) == "[\"-deprecation\"]")
7878
}
79+
locally {
80+
// scalaCompilerPlugins
81+
val res =
82+
os.proc(
83+
root / "mill-proj" / launcher,
84+
"--disable-ticker",
85+
"show",
86+
s"$projectName.scalaCompilerPlugins"
87+
).call(cwd = root / "mill-proj")
88+
val output = res.out.text(Charset.defaultCharset())
89+
expect(output.filterNot(_.isWhitespace) == "ivy\"com.olegpy::better-monadic-for:0.3.1\"")
90+
}
7991
locally {
8092
// test
8193
val res =

modules/integration/src/test/scala/scala/cli/integration/ExportTestProjects.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ object ExportTestProjects {
1212
|//> using resourceDir "./input"
1313
|//> using lib "org.scala-lang::scala3-compiler:$scalaVersion"
1414
|//> using option "-deprecation"
15+
|//> using plugins "com.olegpy::better-monadic-for:0.3.1"
1516
|
1617
|import scala.io.Source
1718
|
@@ -28,6 +29,7 @@ object ExportTestProjects {
2829
s"""//> using scala "$scalaVersion"
2930
|//> using resourceDir "./input"
3031
|//> using option "-deprecation"
32+
|//> using plugins "com.olegpy::better-monadic-for:0.3.1"
3133
|
3234
|import scala.io.Source
3335
|

0 commit comments

Comments
 (0)