Thrift 编译器——生成不同的语言到不同的输出路径

Thrift compiler - generate different languages to different output paths

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

我正在编写一个 Java 客户端和 C# 服务器,我希望从 -gen java-gen csharp 生成的文件位于我项目的不同目录中。

可能吗?

1。默认

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

thrift -gen java -gen csharp myfile.thrift

在您的情况下,这将是 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

更多信息

输入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 ...)

TL;DR

Is it possible?

是的,是的。