Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove workarounds for output directory bug in flatc compiler #335

Open
jarkenau opened this issue Aug 21, 2023 · 0 comments
Open

Remove workarounds for output directory bug in flatc compiler #335

jarkenau opened this issue Aug 21, 2023 · 0 comments
Labels
enhancement New feature or request flatbuffer

Comments

@jarkenau
Copy link
Member

As google/flatbuffers#7397 is resolved, we can remove our workarounds.
This involves updating the calls to the flatc compiler in Cmake and the setup.py :

seerep/setup.py

Lines 77 to 103 in 021b88b

def from_fb(self) -> None:
"""
Currently the flatc compiler has a bug when using --python and --grpc, which prevents the use of -I and -o
for specifying input and output directories https://github.com/google/flatbuffers/issues/7397.
The current workaround is to copy the fbs files to the output directory, then run the flatc compiler in the
output dir and remove the .fbs files afterwards.
"""
shutil.copytree(self.fbs_msgs_path, self.bdist_dir, dirs_exist_ok=True)
shutil.copytree(self.fbs_interface_path, self.bdist_dir, dirs_exist_ok=True)
fbs_files = glob(f"{self.bdist_dir}/*.fbs")
flatc_call = [
"flatc",
"--python",
"--grpc",
# The compiler ONLY accepts filenames, no paths!
*[os.path.basename(file) for file in fbs_files],
]
if call(flatc_call, cwd=self.bdist_dir) != 0:
raise Exception("flatc call failed")
# Remove the .fbs files
for file in fbs_files:
with suppress(Exception):
os.remove(file)

set(FBS_INCLUDE_DIR ${SeerepMsgs_FLATBUFFERS_IMPORT_DIRS}
${SeerepMsgs_FLATBUFFERS_IMPORT_DIRS}/fbs/seerep/fb
)
foreach(FILENAME IN LISTS MY_FBS_FILES)
configure_file(
"${FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}" COPYONLY
)
endforeach()
add_custom_target(fbpyschemas)
add_custom_command(
TARGET fbpyschemas
COMMAND flatc -p -T --grpc "*.fbs" DEPENDS fbpyschemas
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/fbs/"
)

build_flatbuffers(
"${MY_FBS_FILES}"
""
fbschemas
""
"${CMAKE_CURRENT_BINARY_DIR}/fbs"
"${CMAKE_CURRENT_BINARY_DIR}/fbs"
""
)
add_library(FlatBuffersTarget INTERFACE)
target_include_directories(
FlatBuffersTarget INTERFACE ${FLATBUFFERS_INCLUDE_DIR}
)
add_dependencies(FlatBuffersTarget fbschemas)

@jarkenau jarkenau added enhancement New feature or request flatbuffer labels Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request flatbuffer
Projects
None yet
Development

No branches or pull requests

1 participant