[Swift] Moves grpc example to grpc/examples (#6479)
[platform/upstream/flatbuffers.git] / tests / generate_code.sh
1 #!/bin/bash
2 #
3 # Copyright 2015 Google Inc. All rights reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 set -e
17
18 commandline="'$*'"
19
20 if [[ $commandline == *"--cpp-std c++0x"* ]]; then
21   TEST_CPP_FLAGS="--cpp-std c++0x"
22 else
23   # --cpp-std is defined by flatc default settings.
24   TEST_CPP_FLAGS=
25 fi
26
27 TEST_CPP_FLAGS="--gen-compare --cpp-ptr-type flatbuffers::unique_ptr $TEST_CPP_FLAGS"
28 TEST_CS_FLAGS="--cs-gen-json-serializer"
29 TEST_JS_TS_FLAGS="--gen-name-strings"
30 TEST_BASE_FLAGS="--reflect-names --gen-mutable --gen-object-api"
31 TEST_RUST_FLAGS="$TEST_BASE_FLAGS --gen-name-strings"
32 TEST_NOINCL_FLAGS="$TEST_BASE_FLAGS --no-includes"
33
34 ../flatc --binary --cpp --java --kotlin  --csharp --dart --go --lobster --lua --ts --php --grpc \
35 $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS -I include_test monster_test.fbs monsterdata_test.json
36 ../flatc --rust $TEST_RUST_FLAGS -I include_test monster_test.fbs monsterdata_test.json
37
38 ../flatc --python $TEST_BASE_FLAGS -I include_test monster_test.fbs monsterdata_test.json
39
40 ../flatc --cpp --java --kotlin --csharp --dart --go --binary --lobster --lua --ts --php --python \
41 $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS $TEST_JS_TS_FLAGS -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
42
43 # For Rust we currently generate two independent schemas, with namespace_test2
44 # duplicating the types in namespace_test1
45 ../flatc --rust --gen-all $TEST_RUST_FLAGS -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
46
47 ../flatc --cpp --java --kotlin --csharp --ts --php $TEST_BASE_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS $TEST_JS_TS_FLAGS -o union_vector ./union_vector/union_vector.fbs
48 ../flatc --rust -I include_test -o include_test include_test/include_test1.fbs
49 ../flatc --rust -I include_test -o include_test/sub include_test/sub/include_test2.fbs
50 ../flatc -b --schema --bfbs-comments --bfbs-builtins -I include_test monster_test.fbs
51 ../flatc --cpp --bfbs-comments --bfbs-builtins --bfbs-gen-embed $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS -I include_test monster_test.fbs
52 ../flatc -b --schema --bfbs-comments --bfbs-builtins -I include_test arrays_test.fbs
53 ../flatc --jsonschema --schema -I include_test monster_test.fbs
54 ../flatc --cpp --java --kotlin --csharp --python $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS monster_extra.fbs monsterdata_extra.json
55 ../flatc --cpp --java --csharp --jsonschema $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS --scoped-enums arrays_test.fbs
56 ../flatc --python $TEST_BASE_FLAGS arrays_test.fbs
57 ../flatc --dart monster_extra.fbs
58
59 # Generate optional scalar code for tests.
60 ../flatc --java --kotlin --lobster --ts optional_scalars.fbs
61 ../flatc --csharp --rust --gen-object-api optional_scalars.fbs
62 ../flatc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS --cpp optional_scalars.fbs
63
64 # Generate string/vector default code for tests
65 ../flatc --rust --gen-object-api more_defaults.fbs
66
67 # Generate the schema evolution tests
68 ../flatc --cpp --scoped-enums $TEST_CPP_FLAGS -o evolution_test ./evolution_test/evolution_v*.fbs
69
70 working_dir=`pwd`
71 cd FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests
72 $working_dir/../flatc --swift --grpc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS -I ${working_dir}/include_test ${working_dir}/monster_test.fbs
73 $working_dir/../flatc --swift $TEST_BASE_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS ${working_dir}/union_vector/union_vector.fbs
74 $working_dir/../flatc --swift ${working_dir}/optional_scalars.fbs
75 $working_dir/../flatc --swift --gen-object-api ${working_dir}/more_defaults.fbs
76 cd $working_dir
77
78 # Tests if the --filename-suffix and --filename-ext works and produces the same
79 # outputs.
80 ../flatc --cpp --filename-suffix _suffix --filename-ext hpp $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS -I include_test monster_test.fbs
81 if [ -f "monster_test_suffix.hpp" ]; then
82   if ! cmp -s "monster_test_suffix.hpp" "monster_test_generated.h"; then
83     echo "[Error] Filename suffix option did not produce identical results"
84   fi
85   rm "monster_test_suffix.hpp"
86 else
87   echo "[Error] Filename suffix option did not produce a file"
88 fi
89
90 # Flag c++17 requires Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914)  or higher.
91 TEST_CPP17_FLAGS="--cpp --cpp-std c++17 -o ./cpp17/generated_cpp17 $TEST_NOINCL_FLAGS"
92 ../flatc $TEST_CPP17_FLAGS -I include_test monster_test.fbs
93 ../flatc $TEST_CPP17_FLAGS optional_scalars.fbs
94
95 cd ../samples
96 ../flatc --cpp --rust --lobster $TEST_BASE_FLAGS $TEST_CPP_FLAGS monster.fbs
97 ../flatc -b --schema --bfbs-comments --bfbs-builtins monster.fbs
98 cd ../reflection
99 ./generate_code.sh --cpp-std c++0x