From d7b4a31e93004e17fb320682b1801c1aaa9e7afc Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 25 Nov 2015 17:26:34 -0800 Subject: [PATCH] Added long form options for all generators (--cpp etc.) Short-form versions are still supported, but are deprecated. Change-Id: I15f70ca8d69ba5790368205caa9603b65e1b7fff Tested: on Linux. --- docs/html/md__compiler.html | 27 +++++++++++++++++-------- docs/source/Compiler.md | 34 +++++++++++++++++++++++--------- src/flatc.cpp | 34 +++++++++++++++++++------------- tests/generate_code.sh | 4 ++-- tests/monster_test.bfbs | Bin 2784 -> 2744 bytes tests/monster_test_generated.js | 2 ++ 6 files changed, 68 insertions(+), 33 deletions(-) diff --git a/docs/html/md__compiler.html b/docs/html/md__compiler.html index 2fe560da6..ff3f7fe22 100644 --- a/docs/html/md__compiler.html +++ b/docs/html/md__compiler.html @@ -61,18 +61,28 @@ $(document).ready(function(){initNavTree('md__compiler.html','');});
Using the schema compiler
-

Usage:

flatc [ -c ] [ -j ] [ -b ] [ -t ] [ -o PATH ] [ -I PATH ] [ -S ] FILES...
+

Usage:

flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] [ -S ] FILES...
       [ -- FILES...]
 

The files are read and parsed in order, and can contain either schemas or data (see below). Later files can make use of definitions in earlier files.

-- indicates that the following files are binary files in FlatBuffer format conforming to the schema(s) indicated before it. Incompatible binary files currently will give unpredictable results (!)

Depending on the flags passed, additional files may be generated for each file processed:

+

For any schema input files, one or more generators can be specified:

+
    +
  • --cpp, -c : Generate a C++ header for all definitions in this file (as filename_generated.h).
  • +
  • --java, -j : Generate Java code.
  • +
  • --csharp, -n : Generate C# code.
  • +
  • --go, -g : Generate Go code.
  • +
  • --python, -p: Generate Python code.
  • +
  • --javascript, -s: Generate JavaScript code.
  • +
  • --php: Generate PHP code.
  • +
+

For any data input files:

+
    +
  • --binary, -b : If data is contained in this file, generate a filename.bin containing the binary flatbuffer (or a different extension if one is specified in the schema).
  • +
  • --json, -t : If data is contained in this file, generate a filename.json representing the data in the flatbuffer.
  • +
+

