在特定阶段后停止 Scala 编译

发布于 2024-11-04 04:41:25 字数 915 浏览 1 评论 0原文

我正在通过像这样的进程内运行来测试我的插件:

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫腻 2024-11-11 04:41:25

scalac 有一个明确用于此目的的参数。从 2.9.0.RC2 开始,您可以在命令行中指定:

-Ystop-after:<phasename>

在早期版本中:

-Ystop:<phasename>

要直接从 Settings 实例执行等效操作,这被定义为 stopAfter (或在早期版本中stop

scalac has an argument explicitly for this purpose. As of 2.9.0.RC2 you can specify at the command line:

-Ystop-after:<phasename>

And in earlier versions:

-Ystop:<phasename>

To do the equivalent directly from a Settings instance, this is defined as stopAfter (or stop in earlier versions)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文