Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report macros as used #1008

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ class AstUsedJarFinder(
case _ =>
}

// If this expression is the result of a macro, then we
// should also examine the original macro expression
tree.attachments
.get[global.treeChecker.MacroExpansionAttachment]
.foreach { attach =>
// When we explore the original, the original also has
// this attachment. So we should not examine the original
// again if so.
if (attach.expandee != tree) {
fullyExploreTree(attach.expandee)
}
}

val shouldExamine =
tree match {
case select: Select if select.symbol.isDefaultGetter =>
Expand Down
1 change: 1 addition & 0 deletions third_party/dependency_analyzer/src/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load("//scala:scala.bzl", "scala_junit_test", "scala_test")
common_jvm_flags = [
"-Dplugin.jar.location=$(location //third_party/dependency_analyzer/src/main:dependency_analyzer)",
"-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)",
"-Dscala.reflect.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_reflect)",
]

scala_test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,32 @@ class AstUsedJarFinderTest extends FunSuite {
)
}

test("macro is direct") {
checkDirectDependencyRecognized(
aCode =
s"""
|import scala.language.experimental.macros
|import scala.reflect.macros.blackbox.Context
|
|object A {
| def foo(): Unit = macro fooImpl
| def fooImpl(
| c: Context
| )(): c.universe.Tree = {
| import c.universe._
| q""
| }
|}
|""".stripMargin,
bCode =
s"""
|object B {
| A.foo()
|}
|""".stripMargin
)
}

test("java interface method argument is direct") {
withSandbox { sandbox =>
sandbox.compileJava(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ object TestUtil {

private def getClasspathArguments(extraClasspath: List[String]): String = {
val classpathEntries = {
val toolboxClasspathOpt = if (toolboxClasspath.isEmpty) { None } else Some(toolboxClasspath)
extraClasspath ++ toolboxClasspathOpt
val builtinClassPaths = builtinClasspaths.filterNot(_.isEmpty)
extraClasspath ++ builtinClassPaths
}
if (classpathEntries.isEmpty) {
""
Expand Down Expand Up @@ -131,8 +131,11 @@ object TestUtil {

private lazy val baseDir = System.getProperty("user.dir")

private lazy val toolboxClasspath: String =
pathOf("scala.library.location")
private lazy val builtinClasspaths: Vector[String] =
Vector(
pathOf("scala.library.location"),
pathOf("scala.reflect.location")
)

lazy val guavaClasspath: String =
pathOf("guava.jar.location")
Expand Down