Additional options:

    -
  • -c : Generate a C++ header for all definitions in this file (as filename_generated.h). Skipped for data.
  • -
  • -j : Generate Java classes. Skipped for data.
  • -
  • -n : Generate C# classes. Skipped for data.
  • -
  • -g : Generate Go classes. Skipped for data.
  • -
  • -b : If data is contained in this file, generate a filename.bin containing the binary flatbuffer.
  • -
  • -t : If data is contained in this file, generate a filename.json representing the data in the flatbuffer.
  • -o PATH : Output all generated files to PATH (either absolute, or relative to the current directory). If omitted, PATH will be the current directory. PATH should end in your systems path separator, e.g. / or \.
  • -I PATH : when encountering include statements, attempt to load the files from this path. Paths will be tried in the order given, and if all fail (or none are specified) it will try to load relative to the path of the schema file being parsed.
  • -M : Print make rules for generated files.
  • @@ -86,8 +96,9 @@ $(document).ready(function(){initNavTree('md__compiler.html','');});
  • --gen-onefile : Generate single output file (useful for C#)
  • --raw-binary : Allow binaries without a file_indentifier to be read. This may crash flatc given a mismatched schema.
  • --proto: Expect input files to be .proto files (protocol buffers). Output the corresponding .fbs file. Currently supports: package, message, enum, nested declarations, import (use -I for paths), extend, oneof, group. Does not support, but will skip without error: option, service, extensions, and most everything else.
  • -
  • --schema: Serialize schemas instead of JSON (use with -b). This will output a binary version of the specified schema that itself corresponds to the reflection/reflection.fbs schema. Loading this binary file is the basis for reflection functionality.
  • +
  • --schema: Serialize schemas instead of JSON (use with -b). This will output a binary version of the specified schema that itself corresponds to the reflection/reflection.fbs schema. Loading this binary file is the basis for reflection functionality.
+

NOTE: short-form options for generators are deprecated, use the long form whenever possible.

diff --git a/docs/source/Compiler.md b/docs/source/Compiler.md index 4e6b7994b..27ddf52e4 100755 --- a/docs/source/Compiler.md +++ b/docs/source/Compiler.md @@ -2,7 +2,7 @@ Usage: - flatc [ -c ] [ -j ] [ -b ] [ -t ] [ -o PATH ] [ -I PATH ] [ -S ] FILES... + flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] [ -S ] FILES... [ -- FILES...] The files are read and parsed in order, and can contain either schemas @@ -16,21 +16,34 @@ Incompatible binary files currently will give unpredictable results (!) Depending on the flags passed, additional files may be generated for each file processed: -- `-c` : Generate a C++ header for all definitions in this file (as - `filename_generated.h`). Skipped for data. +For any schema input files, one or more generators can be specified: -- `-j` : Generate Java classes. Skipped for data. +- `--cpp`, `-c` : Generate a C++ header for all definitions in this file (as + `filename_generated.h`). -- `-n` : Generate C# classes. Skipped for data. +- `--java`, `-j` : Generate Java code. -- `-g` : Generate Go classes. Skipped for data. +- `--csharp`, `-n` : Generate C# code. -- `-b` : If data is contained in this file, generate a - `filename.bin` containing the binary flatbuffer. +- `--go`, `-g` : Generate Go code. -- `-t` : If data is contained in this file, generate a +- `--python`, `-p`: Generate Python code. + +- `--javascript`, `-s`: Generate JavaScript code. + +- `--php`: Generate PHP code. + +For any data input files: + +- `--binary`, `-b` : If data is contained in this file, generate a + `filename.bin` containing the binary flatbuffer (or a different extension + if one is specified in the schema). + +- `--json`, `-t` : If data is contained in this file, generate a `filename.json` representing the data in the flatbuffer. +Additional options: + - `-o PATH` : Output all generated files to PATH (either absolute, or relative to the current directory). If omitted, PATH will be the current directory. PATH should end in your systems path separator, @@ -82,3 +95,6 @@ be generated for each file processed: output a binary version of the specified schema that itself corresponds to the reflection/reflection.fbs schema. Loading this binary file is the basis for reflection functionality. + +NOTE: short-form options for generators are deprecated, use the long form +whenever possible. diff --git a/src/flatc.cpp b/src/flatc.cpp index 337ce5d8e..2479da12b 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -28,7 +28,8 @@ struct Generator { const std::string &path, const std::string &file_name, const flatbuffers::GeneratorOptions &opts); - const char *generator_opt; + const char *generator_opt_short; + const char *generator_opt_long; const char *lang_name; flatbuffers::GeneratorOptions::Language lang; const char *generator_help; @@ -40,41 +41,41 @@ struct Generator { }; const Generator generators[] = { - { flatbuffers::GenerateBinary, "-b", "binary", + { flatbuffers::GenerateBinary, "-b", "--binary", "binary", flatbuffers::GeneratorOptions::kMAX, "Generate wire format binaries for any data definitions", flatbuffers::BinaryMakeRule }, - { flatbuffers::GenerateTextFile, "-t", "text", + { flatbuffers::GenerateTextFile, "-t", "--json", "text", flatbuffers::GeneratorOptions::kMAX, "Generate text output for any data definitions", flatbuffers::TextMakeRule }, - { flatbuffers::GenerateCPP, "-c", "C++", + { flatbuffers::GenerateCPP, "-c", "--cpp", "C++", flatbuffers::GeneratorOptions::kMAX, "Generate C++ headers for tables/structs", flatbuffers::CPPMakeRule }, - { flatbuffers::GenerateGo, "-g", "Go", + { flatbuffers::GenerateGo, "-g", "--go", "Go", flatbuffers::GeneratorOptions::kGo, "Generate Go files for tables/structs", flatbuffers::GeneralMakeRule }, - { flatbuffers::GenerateGeneral, "-j", "Java", + { flatbuffers::GenerateGeneral, "-j", "--java", "Java", flatbuffers::GeneratorOptions::kJava, "Generate Java classes for tables/structs", flatbuffers::GeneralMakeRule }, - { flatbuffers::GenerateJS, "-s", "JavaScript", + { flatbuffers::GenerateJS, "-s", "--js", "JavaScript", flatbuffers::GeneratorOptions::kMAX, "Generate JavaScript code for tables/structs", flatbuffers::JSMakeRule }, - { flatbuffers::GenerateGeneral, "-n", "C#", + { flatbuffers::GenerateGeneral, "-n", "--csharp", "C#", flatbuffers::GeneratorOptions::kCSharp, "Generate C# classes for tables/structs", flatbuffers::GeneralMakeRule }, - { flatbuffers::GeneratePython, "-p", "Python", + { flatbuffers::GeneratePython, "-p", "--python", "Python", flatbuffers::GeneratorOptions::kMAX, "Generate Python files for tables/structs", flatbuffers::GeneralMakeRule }, - { flatbuffers::GeneratePhp, "--php", "PHP", + { flatbuffers::GeneratePhp, nullptr, "--php", "PHP", flatbuffers::GeneratorOptions::kMAX, - "Generate Php files for tables/structs", + "Generate PHP files for tables/structs", flatbuffers::GeneralMakeRule }, }; @@ -86,8 +87,11 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) { if (usage) { printf("usage: %s [OPTION]... FILE... [-- FILE...]\n", program_name); for (size_t i = 0; i < sizeof(generators) / sizeof(generators[0]); ++i) - printf(" %s %s.\n", - generators[i].generator_opt, + printf(" %-12s %s %s.\n", + generators[i].generator_opt_long, + generators[i].generator_opt_short + ? generators[i].generator_opt_short + : " ", generators[i].generator_help); printf( " -o PATH Prefix PATH to all generated files.\n" @@ -179,7 +183,9 @@ int main(int argc, const char *argv[]) { print_make_rules = true; } else { for (size_t i = 0; i < num_generators; ++i) { - if (arg == generators[i].generator_opt) { + if (arg == generators[i].generator_opt_long || + (generators[i].generator_opt_short && + arg == generators[i].generator_opt_short)) { generator_enabled[i] = true; any_generator = true; goto found; diff --git a/tests/generate_code.sh b/tests/generate_code.sh index 91158bff4..91661f30d 100644 --- a/tests/generate_code.sh +++ b/tests/generate_code.sh @@ -1,2 +1,2 @@ -../flatc -c -j -n -g -b -p -s --php --gen-mutable --no-includes monster_test.fbs monsterdata_test.json -../flatc -b --schema monster_test.fbs +../flatc --cpp --java --csharp --go --binary --python --js --php --gen-mutable --no-includes monster_test.fbs monsterdata_test.json +../flatc --binary --schema monster_test.fbs diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index 8d54ead7e9a3a5047063843fdf0f38af5266385b..e5f51face696a1ee9b3aa64b70bba83df1c4645a 100644 GIT binary patch literal 2744 zcmaJ@O^91n6h4{!|4fqBF&(9pAVVodhITp(B1P&*>kl>sCr-hIoi~#g6G`3+$xCQl zhzl39Dy{}sBBc~@DXzK@aUs%05f??Il;TRda5-qLjo)|fyP1auFPxm0d%tt;ch0%z zzIRka)-SAYKw%VRQ4*4of|O+e{{+7x&qH2-oP!kRL{iWR=-1LBUt~qfkT-K8_wYZC zHR2yYc4NRnU%XUP|6J?(9=tE;9%<}Sz#K-5x(qoAA?{^wtoma-Z$UW!aDOs^f>(~5 zaxK6UwpO0I84=K$jw5)gyMth(-R*VUy0hJJFSmo%d2iUoN)9#&>~HM3_bGS|oeM&d zi@rAq+`i-{lL_OX)GpP|L&+BA$eH=6LXwbI{Epv;CjS=XEQEe<{h_?$^!+RBI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i$$c+Gwwzjyp9@^2lVd@8!qf%wo|QWsRG5 zwjQ_IQPYauZdZPZmd-7mX0kPSX`d@UJD>X{uUNbdDIU^00KHbP)|MiMzkAbv;50gY$alnMdf9P(- zKJDA&z1(b;x9XLZdcE3$Ww*f}u(7tRtjJIwcCBxjwJYRJbo~Z?;M*;^q&MjVY3PTk;muK_*M!ZgMY?eOz?-<<7PhG zH|;-s+va@SW)l3e#}B3P!GGcJalYRUC-{#%elU#>{tN$@^D(-E&K3V1kI$v?!GGb8 z{MPM`+Q9_>qsRBDhLkTQO1NckMVn4)c9%WuQOdw*BMuwY8f|rf4>=pL7ZRP#$F2sl zs(0y(p=hmAEw@)Xl?soUv4c#(rV{-JfA{)zrneTwQBAt8Q0eo zn^o7xN@!IF&$>SEfc%u80sb|l!#U&ni0>w z>dqmKY5YO~uKggf=@*}QKlxtkMM3%xGytl!2AAJ4S zC=P34GOm010p()7Ax?>V{=0kzFG37%2-+Lp^>oOGS~*sWv3Fg4WRo1-{?pf@VojU0 zM!jVxsA=g7y;gkrCpT0N(s!X@E3SJr~uXI^eZG1(wci|*}NW|qBVg`0+?Lv|M+-Qx%7bLbi*-6Rah_=W$7ms{ZHTZ^Q4$i{S6F#}yO{VU9BI!b`{Ns>ckg z*Ib39JCnNe&D6Q-S8pJ^72s|tPQm8g6#hNl#*=?$UIRGYA>>sy^}Y4~-z_B~6mlag zeuUi2uvKj+Cw{1(=v{?=Vo99*Th=$9^yzENfAay(C{N0v^eD!fFGGiV`-`r}ggW_W zAIKmPVsOvZxVO7P%!>aJGuiYv()Wk&1-=K`fMQcd^2wK@k00!eWI_yCx_Y}5cUpW3 F*)yDt; diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index d46a9c684..9d0f48b09 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -352,6 +352,8 @@ MyGame.Example.Stat.endStat = function(builder) { }; /** + * an example documentation comment: monster object + * * @constructor */ MyGame.Example.Monster = function() {