-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix classpath in QuoteDriver when executing from sbt #3871
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
Fix classpath in QuoteDriver when executing from sbt #3871
Conversation
Found the bug and fixed it in nicolasstucki/scala-quoted-util@39087d4 |
I have no idea what the context is so I can't really review this. I'll just note that you can pass |
Maybe the |
The |
var classpath = System.getProperty("java.class.path") | ||
this.getClass.getClassLoader match { | ||
case cl: URLClassLoader => | ||
// Loads the classes load by this class loader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the classes loaded by
this.getClass.getClassLoader match { | ||
case cl: URLClassLoader => | ||
// Loads the classes load by this class loader | ||
// When executing `run` or `test` in sbt the classpath is not in th property java.class.path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the property
72173d2
to
014164d
Compare
Rebased and fixed comments |
@@ -61,7 +62,15 @@ class QuoteDriver extends Driver { | |||
|
|||
override def initCtx: Context = { | |||
val ictx = super.initCtx.fresh | |||
val classpath = System.getProperty("java.class.path") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using ctx.settings.classpath instead, isn't that enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the classpath of the library in not in there. That is why I needed to add it explicitly. We also need the current classpath in case the quote refers to something in the application (such as class or static method).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example
class Foo
object Foo {
def main(...) = {
val q = '(new Foo)
q.run // Foo need to be present in the classpath of the compiler that will compile q
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In scala.reflect macros, it assumes separation (ahead-of) compilation of macro definitions. The user-app must depend on the lib that contains Foo
in order to use that macro, thus it's automatically on the path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. But the app is guaranteed to have separate compilation as the macro is staged.
I assume macros in scalac have the same problem. We should check how they handle classpaths. |
No description provided.