How to create an Action compiler for SBT

I want to create an Action to automate the compilation of GCJ. Since I could not get it to work with Ant , I decided to try SBT. The docs say how to create an action and how to start an external process. I still don't see how to reuse the directory tree traversal that exists for java and scala Actions. In this case, my .class files in a specific root folder will be my input files. I also need to specify a specific class path for GCJ. Any pointers to this will also be appreciated.

+5
source share
1 answer

I haven't used GCJ at all, and I'm still pretty new to SBT, but I'm sure you could write a brief task to exactly accomplish what you are looking for with SBT 0.7.1. You can use PathFinder to capture all class files as follows:

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

Using this PathFinder method and top-level "compileClasspath", you can create a task that will run gcj using the current path to the project class and compile all .class files into a single gcjFile file:

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")
+4
source

All Articles