def test_translation_extensions(tmp_path, capsys): # NOTE(hidmic): pytest and empy do not play along, # the latter expects some proxy will stay in sys.stdout # and the former insists in overwriting it with capsys.disabled(): # so do everything in one run # Test .msg to .idl translation idl_files = translate(package_name='test_msgs', interface_files=[f'{DATA_PATH}:msg/Test.msg'], output_path=tmp_path, output_format='idl', translators=['msg2idl']) assert len(idl_files) == 1 idl_file = idl_files[0] assert idl_file == f'{tmp_path}:msg/Test.idl' assert filecmp.cmp(tmp_path / 'msg' / 'Test.idl', DATA_PATH / 'msg' / 'Test.expected.idl', shallow=False) # Test .srv to .idl translation idl_files = translate(package_name='test_msgs', interface_files=[f'{DATA_PATH}:srv/Test.srv'], output_path=tmp_path, output_format='idl', translators=['srv2idl']) assert len(idl_files) == 1 idl_file = idl_files[0] assert idl_file == f'{tmp_path}:srv/Test.idl' assert filecmp.cmp(tmp_path / 'srv' / 'Test.idl', DATA_PATH / 'srv' / 'Test.expected.idl', shallow=False) # Test .action to .idl translation idl_files = translate( package_name='test_msgs', interface_files=[f'{DATA_PATH}:action/Test.action'], output_path=tmp_path, output_format='idl', translators=['action2idl']) assert len(idl_files) == 1 idl_file = idl_files[0] assert idl_file == f'{tmp_path}:action/Test.idl' assert filecmp.cmp(tmp_path / 'action' / 'Test.idl', DATA_PATH / 'action' / 'Test.expected.idl', shallow=False)
def generate(self, package_name, interface_files, include_paths, output_path): package_share_path = \ pathlib.Path(get_package_share_directory('rosidl_generator_cpp')) templates_path = package_share_path / 'resource' # Normalize interface definition format to .idl idl_interface_files = [] non_idl_interface_files = [] for path in interface_files: if not path.endswith('.idl'): non_idl_interface_files.append(path) else: idl_interface_files.append(path) if non_idl_interface_files: idl_interface_files.extend( translate( package_name=package_name, interface_files=non_idl_interface_files, include_paths=include_paths, output_format='idl', output_path=output_path / 'tmp', )) # Generate code with legacy_generator_arguments_file( package_name=package_name, interface_files=idl_interface_files, include_paths=include_paths, templates_path=templates_path, output_path=output_path) as path_to_arguments_file: return generate_cpp(path_to_arguments_file)
def generate(self, package_name, interface_files, include_paths, output_path): generated_files = [] package_share_path = \ get_package_share_directory('rosidl_typesupport_c') templates_path = os.path.join(package_share_path, 'resource') # Normalize interface definition format to .idl idl_interface_files = [] non_idl_interface_files = [] for path in interface_files: if not path.endswith('.idl'): non_idl_interface_files.append(path) else: idl_interface_files.append(path) if non_idl_interface_files: idl_interface_files.extend( translate( package_name=package_name, interface_files=non_idl_interface_files, include_paths=include_paths, output_format='idl', output_path=output_path / 'tmp', )) # Generate visibility control file visibility_control_file_template_path = \ 'rosidl_typesupport_c__visibility_control.h.in' visibility_control_file_template_path = \ templates_path / visibility_control_file_template_path visibility_control_file_path = \ 'rosidl_typesupport_c__visibility_control.h' visibility_control_file_path = \ output_path / 'msg' / visibility_control_file_path generate_visibility_control_file( package_name=package_name, template_path=visibility_control_file_template_path, output_path=visibility_control_file_path) generated_files.append(visibility_control_file_path) # Generate typesupport code typesupport_implementations = list( get_resources('rosidl_typesupport_c')) with legacy_generator_arguments_file( package_name=package_name, interface_files=idl_interface_files, include_paths=include_paths, templates_path=templates_path, output_path=output_path) as path_to_arguments_file: generated_files.extend( generate_c(path_to_arguments_file, typesupport_implementations)) return generated_files
def generate(self, package_name, interface_files, include_paths, output_path): generated_files = [] package_share_path = \ pathlib.Path(get_package_share_directory('rosidl_generator_c')) templates_path = package_share_path / 'resource' # Normalize interface definition format to .idl idl_interface_files = [] non_idl_interface_files = [] for path in interface_files: if not path.endswith('.idl'): non_idl_interface_files.append(path) else: idl_interface_files.append(path) if non_idl_interface_files: idl_interface_files.extend( translate( package_name=package_name, interface_files=non_idl_interface_files, include_paths=include_paths, output_format='idl', output_path=output_path / 'tmp', )) # Generate visibility control file visibility_control_file_template_path = \ templates_path / 'rosidl_generator_c__visibility_control.h.in' visibility_control_file_path = \ output_path / 'msg' / 'rosidl_generator_c__visibility_control.h' generate_visibility_control_file( package_name=package_name, template_path=visibility_control_file_template_path, output_path=visibility_control_file_path) generated_files.append(visibility_control_file_path) # Generate code with legacy_generator_arguments_file( package_name=package_name, interface_files=idl_interface_files, include_paths=include_paths, templates_path=templates_path, output_path=output_path) as path_to_arguments_file: generated_files.extend(generate_c(path_to_arguments_file)) return generated_files
def generate(self, package_name, interface_files, include_paths, output_path): idl_pp = find_rti_connext_idl_preprocessor() # Normalize interface definition format to _.idl dds_idl_interface_files = [] non_dds_idl_interface_files = [] for path in interface_files: if not path.endswith('_.idl'): non_dds_idl_interface_files.append(path) else: dds_idl_interface_files.append(path) if non_dds_idl_interface_files: dds_idl_interface_files.extend( translate( package_name=package_name, interface_files=non_dds_idl_interface_files, include_paths=include_paths, output_format='dds_idl', output_path=output_path / 'tmp', )) generated_files = [] for idl_tuple in idl_tuples_from_interface_files( dds_idl_interface_files): prefix, _, stem = idl_tuple.rpartition(':') idl_file = os.path.join(prefix, stem) output_dir = os.path.join(output_path, os.path.dirname(stem)) os.makedirs(output_dir, exist_ok=True) # Generate RTI Connext specific code generated_files.extend( generate_dds_connext_cpp_file(package_name, idl_file, include_paths, output_dir, idl_pp)) return generated_files
def generate(self, package_name, interface_files, include_paths, output_path): package_share_path = \ get_package_share_directory('rosidl_typesupport_cpp') templates_path = os.path.join(package_share_path, 'resource') # Normalize interface definition format to .idl idl_interface_files = [] non_idl_interface_files = [] for path in interface_files: if not path.endswith('.idl'): non_idl_interface_files.append(path) else: idl_interface_files.append(path) if non_idl_interface_files: idl_interface_files.extend( translate( package_name=package_name, interface_files=non_idl_interface_files, include_paths=include_paths, output_format='idl', output_path=output_path / 'tmp', )) # Generate typesupport code typesupport_implementations = list( get_resources('rosidl_typesupport_cpp')) with legacy_generator_arguments_file( package_name=package_name, interface_files=idl_interface_files, include_paths=include_paths, templates_path=templates_path, output_path=output_path) as path_to_arguments_file: return generate_cpp(path_to_arguments_file, typesupport_implementations)