Created
March 10, 2011 01:28
-
-
Save harrah/863403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** not compiled or checked, just for the idea *** | |
import sbt._ | |
import Keys._ | |
object MyBuild extends Build | |
{ | |
... wiring into project not shown, see FullConfiguration for where to put `defaults` ... | |
val protocExePath = SettingKey[File]("protoc-exe-path") | |
val protoFiles = SettingKey[Seq[File]]("proto-files") | |
val protoJavaDir = SettingKey[File]("proto-java-dir") | |
val protoDir = SettingKey[File]("proto-dir") | |
val protoDirs = SettingKey[Seq[File]]("proto-dirs") | |
val protoJava = TaskKey[Seq[File]]("proto-java") | |
def defaults = Seq( | |
protoJavaDir <<= sourceDirectory(_ / "gen" / "java"), | |
protoDir <<= sourceDirectory(_ / "main" / "proto"), | |
protoDirs <<= protoDir(_ :: Nil), | |
protoJava <<= protoTask("java"), | |
sources in Compile <<= (sources in Compile, protoJava) map { _ ++ _ } | |
) | |
def protoTask(tpe: String) = (protoJavaDir, protoFiles, protocExePath, streams) map { | |
(dir, files, exe, s) => proto(tpe, dir, files, exe, s.log) | |
} | |
def proto(tpe: String, directory: File, files: Seq[File], exe: File, log: Logger) = | |
{ | |
IO.delete(directory) | |
val dir = directory.getAbsolutePath | |
val mkdirProc: Process = "mkdir" :: "-p" :: dir :: Nil | |
val protoProc = exe :: protoPaths :: "--%s_out=%s".format(tpe,dir) :: files | |
val result = (mkdirProc #&& protocProc) ! log | |
def generated = directory.***.get | |
if(result == 0) generated else error("Non-zero exit code: " + result) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment