Skip to content

Commit

Permalink
Add scalaCompilerPlugins to Mill project export (#1626)
Browse files Browse the repository at this point in the history
* Add scalaCompilerPlugins to Mill project export

* Fix test for scalacPluginIvyDeps

* Fix number of colons on plugin generation

* Separate tests and filter by Scala version
  • Loading branch information
carlosedp authored Dec 2, 2022
1 parent a3ca664 commit 55210e9
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
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)
)

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 @@ -87,6 +87,47 @@ abstract class ExportMillTestDefinitions(val scalaVersionOpt: Option[String])
}
}
}

def jvmTestCompilerPlugin(projectName: String = "project"): Unit = {
val inputs = addMillJvmOpts(ExportTestProjects.jvmTest(actualScalaVersion))
inputs.fromRoot { root =>
val setProject = if (projectName != "project") Seq("-p", projectName) else Seq.empty
os.proc(
TestUtil.cli,
"export",
extraOptions,
"--mill",
setProject,
"-o",
"mill-proj",
"."
)
.call(cwd = root, stdout = os.Inherit)
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 =
os.proc(root / "mill-proj" / launcher, s"$projectName.test").call(cwd =
root / "mill-proj"
)
val output = res.out.text(Charset.defaultCharset())
expect(output.contains("1 succeeded"))
}
}
}

if (runExportTests)
test("JVM") {
jvmTest()
Expand All @@ -97,6 +138,11 @@ abstract class ExportMillTestDefinitions(val scalaVersionOpt: Option[String])
jvmTest("newproject")
}

if (runExportTests && !actualScalaVersion.startsWith("3."))
test("JVM with compiler plugin") {
jvmTestCompilerPlugin()
}

if (runExportTests)
test("Scala.js") {
simpleTest(ExportTestProjects.jsTest(actualScalaVersion))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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

0 comments on commit 55210e9

Please sign in to comment.