在特定阶段后停止 Scala 编译
我正在通过像这样的进程内运行来测试我的插件:
type PluginMessage = StoreReporter#Info
def runPlugin(fileName: String): List[PluginMessage] = {
val settings = new Settings
settings.outputDirs setSingleOutput (curDir + "/target")
settings.classpath.tryToSet(List(
"project/boot/scala-" + scalaVersion + "/lib/scala-compiler.jar" +
":project/boot/scala-" + scalaVersion + "/lib/scala-library.jar"))
val reporter = new StoreReporter
val compiler = new Global(settings, reporter) {
override protected def computeInternalPhases() {
super.computeInternalPhases
for (phase <- new AlacsPlugin(this).components)
phasesSet += phase
}
}
(new compiler.Run).compile(List(testPrefix + fileName))
reporter.infos.toList
}
但是,考虑到 scalac 的速度很慢,我真的希望编译在某个阶段后结束(特别是在我的插件运行之后) )。不幸的是 Global.cancel
没有达到预期的效果。我该怎么做?
I'm testing my plugin by running it in-process like this:
type PluginMessage = StoreReporter#Info
def runPlugin(fileName: String): List[PluginMessage] = {
val settings = new Settings
settings.outputDirs setSingleOutput (curDir + "/target")
settings.classpath.tryToSet(List(
"project/boot/scala-" + scalaVersion + "/lib/scala-compiler.jar" +
":project/boot/scala-" + scalaVersion + "/lib/scala-library.jar"))
val reporter = new StoreReporter
val compiler = new Global(settings, reporter) {
override protected def computeInternalPhases() {
super.computeInternalPhases
for (phase <- new AlacsPlugin(this).components)
phasesSet += phase
}
}
(new compiler.Run).compile(List(testPrefix + fileName))
reporter.infos.toList
}
However, given the slow speed of scalac
I'd really like for compilation to end after a certain phase (specifically, after my plugin runs). Unfortunately Global.cancel
doesn't have the intended effect. How might I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
scalac 有一个明确用于此目的的参数。从 2.9.0.RC2 开始,您可以在命令行中指定:
在早期版本中:
要直接从
Settings
实例执行等效操作,这被定义为stopAfter
(或在早期版本中stop
)scalac has an argument explicitly for this purpose. As of 2.9.0.RC2 you can specify at the command line:
And in earlier versions:
To do the equivalent directly from a
Settings
instance, this is defined asstopAfter
(orstop
in earlier versions)