Search code examples
javac#thrift

Thrift compiler - generate different languages to different output paths


Thrift compiler allows specifying output directory for generated files.

I am writing a Java client and C# server, and I would like to have the generated files from -gen java and -gen csharp be located in different directories of my project.

Is it possible?


Solution

  • 1. By default

    ... files are generated into one folder per language, following the pattern gen-<lang>.

    thrift -gen java -gen csharp myfile.thrift
    

    In your case this would be gen-csharp and gen-java. If that does not meet your requirements, try

    2. Explicit out-path

    By means of the -out parameter you can tell Thrift to generate code in any folder you want. The only caveat is that these target folders must be created beforehand. Other than with the default folders these are not created automatically.

    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
    

    More info

    Enter thrift -help to see all the options:

    $ 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?

    Yes, it is.