aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-22 10:11:46 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-24 11:32:09 -0400
commit758611576a4f6ceb7020e3cee1f70bbd1cc0b4d8 (patch)
tree63befde48bed261a1fbed42543206711818858a3 /plugins
parent3d321f42c19d2166204079ba7eece66b36037042 (diff)
downloadcbt-758611576a4f6ceb7020e3cee1f70bbd1cc0b4d8.tar.gz
cbt-758611576a4f6ceb7020e3cee1f70bbd1cc0b4d8.tar.bz2
cbt-758611576a4f6ceb7020e3cee1f70bbd1cc0b4d8.zip
ScalaPB plugin
Diffstat (limited to 'plugins')
-rw-r--r--plugins/scalapb/ScalaPB.scala72
-rw-r--r--plugins/scalapb/build/build.scala23
-rw-r--r--plugins/scalapb/src_generated/BuildInfo.scala5
3 files changed, 100 insertions, 0 deletions
diff --git a/plugins/scalapb/ScalaPB.scala b/plugins/scalapb/ScalaPB.scala
new file mode 100644
index 0000000..e514476
--- /dev/null
+++ b/plugins/scalapb/ScalaPB.scala
@@ -0,0 +1,72 @@
+package cbt
+
+import com.trueaccord.scalapb._
+import _root_.protocbridge.ProtocBridge
+import _root_.scalapb.ScalaPbCodeGenerator
+import java.io.File
+
+trait Scalapb extends BaseBuild{
+ override def dependencies = super.dependencies ++ Resolver( mavenCentral ).bind(
+ ScalaDependency(
+ "com.trueaccord.scalapb", "scalapb-runtime", cbt.scalapb.BuildInfo.scalaPBVersion
+ )
+ )
+
+ def scalapb = Scalapb.apply(lib).config(
+ input = projectDirectory / "protobuf-schemas",
+ output = projectDirectory / "src_generated"
+ )
+}
+
+sealed trait ProtocVersion
+object ProtocVersion{
+ case object v310 extends ProtocVersion
+ case object v300 extends ProtocVersion
+ case object v261 extends ProtocVersion
+ case object v250 extends ProtocVersion
+ case object v241 extends ProtocVersion
+}
+
+object Scalapb{
+ case class apply(lib: Lib){
+ case class config(
+ input: File,
+ output: File,
+ version: ProtocVersion = ProtocVersion.v310,
+ flatPackage: Boolean = false,
+ javaConversions: Boolean = false,
+ grpc: Boolean = true,
+ singleLineToString: Boolean = false
+ ){
+ def apply = {
+ output.mkdirs
+ val protoFiles = input.listRecursive.filter(_.isFile).map(_.string).toArray
+ Seq(
+ javaConversions.option("javaConversions"),
+ grpc.option("grpc"),
+ singleLineToString.option("singleLineToString"),
+ flatPackage.option("flatPackage")
+ ).flatten.mkString(",")
+ import _root_.protocbridge.frontend.PluginFrontend
+ val pluginFrontend: PluginFrontend = PluginFrontend.newInstance()
+ val (scriptPath, state) = pluginFrontend.prepare( ScalaPbCodeGenerator )
+ try {
+ lib.redirectOutToErr(
+ ExitCode(
+ com.github.os72.protocjar.Protoc.runProtoc(
+ Array(
+ "-" ++ version.getClass.getSimpleName.stripSuffix("$"),
+ "-I=" ++ input.string,
+ "--scala_out=" ++ output.string,
+ s"--plugin=protoc-gen-scala=${scriptPath}"
+ ) ++ protoFiles
+ )
+ )
+ )
+ } finally {
+ pluginFrontend.cleanup(state)
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/scalapb/build/build.scala b/plugins/scalapb/build/build.scala
new file mode 100644
index 0000000..cadee1b
--- /dev/null
+++ b/plugins/scalapb/build/build.scala
@@ -0,0 +1,23 @@
+import cbt._
+
+class Build(val context: Context) extends Plugin {
+ private val scalaPBVersion = "0.5.47"
+
+ override def dependencies =
+ super.dependencies ++
+ Resolver( mavenCentral ).bind(
+ ScalaDependency( "com.trueaccord.scalapb", "scalapbc", scalaPBVersion )
+ )
+
+ override def compile = { buildInfo; super.compile }
+
+ def buildInfo = lib.writeIfChanged(
+ projectDirectory / "src_generated/BuildInfo.scala",
+ s"""// generated file
+package cbt.scalapb
+object BuildInfo{
+ def scalaPBVersion = "$scalaPBVersion"
+}
+"""
+ )
+}
diff --git a/plugins/scalapb/src_generated/BuildInfo.scala b/plugins/scalapb/src_generated/BuildInfo.scala
new file mode 100644
index 0000000..8498d10
--- /dev/null
+++ b/plugins/scalapb/src_generated/BuildInfo.scala
@@ -0,0 +1,5 @@
+// generated file
+package cbt.scalapb
+object BuildInfo{
+ def scalaPBVersion = "0.5.47"
+}