mirror of https://github.com/sbt/sbt.git
Make autoCompilerPlugins support compiler plugins defined in a internal dependency
requires the compiler plugin project to define exportJars := true
This commit is contained in:
parent
8ce252d1b1
commit
322a49faba
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
import Configurations.{CompilerPlugin => CPlugin}
|
||||
|
||||
lazy val use = project.dependsOn(file("def") % CPlugin).settings(
|
||||
autoCompilerPlugins := true
|
||||
)
|
||||
|
|
@ -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.")
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<plugin>
|
||||
<name>demo</name>
|
||||
<classname>demo.DemoPlugin</classname>
|
||||
</plugin>
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1 @@
|
|||
object A
|
||||
|
|
@ -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
|
||||
-----
|
||||
|
|
|
|||
Loading…
Reference in New Issue