Skip to content

Commit 55210e9

Browse files
authored
Add scalaCompilerPlugins to Mill project export (#1626)
* Add scalaCompilerPlugins to Mill project export * Fix test for scalacPluginIvyDeps * Fix number of colons on plugin generation * Separate tests and filter by Scala version
1 parent a3ca664 commit 55210e9

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,47 @@ abstract class ExportMillTestDefinitions(val scalaVersionOpt: Option[String])
8787
}
8888
}
8989
}
90+
91+
def jvmTestCompilerPlugin(projectName: String = "project"): Unit = {
92+
val inputs = addMillJvmOpts(ExportTestProjects.jvmTest(actualScalaVersion))
93+
inputs.fromRoot { root =>
94+
val setProject = if (projectName != "project") Seq("-p", projectName) else Seq.empty
95+
os.proc(
96+
TestUtil.cli,
97+
"export",
98+
extraOptions,
99+
"--mill",
100+
setProject,
101+
"-o",
102+
"mill-proj",
103+
"."
104+
)
105+
.call(cwd = root, stdout = os.Inherit)
106+
locally {
107+
// scalacPluginIvyDeps
108+
val res =
109+
os.proc(
110+
root / "mill-proj" / launcher,
111+
"--disable-ticker",
112+
"show",
113+
s"$projectName.scalacPluginIvyDeps"
114+
).call(cwd = root / "mill-proj")
115+
val output = res.out.text(Charset.defaultCharset())
116+
expect(output.contains("com.olegpy"))
117+
expect(output.contains("better-monadic-for"))
118+
}
119+
locally {
120+
// test
121+
val res =
122+
os.proc(root / "mill-proj" / launcher, s"$projectName.test").call(cwd =
123+
root / "mill-proj"
124+
)
125+
val output = res.out.text(Charset.defaultCharset())
126+
expect(output.contains("1 succeeded"))
127+
}
128+
}
129+
}
130+
90131
if (runExportTests)
91132
test("JVM") {
92133
jvmTest()
@@ -97,6 +138,11 @@ abstract class ExportMillTestDefinitions(val scalaVersionOpt: Option[String])
97138
jvmTest("newproject")
98139
}
99140

141+
if (runExportTests && !actualScalaVersion.startsWith("3."))
142+
test("JVM with compiler plugin") {
143+
jvmTestCompilerPlugin()
144+
}
145+
100146
if (runExportTests)
101147
test("Scala.js") {
102148
simpleTest(ExportTestProjects.jsTest(actualScalaVersion))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ object ExportTestProjects {
2828
s"""//> using scala "$scalaVersion"
2929
|//> using resourceDir "./input"
3030
|//> using option "-deprecation"
31+
|//> using plugins "com.olegpy::better-monadic-for:0.3.1"
3132
|
3233
|import scala.io.Source
3334
|

0 commit comments

Comments
 (0)