Rebased: grpc/compiler: Respect filename suffix and extension during code generation (#7414)

* grpc/compiler: Respect filename suffix and extension during code generation

grpc compiler is not respecting filename suffix and extension passed to
flatc CLI. This causes compiler to spit out incorrect code, which then
cannot be compiled without modification.

Following patch fixes the problem.

Note, I ended up removing some code introduced #6954 ("Have grpc include
file with correct filename-suffix given to flatc") in favour of keeping
sanity of the generator code.

Signed-off-by: Aman Priyadarshi <aman.eureka@gmail.com>

* tests: Add filename-suffix and filename-ext test files

* Test 1: Filename extension changed to "hpp".
* Test 2: Filename suffix changed to "_suffix".
* Test 3: Filename extension changed to "hpp" and suffix changed to "_suffix"

Signed-off-by: Aman Priyadarshi <aman.eureka@gmail.com>
This commit is contained in:
Aman Priyadarshi
2022-08-07 19:32:53 +01:00
committed by GitHub
parent 47c757f714
commit 468c00a3fe
14 changed files with 13596 additions and 25 deletions

View File

@@ -425,17 +425,23 @@ flatc(
# --filename-suffix and --filename-ext tests
flatc(
CPP_OPTS + NO_INCL_OPTS + ["--filename-suffix", "_suffix", "--filename-ext", "hpp"],
CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-ext", "hpp"],
include="include_test",
prefix="monster_test_suffix/ext_only",
schema="monster_test.fbs",
)
flatc(
CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-suffix", "_suffix"],
include="include_test",
prefix="monster_test_suffix/filesuffix_only",
schema="monster_test.fbs",
)
flatc(
CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-suffix", "_suffix", "--filename-ext", "hpp"],
include="include_test",
prefix="monster_test_suffix",
schema="monster_test.fbs",
)
orig_monster_file = Path(tests_path, "monster_test_generated.h")
new_monster_file = Path(tests_path, "monster_test_suffix.hpp")
assert new_monster_file.exists(), "filename suffix option did not produce a file"
assert filecmp.cmp(
str(orig_monster_file), str(new_monster_file)
), "filename suffix option did not produce identical results"
new_monster_file.unlink()
# Flag c++17 requires Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher.
cpp_17_prefix = "cpp17/generated_cpp17"