Merge pull request #1202 from Duhemm/inherited-macros

Disable macro heuristic for inherited macros (sbt/sbt#1142)
This commit is contained in:
Grzegorz Kossakowski 2014-04-03 19:57:58 +02:00
commit 74fb8b4e3c
8 changed files with 84 additions and 0 deletions

View File

@ -29,6 +29,14 @@ object APIUtil
{
var hasMacro = false
// Don't visit inherited definitions since we consider that a class
// that inherits a macro does not have a macro.
override def visitStructure0(structure: Structure)
{
visitTypes(structure.parents)
visitDefinitions(structure.declared)
}
override def visitModifiers(m: Modifiers)
{
hasMacro ||= m.isMacro

View File

@ -0,0 +1,7 @@
package macro
object Client {
object RealClient extends Provider {
// Some comment...
}
}

View File

@ -0,0 +1,9 @@
// Check that a file has not been recompiled during last compilation
InputKey[Unit]("check-not-recompiled") <<= inputTask { (argTask: TaskKey[Seq[String]]) =>
(argTask, compile in Compile) map { (args: Seq[String], a: sbt.inc.Analysis) =>
assert(args.size == 1)
val fileCompilation = a.apis.internal.collect { case (file, src) if file.name.endsWith(args(0)) => src.compilation }.head
val lastCompilation = a.compilations.allCompilations.last
assert(fileCompilation.startTime != lastCompilation.startTime, "File has been recompiled during last compilation.")
}
}

View File

@ -0,0 +1,7 @@
package macro
object Client {
object RealClient extends Provider {
}
}

View File

@ -0,0 +1,5 @@
package macro
object Foo {
val c = Client.RealClient
}

View File

@ -0,0 +1,7 @@
package macro
import scala.language.experimental.macros
import scala.reflect.macros._
abstract class Provider {
def notImplementedMacro = macro ???
}

View File

@ -0,0 +1,29 @@
import sbt._
import Keys._
object build extends Build {
val defaultSettings = Seq(
libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _ )//,
//incOptions := incOptions.value.withNameHashing(true)
)
lazy val root = Project(
base = file("."),
id = "macro",
aggregate = Seq(macroProvider, macroClient),
settings = Defaults.defaultSettings ++ defaultSettings
)
lazy val macroProvider = Project(
base = file("macro-provider"),
id = "macro-provider",
settings = Defaults.defaultSettings ++ defaultSettings
)
lazy val macroClient = Project(
base = file("macro-client"),
id = "macro-client",
dependencies = Seq(macroProvider),
settings = Defaults.defaultSettings ++ defaultSettings
)
}

View File

@ -0,0 +1,12 @@
> macro-provider/compile
> macro-client/compile
# Introduce a comment in Client, which inherits a macro from Provider
$ copy-file changes/Client.scala macro-client/src/main/scala/Client.scala
> macro-client/compile
# Object Foo depends on Client via composition, thus a whitespace change to
# Client shouldn't trigger its recompilation
> check-not-recompiled Foo.scala