diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-15 17:41:32 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-15 17:42:22 -0800 |
commit | 4ec6dca8c3432339620bbc6298fdf75a4b930fb4 (patch) | |
tree | 1c17bb9bb3477be1b498c72ff2c74b9d235dd4bd /build.sc | |
parent | 3a40842d7b3aeedddb9ab5e8261dd48ea4e024b6 (diff) | |
download | mill-4ec6dca8c3432339620bbc6298fdf75a4b930fb4.tar.gz mill-4ec6dca8c3432339620bbc6298fdf75a4b930fb4.tar.bz2 mill-4ec6dca8c3432339620bbc6298fdf75a4b930fb4.zip |
First pass at using a compiler plugin to remove the need for the `override` keyword when overriding a field within a `mill.Module`
This only applies to `mill.Module`s, not overrides elsewhere which still require the keyword. `mill.Module`s tend to have lots and lots of overriding, so the keyword is basically noise.
Also includes the necessary build changes to enable the locally-built Scalac plugin when compiling the test suite. Note that no changes are necessary for the executable assembly, because the `scalac-plugin.xml` will be included in the assembly and get picked up by the Ammonite scalac plugin classloader automatically
Diffstat (limited to 'build.sc')
-rwxr-xr-x | build.sc | 45 |
1 files changed, 30 insertions, 15 deletions
@@ -3,32 +3,46 @@ import mill._ import mill.scalaplugin._ import mill.modules.Jvm.createAssembly + +object CompilerPlugin extends SbtScalaModule{ + def scalaVersion = "2.12.4" + def basePath = pwd / 'plugin + def ivyDeps = Seq( + Dep.Java("org.scala-lang", "scala-compiler", scalaVersion()), + Dep("com.lihaoyi", "sourcecode", "0.1.4") + ) +} + trait MillModule extends SbtScalaModule{ outer => def scalaVersion = "2.12.4" - override def compileIvyDeps = Seq(Dep("com.lihaoyi", "acyclic", "0.1.7")) - override def scalacOptions = Seq("-P:acyclic:force") - override def scalacPluginIvyDeps = Seq(Dep("com.lihaoyi", "acyclic", "0.1.7")) + def compileIvyDeps = Seq(Dep("com.lihaoyi", "acyclic", "0.1.7")) + def scalacOptions = Seq("-P:acyclic:force") + def scalacPluginIvyDeps = Seq(Dep("com.lihaoyi", "acyclic", "0.1.7")) def testArgs = T{ Seq.empty[String] } object test extends this.Tests{ - override def defaultCommandName() = "forkTest" - override def forkArgs = T{ testArgs() } - override def projectDeps = + def defaultCommandName() = "forkTest" + def forkArgs = T{ testArgs() } + def projectDeps = if (this == Core.test) Seq(Core) else Seq(outer, Core.test) - override def ivyDeps = Seq(Dep("com.lihaoyi", "utest", "0.6.0")) + def ivyDeps = Seq(Dep("com.lihaoyi", "utest", "0.6.0")) def testFramework = "mill.UTestFramework" + def scalacPluginClasspath = super.scalacPluginClasspath() ++ Seq(CompilerPlugin.jar()) + } } object Core extends MillModule { - override def compileIvyDeps = Seq( + def projectDeps = Seq(CompilerPlugin) + + def compileIvyDeps = Seq( Dep.Java("org.scala-lang", "scala-reflect", scalaVersion()) ) - override def ivyDeps = Seq( + def ivyDeps = Seq( Dep("com.lihaoyi", "sourcecode", "0.1.4"), Dep("com.lihaoyi", "pprint", "0.5.3"), Dep.Point("com.lihaoyi", "ammonite", "1.0.3"), @@ -61,7 +75,7 @@ val bridges = for{ } yield new ScalaModule{ def basePath = pwd / 'bridge def scalaVersion = crossVersion - override def allSources = T{ + def allSources = T{ val v = crossVersion.split('.').dropRight(1).mkString(".") val url = @@ -77,7 +91,7 @@ val bridges = for{ Seq(PathRef(curlDest / 'classes)) } - override def ivyDeps = Seq( + def ivyDeps = Seq( Dep.Java("org.scala-lang", "scala-compiler", crossVersion), Dep.Java("org.scala-sbt", "compiler-interface", "1.0.5") ) @@ -85,16 +99,17 @@ val bridges = for{ object ScalaPlugin extends MillModule { - override def projectDeps = Seq(Core) + def projectDeps = Seq(Core) def basePath = pwd / 'scalaplugin - override def testArgs = T{ + def testArgs = T{ val mapping = Map( "MILL_COMPILER_BRIDGE_2_10_6" -> bridges("2.10.6").compile().classes.path, "MILL_COMPILER_BRIDGE_2_11_8" -> bridges("2.11.8").compile().classes.path, "MILL_COMPILER_BRIDGE_2_11_11" -> bridges("2.11.11").compile().classes.path, "MILL_COMPILER_BRIDGE_2_12_3" -> bridges("2.12.3").compile().classes.path, "MILL_COMPILER_BRIDGE_2_12_4" -> bridges("2.12.4").compile().classes.path, + "MILL_COMPILER_PLUGIN" -> CompilerPlugin.compile().classes.path ) for((k, v) <- mapping.toSeq) yield s"-D$k=$v" } @@ -103,7 +118,7 @@ object ScalaPlugin extends MillModule { object Bin extends MillModule { - override def projectDeps = Seq(ScalaPlugin) + def projectDeps = Seq(ScalaPlugin) def basePath = pwd / 'bin def releaseAssembly = T{ @@ -116,7 +131,7 @@ object Bin extends MillModule { ) } - override def prependShellScript = + def prependShellScript = "#!/usr/bin/env sh\n" + s"""exec java ${ScalaPlugin.testArgs().mkString(" ")} $$JAVA_OPTS -cp "$$0" mill.Main "$$@" """ |