From 0c49eb703150aa1539e2f315918bb76c57c84a68 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Mon, 14 Oct 2024 18:37:34 +0100 Subject: [PATCH 1/2] missing library file --- open-codegen/opengen/builder/ros_builder.py | 32 +++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/open-codegen/opengen/builder/ros_builder.py b/open-codegen/opengen/builder/ros_builder.py index 0108a8a5..ba89c092 100644 --- a/open-codegen/opengen/builder/ros_builder.py +++ b/open-codegen/opengen/builder/ros_builder.py @@ -34,6 +34,11 @@ class RosBuilder: """ def __init__(self, meta, build_config, solver_config): + if os.name == 'nt': + self.__logger.warning( + "You're on Windows; you will not be able to run ROS!") + self.__logger.info( + "The ROS code will be generated, but without the static library") self.__meta = meta self.__build_config = build_config self.__solver_config = solver_config @@ -106,7 +111,10 @@ def __copy__ros_files(self): target_ros_dir, 'include', header_file_name)) original_include_file = os.path.abspath( os.path.join(self.__target_dir(), header_file_name)) - shutil.copyfile(original_include_file, target_include_filename) + try: + shutil.copyfile(original_include_file, target_include_filename) + except: + pass # 2. --- copy library file lib_file_name = 'lib' + self.__meta.optimizer_name + '.a' @@ -120,7 +128,27 @@ def __copy__ros_files(self): 'target', self.__build_config.build_mode, lib_file_name)) - shutil.copyfile(original_lib_file, target_lib_file_name) + + if not os.path.exists(original_lib_file): + # No static library file (most likely, because the user is on Windows) + # otherwise an error would have been produced earlier. Windows produces + # a DLL file, however it doesn't make sense to move it to the target + # directory (extern_lib) because ROS doesn't run on Windows anyway + self.__logger.warning( + f"File {original_lib_file} not found; proceeding without") + if os.name == 'nt': + self.__logger.warning( + "File {lib_file_name} not found because you're running on Windows") + # Create a LIBRARY_MISSING_README.md file in the target directory + warning_file_name = \ + os.path.abspath(os.path.join( + target_ros_dir, 'extern_lib', 'LIBRARY_MISSING_README.md')) + with open(warning_file_name, 'w') as wfh: + wfh.write(f"""WARNING!\n\n +Library file {lib_file_name} is missing. You will need to compile +on the target device and copy the library file here by yourself.""") + else: + shutil.copyfile(original_lib_file, target_lib_file_name) # 3. --- copy msg file OptimizationParameters.msg original_params_msg = os.path.abspath( From c4af72656702416881fd49c077619db7fd278f00 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Mon, 14 Oct 2024 22:53:52 +0100 Subject: [PATCH 2/2] addressing #360 --- open-codegen/opengen/builder/optimizer_builder.py | 5 +++++ open-codegen/opengen/builder/ros_builder.py | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/open-codegen/opengen/builder/optimizer_builder.py b/open-codegen/opengen/builder/optimizer_builder.py index 55c96f64..75f46603 100644 --- a/open-codegen/opengen/builder/optimizer_builder.py +++ b/open-codegen/opengen/builder/optimizer_builder.py @@ -860,6 +860,11 @@ def build(self): self.__build_python_bindings() if self.__build_config.ros_config is not None: + if self.__generate_not_build: + self.__logger.fatal( + "Do not use with_ros and with_generate_not_build_flag simultaneously") + raise ValueError( + "Unless the optimiser has been built, a ROS package cannot be generated") ros_builder = RosBuilder( self.__meta, self.__build_config, diff --git a/open-codegen/opengen/builder/ros_builder.py b/open-codegen/opengen/builder/ros_builder.py index ba89c092..2e06694a 100644 --- a/open-codegen/opengen/builder/ros_builder.py +++ b/open-codegen/opengen/builder/ros_builder.py @@ -111,10 +111,7 @@ def __copy__ros_files(self): target_ros_dir, 'include', header_file_name)) original_include_file = os.path.abspath( os.path.join(self.__target_dir(), header_file_name)) - try: - shutil.copyfile(original_include_file, target_include_filename) - except: - pass + shutil.copyfile(original_include_file, target_include_filename) # 2. --- copy library file lib_file_name = 'lib' + self.__meta.optimizer_name + '.a'