This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mmcbride
committed
Jan 16, 2012
1 parent
f8ceb4c
commit a8e5c0d
Showing
1 changed file
with
71 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,77 @@ | ||
Overview | ||
======== | ||
|
||
Sbt-thrift is an sbt plugin that adds a mixin for doing thrift code auto-generation during your | ||
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/` | ||
|
||
Scala Thrift Generation | ||
----------------------- | ||
|
||
`CompileThriftScala` implements a way of generating a Scala-wrapper for a | ||
[Finagle](http://twitter.github.com/finagle) Thrift service by using JRuby to | ||
inspect thrift-generated ruby code. It is therefore necessary for input thrift | ||
files to specify ruby and java namespace rules. If the java namespace is not | ||
specified in a `CompileThriftScala` object, it is assumed to be | ||
`_scala-namespace_.thrift`. In order to specify these namespaces, | ||
project specifications must provide a list of `ThriftNamespace`s, as follows: | ||
# Overview | ||
|
||
Sbt-thrift is an sbt 0.11 plugin that adds a mixin for doing thrift code auto-generation during your | ||
|
||
## Building | ||
|
||
Until standard-project is released as an sbt 0.11 plugin, you'll need | ||
to publish local. So... | ||
|
||
$sbt publish-local | ||
|
||
|
||
## Testing | ||
|
||
There is a really crude scripted plugin. You can run it with | ||
|
||
$sbt scripted | ||
|
||
## How it works | ||
|
||
The plugin registers itself as a source generator for the compile | ||
phase. Settings are added for both compile and test phases, so if you | ||
have thrift files in src/test/thrift they'll get processed too. | ||
|
||
## Getting SbtThrift | ||
|
||
See https://github.com/harrah/xsbt/wiki/Plugins for information on | ||
adding plugins. In general, you'll need to add the following to your | ||
project/plugins.sbt file: | ||
|
||
addSbtPlugin("com.twitter" % "sbt-thrift % "11.0.0-SNAPSHOT") | ||
|
||
## Mixing in SbtThrift | ||
|
||
### Using a .sbt file | ||
|
||
import sbt._ | ||
import com.twitter.sbt._ | ||
|
||
seq(SbtThrift.newSettings: _*) | ||
|
||
|
||
/** | ||
* Describes a scala project that relies on two Thrift IDLs, to be compiled to two different namespaces. | ||
*/ | ||
class TaxesProject(info: ProjectInfo) | ||
extends StandardServiceProject(info) | ||
with CompileThriftScala | ||
{ | ||
def finagleVersion = "1.2.5" | ||
def finagleCore = "com.twitter" % "finagle-core" % finagleVersion | ||
def finagleThrift = "com.twitter" % "finagle-thrift" % finagleVersion | ||
def finagleOstrich = "com.twitter" % "finagle-ostrich4" % finagleVersion | ||
### Using a .scala build definition | ||
|
||
import sbt._ | ||
import Keys._ | ||
import com.twitter.sbt._ | ||
|
||
def thriftNamespaces = | ||
new ThriftNamespace("Calculator", "gov.irs.taxes.calculator") // Java namespace inferred to be gov.irs.taxes.calculator.thrift | ||
:: new ThriftNamespace( "EZFile", "gov.irs.taxes.ezfile.nondefaultthriftnamespace", "gov.irs.taxes.ezfile") | ||
:: Nil | ||
object Util extends Build { | ||
lazy val root = Project(id = "util", base = file(".")) | ||
settings (SbtThrift.settings: _*) | ||
} | ||
|
||
## Settings Overview | ||
|
||
* thrift-name - name of thrift binary to use. Usually "thrift", but | ||
can be "thrift-finagle" if you want finagle bindings. | ||
* thrift-platform - qualifier for the thrift binary to use calculated | ||
from os.arch and os.name. | ||
* thrift-bin - the File to use for thrift gen. Usually extracted from | ||
the jar, but overridable with the SBT__THRIFT__BIN environment | ||
variable | ||
* thrift-sources-dir - where thrift source files are | ||
* thrift-gen-langs - languages to emit. This is just for thrift gen. | ||
It doesn't necessarily pass _all_ of these to sbt for compilation. | ||
* thrift-compile-langs - languages to compile. Java/Scala only, unless | ||
you extend stuff more | ||
* thrift-include-folders - folders to search for thrift includes. | ||
* thrift-sources - thrift files to process. Generated from | ||
thrift-sources-dir | ||
* thrift-output-dir - where to emit thrift files. | ||
* thrift-is-dirty - should we re-gen thrift files | ||
* thrift-gen - actually generate thrift | ||
|
||
## Where did scala thrift gen go? | ||
|
||
See https://github.com/twitter/sbt-scrooge | ||
|