Skip to content

Commit

Permalink
Add setting to restrict macro classpath
Browse files Browse the repository at this point in the history
For better cacheability
  • Loading branch information
retronym committed Oct 15, 2018
1 parent ec669bf commit 24124d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ trait ScalaSettings extends AbsScalaSettings
val YcachePluginClassLoader = CachePolicy.setting("plugin", "compiler plugins")
val YcacheMacroClassLoader = CachePolicy.setting("macro", "macros")

val YmacroClasspath = PathSetting ("-Ymacro-classpath", "The classpath used to reflectively load macro implementations", "")

val exposeEmptyPackage = BooleanSetting ("-Yexpose-empty-package", "Internal only: expose the empty package.").internalOnly()
val Ydelambdafy = ChoiceSetting ("-Ydelambdafy", "strategy", "Strategy used for translating lambdas into JVM code.", List("inline", "method"), "method")

Expand Down
10 changes: 9 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ package scala.tools.nsc
package typechecker

import java.lang.Math.min
import java.net.URL

import symtab.Flags._
import scala.reflect.internal.util.ScalaClassLoader
import scala.reflect.runtime.ReflectionUtils
Expand All @@ -22,6 +24,7 @@ import scala.reflect.internal.TypesStats
import scala.reflect.macros.util._
import scala.util.control.ControlThrowable
import scala.reflect.internal.util.ListOfNil
import scala.reflect.io.AbstractFile
import scala.reflect.macros.runtime.{AbortMacroException, MacroRuntimes}
import scala.reflect.macros.compiler.DefaultMacroCompiler
import scala.tools.reflect.FastTrack
Expand Down Expand Up @@ -75,7 +78,12 @@ trait Macros extends MacroRuntimes with Traces with Helpers {
* Mirrors with runtime definitions (e.g. Repl) need to adjust this method.
*/
protected def findMacroClassLoader(): ClassLoader = {
val classpath = global.classPath.asURLs
val classpath: Seq[URL] = if (settings.YmacroClasspath.isSetByUser) {
for {
file <- scala.tools.nsc.util.ClassPath.expandPath(settings.YmacroClasspath.value, true)
af <- Option(AbstractFile getDirectory file)
} yield af.file.toURI.toURL
} else global.classPath.asURLs
def newLoader = () => {
macroLogVerbose("macro classloader: initializing from -cp: %s".format(classpath))
ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader)
Expand Down

0 comments on commit 24124d5

Please sign in to comment.