Skip to content

Commit

Permalink
Make the runner arg responsible for finding protoc.
Browse files Browse the repository at this point in the history
Towards fixing #17
  • Loading branch information
thesamet committed May 8, 2015
1 parent 454cef4 commit 088238d
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import scala.util.Try
* 7. protoc handles the CodeGenerationResponse (creates Scala sources)
*/
trait ProtocDriver {
def runProtocUsing[A](protocCommand: String, schemas: Seq[String] = Nil,
def runProtocUsing[A](schemas: Seq[String] = Nil,
includePaths: Seq[String] = Nil, protocOptions: Seq[String] = Nil)(runner: Seq[String] => A): A
}

/** A driver that creates a named pipe and sets up a shell script as a protoc plugin */
class PosixProtocDriver extends ProtocDriver {
def runProtocUsing[A](protocCommand: String, schemas: Seq[String] = Nil,
def runProtocUsing[A](schemas: Seq[String] = Nil,
includePaths: Seq[String] = Nil, protocOptions: Seq[String] = Nil)(runner: Seq[String] => A): A = {
val pipe = createPipe()
val sh = createShellScript(pipe)
Expand All @@ -55,7 +55,7 @@ class PosixProtocDriver extends ProtocDriver {

try {
val incPath = includePaths.map("-I" + _)
val args = Seq(protocCommand, s"--plugin=protoc-gen-scala=$sh") ++ incPath ++ protocOptions ++ schemas
val args = Seq(s"--plugin=protoc-gen-scala=$sh") ++ incPath ++ protocOptions ++ schemas
runner(args)
} finally {
Files.delete(pipe)
Expand Down Expand Up @@ -89,8 +89,7 @@ class PosixProtocDriver extends ProtocDriver {
* stdin and stdout to this socket.
*/
class WindowsProtocDriver(pythonExecutable: String) extends ProtocDriver {
def runProtocUsing[A](protocCommand: String,
schemas: Seq[String] = Nil,
def runProtocUsing[A](schemas: Seq[String] = Nil,
includePaths: Seq[String] = Nil,
protocOptions: Seq[String] = Nil)(runner: Seq[String] => A): A = {
val ss = new ServerSocket(0)
Expand All @@ -105,7 +104,7 @@ class WindowsProtocDriver(pythonExecutable: String) extends ProtocDriver {

try {
val incPath = includePaths.map("-I" + _)
val args = Seq(protocCommand, s"--plugin=protoc-gen-scala=$batFile") ++ incPath ++ protocOptions ++ schemas
val args = Seq(s"--plugin=protoc-gen-scala=$batFile") ++ incPath ++ protocOptions ++ schemas
runner(args)
} finally {
Files.delete(batFile)
Expand Down Expand Up @@ -146,7 +145,8 @@ object Process {
schemas: Seq[String] = Nil,
includePaths: Seq[String] = Nil,
protocOptions: Seq[String] = Nil)(runner: Seq[String] => A): A =
(new PosixProtocDriver).runProtocUsing(protocCommand, schemas, includePaths, protocOptions)(runner)
(new PosixProtocDriver).runProtocUsing(schemas, includePaths, protocOptions)(args =>
runner(protocCommand +: args))

private def getStackTrace(e: Throwable): String = {
val stringWriter = new StringWriter
Expand Down

0 comments on commit 088238d

Please sign in to comment.