如何为 SBT 创建编译器操作

发布于 2024-08-24 06:39:19 字数 277 浏览 5 评论 0原文

我想创建一个 Action 来自动执行 GCJ 编译。由于我无法使其与 Ant 一起使用,我决定尝试 SBT 。文档说明了如何创建操作以及如何运行外部进程。我还没有看到的是如何重用 java 和 scala 编译器操作中存在的目录树遍历。在这种情况下,我的输入文件将是某个根文件夹下的所有 .class 文件。我还需要为 GCJ 指定特定的类路径。对此的任何指示也将不胜感激。

I want to create an Action to automate GCJ compilation. Since I couldn't make it work with Ant, I decided to try SBT. The docs say how to create an Action and how to run an external process. What I don't yet see is how to reuse the directory tree traversal which exists for java and scala compiler Actions. In this case my input files would be all the .class files under a certain root folder. I would also need to specify a specific classpath for GCJ. Any pointers for this would be appreciated too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我根本没有太多使用 GCJ,而且我对 SBT 还很陌生,但我相信您可以通过这种方式编写一个快速任务来准确地使用 SBT 0.7.1 完成您想要的任务。您可以使用 PathFinder 获取所有类文件像这样:

val allClasses = (outputPath ##) ** "*.class"

使用 PathFinder 和“compileClasspath”顶级方法,您可以构造一个这样的任务,它将使用当前项目的类路径运行 gcj 并将所有 .class 文件组成一个 gcjFile:

val gcj = "/usr/local/bin/gcj"
val gcjFile = "target/my_executable.o"

val allClasses = (outputPath ##) ** "*.class"

lazy val gcjCompile = execTask {
  <x>{gcj} --classpath={compileClasspath.get.map(_.absolutePath).mkString(":")}  -c {allClasses.get.map(_.absolutePath).mkString("-c ")} -o {gcjFile}</x>
} dependsOn(compile) describedAs("Create a GCJ executable object")

I haven't used GCJ much at all and I'm still pretty new at SBT, but this is how I believe you could write a quick task to do exactly what you are looking for with SBT 0.7.1. You can use a PathFinder to grab all of the class files like so:

val allClasses = (outputPath ##) ** "*.class"

Using that PathFinder and the "compileClasspath" top level method, you can construct a task like this which will run gcj using the current project's classpath and compose all of the .class files into one gcjFile:

val gcj = "/usr/local/bin/gcj"
val gcjFile = "target/my_executable.o"

val allClasses = (outputPath ##) ** "*.class"

lazy val gcjCompile = execTask {
  <x>{gcj} --classpath={compileClasspath.get.map(_.absolutePath).mkString(":")}  -c {allClasses.get.map(_.absolutePath).mkString("-c ")} -o {gcjFile}</x>
} dependsOn(compile) describedAs("Create a GCJ executable object")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文