Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'twitter/master' into create_thrift_geme…

…rator

Conflicts:
	src/main/scala/com/twitter/sbt/CompileThrift.scala
  • Loading branch information...
commit f5628ab87500272a1404af5b764e9f3e5540afba 2 parents d47ac11 + 4a656b6
@sprsquish authored
View
1  README.md
@@ -6,6 +6,7 @@ compile phase. Choose one of these three:
- `CompileThriftFinagle` - create the java bindings with alternative async interfaces for finagle, in `target/gen-java/`
- `CompileThriftJava` - create just the java bindings, in `target/gen-java/`
+- `CompileThriftPhp` - create just the PHP bindings, in `target/gen-php/`
- `CompileThriftPython` - create just the python bindings, in `target/gen-py/ (or target/gen-py.twisted/)`
- `CompileThriftRuby` - create just the ruby bindings, in `target/gen-ruby/`
- `CompileThriftScala` - do `CompileThriftFinagle` and `CompileThriftRuby`, but also generate scala wrappers and implicit conversions in `target/gen-scala/`
View
46 src/main/scala/com/twitter/sbt/CompileThrift.scala
@@ -8,13 +8,17 @@ import java.io.{File, FileOutputStream, BufferedOutputStream}
// TODO support multiple thrift versions
object CompileThrift {
- var cachedFinaglePath: Option[String] = None
- var cachedVanillaPath: Option[String] = None
+ var cachedThriftPath: Option[(String, String)] = None
}
trait CompileThrift extends DefaultProject with GeneratedSources {
import CompileThrift._
+ private[this] val env = jcl.Map(System.getenv())
+
+ // name of the thrift binary
+ lazy val thriftname = "thrift"
+
private[this] lazy val platform = System.getProperty("os.name") match {
case "Mac OS X" => "osx10.6"
case "Linux" => System.getProperty("os.arch") match {
@@ -59,22 +63,20 @@ trait CompileThrift extends DefaultProject with GeneratedSources {
path
}
- lazy val thriftBinFinagle = CompileThrift.synchronized {
- if (!cachedFinaglePath.isDefined) {
- cachedFinaglePath = Some(extractBinary("thrift-finagle." + platform))
- }
-
- cachedFinaglePath.get
- }
-
- lazy val thriftBinVanilla = CompileThrift.synchronized {
- if (!cachedVanillaPath.isDefined) {
- cachedVanillaPath = Some(extractBinary("thrift." + platform))
+ lazy val thriftBin = env.get("SBT_THRIFT_BIN") getOrElse
+ CompileThrift.synchronized {
+ val cached = for {
+ (cachedThrift, cachedPath) <- cachedThriftPath
+ if cachedThrift == thriftname
+ } yield cachedPath
+
+ cached getOrElse {
+ val path = extractBinary(thriftname + "." + platform)
+ cachedThriftPath = Some((thriftname, path))
+ path
+ }
}
- cachedVanillaPath.get
- }
-
def thriftSources = (mainSourcePath / "thrift" ##) ** "*.thrift"
/** override to disable auto-compiling of thrift */
@@ -95,8 +97,18 @@ trait CompileThrift extends DefaultProject with GeneratedSources {
val tasks = exclusions.foldLeft(thriftSources) { (finder, name) =>
finder --- (mainSourcePath / "thrift" / (name + ".thrift"))
}.getPaths.map { path =>
- execTask { "%s %s --gen %s -o %s %s".format(thriftBinVanilla, thriftIncludes, lang, outputPath.absolutePath, path) }
+ execTask { "%s %s --gen %s -o %s %s".format(thriftBin, thriftIncludes, lang, outputPath.absolutePath, path) }
}
if (tasks.isEmpty) None else tasks.reduceLeft { _ && _ }.run
} describedAs("Compile thrift into %s".format(lang))
+
+ lazy val compileThriftJava = compileThriftAction("java")
+ lazy val autoCompileThriftJava = task {
+ if (autoCompileThriftEnabled) {
+ compileThriftJava.run
+ } else {
+ log.info("%s: not auto-compiling thrift-java; you may need to run compile-thrift-java manually".format(name))
+ None
+ }
+ }
}
View
27 src/main/scala/com/twitter/sbt/CompileThriftFinagle.scala
@@ -6,31 +6,6 @@ import java.io.File
trait CompileThriftFinagle
extends DefaultProject with CompileThrift
{
- // thrift generation.
- override def compileThriftAction(lang: String) = task {
- import Process._
- outputPath.asFile.mkdirs()
-
- val thriftIncludes = thriftIncludeFolders.map { folder =>
- "-I " + new File(folder).getAbsolutePath
- }.mkString(" ")
-
- val tasks = thriftSources.getPaths.map { path =>
- execTask { "%s %s --gen %s -o %s %s".format(thriftBinFinagle, thriftIncludes, lang, outputPath.absolutePath, path) }
- }
- if (tasks.isEmpty) None else tasks.reduceLeft { _ && _ }.run
- } describedAs("Compile thrift into %s".format(lang))
-
- lazy val compileThriftJava = compileThriftAction("java")
-
- lazy val autoCompileThriftJava = task {
- if (autoCompileThriftEnabled) {
- compileThriftJava.run
- } else {
- log.info("%s: not auto-compiling thrift-java; you may need to run compile-thrift-java manually".format(name))
- None
- }
- }
-
+ override lazy val thriftname = "thrift-finagle"
override def compileAction = super.compileAction dependsOn(autoCompileThriftJava)
}
View
11 src/main/scala/com/twitter/sbt/CompileThriftJava.scala
@@ -3,16 +3,5 @@ package com.twitter.sbt
import _root_.sbt._
trait CompileThriftJava extends CompileThrift {
- lazy val compileThriftJava = compileThriftAction("java")
-
- lazy val autoCompileThriftJava = task {
- if (autoCompileThriftEnabled) {
- compileThriftJava.run
- } else {
- log.info("%s: not auto-compiling thrift-java; you may need to run compile-thrift-java manually".format(name))
- None
- }
- }
-
override def compileAction = super.compileAction dependsOn(autoCompileThriftJava)
}
View
21 src/main/scala/com/twitter/sbt/CompileThriftPhp.scala
@@ -0,0 +1,21 @@
+package com.twitter.sbt
+
+import _root_.sbt._
+
+/**
+ * Generate plain-old-php bindings
+ */
+trait CompileThriftPhp extends CompileThrift {
+ lazy val compileThriftPhp = compileThriftAction("php")
+
+ lazy val autoCompileThriftPhp = task {
+ if (autoCompileThriftEnabled) {
+ compileThriftPhp.run
+ } else {
+ log.info("%s: not auto-compiling thrift-php; you may need to run compile-thrift-php manually".format(name))
+ None
+ }
+ }
+
+ override def compileAction = super.compileAction dependsOn(autoCompileThriftPhp)
+}
View
3  src/main/scala/com/twitter/sbt/GeneratedSources.scala
@@ -5,11 +5,13 @@ import _root_.sbt._
trait GeneratedSources extends DefaultProject {
def generatedJavaDirectoryName = "gen-java"
def generatedRubyDirectoryName = "gen-rb"
+ def generatedPhpDirectoryName = "gen-php"
def generatedPythonDirectoryName = "gen-py"
def generatedScalaDirectoryName = "gen-scala"
def generatedJavaPath = outputPath / generatedJavaDirectoryName
def generatedRubyPath = outputPath / generatedRubyDirectoryName
+ def generatedPhpPath = outputPath / generatedPhpDirectoryName
def generatedPythonPath = outputPath / generatedPythonDirectoryName
def generatedScalaPath = outputPath / generatedScalaDirectoryName
@@ -18,6 +20,7 @@ trait GeneratedSources extends DefaultProject {
lazy val cleanGenerated = (
cleanTask(generatedJavaPath) && cleanTask(generatedRubyPath)
&& cleanTask(generatedPythonPath) && cleanTask(generatedScalaDirectoryName)
+ && cleanTask(generatedPhpPath)
) describedAs "Clean generated source folders"
override def cleanAction = super.cleanAction dependsOn(cleanGenerated)
Please sign in to comment.
Something went wrong with that request. Please try again.