Make autoCompilerPlugins support compiler plugins defined in a internal dependency

requires the compiler plugin project to define exportJars := true
This commit is contained in:
Mark Harrah 2013-04-03 12:44:35 -04:00
parent 8ce252d1b1
commit 322a49faba
8 changed files with 52 additions and 4 deletions

View File

@ -1329,16 +1329,24 @@ object Classpaths
(base * (filter -- excl) +++ (base / config.name).descendantsExcept(filter, excl)).classpath
def autoPlugins(report: UpdateReport): Seq[String] =
@deprecated("Specify the classpath that includes internal dependencies", "0.13.0")
def autoPlugins(report: UpdateReport): Seq[String] = autoPlugins(report, Nil)
def autoPlugins(report: UpdateReport, internalPluginClasspath: Seq[File]): Seq[String] =
{
val pluginClasspath = report matching configurationFilter(CompilerPlugin.name)
classpath.ClasspathUtilities.compilerPlugins(pluginClasspath).map("-Xplugin:" + _.getAbsolutePath).toSeq
val pluginClasspath = report.matching(configurationFilter(CompilerPlugin.name)) ++ internalPluginClasspath
val plugins = classpath.ClasspathUtilities.compilerPlugins(pluginClasspath)
plugins.map("-Xplugin:" + _.getAbsolutePath).toSeq
}
private[this] lazy val internalCompilerPluginClasspath: Initialize[Task[Classpath]] =
(thisProjectRef, settingsData, buildDependencies) flatMap { (ref, data, deps) =>
internalDependencies0(ref, CompilerPlugin, CompilerPlugin, data, deps)
}
lazy val compilerPluginConfig = Seq(
scalacOptions := {
val options = scalacOptions.value
if(autoCompilerPlugins.value) options ++ autoPlugins(update.value) else options
if(autoCompilerPlugins.value) options ++ autoPlugins(update.value, internalCompilerPluginClasspath.value.files) else options
}
)
@deprecated("Doesn't properly handle non-standard Scala organizations.", "0.13.0")

View File

@ -0,0 +1,5 @@
import Configurations.{CompilerPlugin => CPlugin}
lazy val use = project.dependsOn(file("def") % CPlugin).settings(
autoCompilerPlugins := true
)

View File

@ -0,0 +1,10 @@
package demo
import scala.tools.nsc.{Global, plugins}
class DemoPlugin(val global: Global) extends plugins.Plugin
{
val name = "demo-plugin"
val description = "Throws an error"
val components = error("The plugin was successfully registered.")
}

View File

@ -0,0 +1,4 @@
<plugin>
<name>demo</name>
<classname>demo.DemoPlugin</classname>
</plugin>

View File

@ -0,0 +1,9 @@
organization := "org.example"
name := "demo-compiler-plugin"
version := "0.1"
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
exportJars := true

View File

@ -0,0 +1,10 @@
# compilation should succeed on the trivial source file in use/
> use/compile
# add the plugin
$ copy-file changes/scalac-plugin.xml def/src/main/resources/scalac-plugin.xml
$ copy-file changes/DemoPlugin.scala def/DemoPlugin.scala
# if the plugin is successfully registered it will generate an error on construction
> use/clean
-> use/compile

View File

@ -0,0 +1 @@
object A

View File

@ -44,6 +44,7 @@ Improvements
- Tasks that need a directory for storing cache information can now use the ``cacheDirectory`` method on ``streams``. This supersedes the ``cacheDirectory`` setting.
- The environment variables used when forking ``run`` and ``test`` may be set via ``envVars``, which is a ``Task[Map[String,String]]``. (gh-665)
- Restore class files after an unsuccessful compilation. This is useful when an error occurs in a later incremental step that requires a fix in the originally changed files.
- ``autoCompilerPlugins`` now supports compiler plugins defined in a internal dependency. The plugin project must define ``exportJars := true``. Depend on the plugin with ``...dependsOn(... % Configurations.CompilerPlugin)``.
Other
-----