Thrift编译器 - 为不同的输出路径生成不同的语言

Eli*_*ist 3 c# java thrift

Thrift编译器允许为生成的文件指定输出目录.

我写一个Java客户端和C#的服务器,我想有从生成的文件-gen java-gen csharp设在我的项目的不同的目录.

可能吗?

Jen*_*nsG 7

1.默认情况下

...文件按照模式生成到每种语言的一个文件夹中gen-<lang>.

thrift -gen java -gen csharp myfile.thrift
Run Code Online (Sandbox Code Playgroud)

在你的情况下,这将是gen-csharpgen-java.如果这不符合您的要求,请尝试

2.明确的外向路径

通过-out参数,您可以告诉Thrift在您想要的任何文件夹中生成代码.唯一需要注意的是,必须事先创建这些目标文件夹.除了使用默认文件夹,这些文件夹不会自动创建.

mkdir my/cool/javadir 
mkdir my/cool/csdir   
thrift -gen java   -out my/cool/javadir myfile.thrift
thrift -gen csharp -out my/cool/csdir   myfile.thrift
Run Code Online (Sandbox Code Playgroud)

更多信息

输入thrift -help以查看所有选项:

$ thrift -help
Usage: thrift [options] file
Options:
  -version    Print the compiler version
  -o dir      Set the output directory for gen-* packages
               (default: current directory)
  -out dir    Set the ouput location for generated files.
               (no gen-* folder will be created)
  -I dir      Add a directory to the list of directories
                searched for include directives
  -nowarn     Suppress all compiler warnings (BAD!)
  -strict     Strict compiler warnings on
  -v[erbose]  Verbose mode
  -r[ecurse]  Also generate included files
  -debug      Parse debug trace to stdout
  --allow-neg-keys  Allow negative field keys (Used to preserve protocol
                compatibility with older .thrift files)
  --allow-64bit-consts  Do not print warnings about using 64-bit constants
  --gen STR   Generate code with a dynamically-registered generator.
                STR has the form language[:key1=val1[,key2[,key3=val3]]].
                Keys and values are options passed to the generator.
                Many options will not require values.

Available generators (and options):
(... more options ...)
Run Code Online (Sandbox Code Playgroud)

TL; DR

可能吗?

是的.