Skip to content

Use snake_case for generated proto files. #40

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rosidl_adapter_proto/bin/rosidl_adapter_proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import sys
import pathlib
import os

from rosidl_cmake import read_generator_arguments
from rosidl_cmake import read_generator_arguments, convert_camel_case_to_lower_case_underscore
from rosidl_adapter_proto import generate_proto
from rosidl_adapter_proto import compile_proto

Expand Down Expand Up @@ -65,10 +65,11 @@ def main(argv=sys.argv[1:]):
assert len(idl_parts) == 2
idl_rel_path = pathlib.Path(idl_parts[1])
idl_stem = idl_rel_path.stem
proto_stem = convert_camel_case_to_lower_case_underscore(idl_stem)
generated_file = os.path.join(
generator_args['output_dir'],
str(idl_rel_path.parent),
idl_stem + ".proto"
proto_stem + ".proto"
)
proto_files.append(str(pathlib.Path(generated_file).resolve()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
get_filename_component(_parent_folder "${_abs_idl_file}" DIRECTORY)
get_filename_component(_parent_folder "${_parent_folder}" NAME)
get_filename_component(_idl_name "${_abs_idl_file}" NAME_WE)
list(APPEND rosidl_adapter_proto_GENERATED_CPP "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.pb.cc")
list(APPEND rosidl_adapter_proto_GENERATED_H "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.pb.h")
list(APPEND rosidl_adapter_proto_GENERATED_PROTO "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.proto")
string_camel_case_to_lower_case_underscore("${_idl_name}" _idl_name_lower)

list(APPEND rosidl_adapter_proto_GENERATED_CPP "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name_lower}.pb.cc")
list(APPEND rosidl_adapter_proto_GENERATED_H "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name_lower}.pb.h")
list(APPEND rosidl_adapter_proto_GENERATED_PROTO "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name_lower}.proto")
endforeach()

add_custom_command(
Expand Down
2 changes: 1 addition & 1 deletion rosidl_adapter_proto/resource/idl.proto.em
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ for action in content.get_elements_of_type(Action):
interface_path=interface_path,
action=action,
)
}@
}@
11 changes: 8 additions & 3 deletions rosidl_adapter_proto/rosidl_adapter_proto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import subprocess
import zlib

from rosidl_cmake import generate_files
from rosidl_cmake import generate_files, convert_camel_case_to_lower_case_underscore
import rosidl_parser.definition as rosidl

# A postfix for the protobuf package name / the c++ namespace
Expand Down Expand Up @@ -83,7 +83,7 @@ def compute_proto_field_number(variable_name):

def to_proto_import(namespaced_type):
assert isinstance(namespaced_type, rosidl.NamespacedType)
return '/'.join(namespaced_type.namespaces + [namespaced_type.name]) + '.proto'
return '/'.join(namespaced_type.namespaces + [convert_camel_case_to_lower_case_underscore(namespaced_type.name)]) + '.proto'


def collect_proto_imports(rosidl_message):
Expand All @@ -108,7 +108,12 @@ def generate_proto(generator_arguments_file):
mapping = {
'idl.proto.em': '%s.proto',
}
generate_files(generator_arguments_file, mapping, keep_case=True)
generate_files(
generator_arguments_file,
mapping,
# Don't keep case - we want snake case
keep_case=False
)
return 0


Expand Down
6 changes: 3 additions & 3 deletions rosidl_adapter_proto/test/test_adapter_proto_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_message_proto_generated(message_idl_file):

proto_file_name = IdlLocator(
pathlib.Path(__file__).parent,
pathlib.Path('msg') / 'BoolTest.proto')
pathlib.Path('msg') / 'bool_test.proto')

assert search_word(proto_file_name.get_absolute_path(), member.name) is True
assert search_word(proto_file_name.get_absolute_path(), str(field_number)) is True
Expand Down Expand Up @@ -150,7 +150,7 @@ def test_to_proto_import(message_idl_file):
messages = message_idl_file.content.get_elements_of_type(Message)
namespace_type = messages[0].structure.namespaced_type
proto_import = to_proto_import(namespace_type)
assert proto_import == 'rosidl_adapter_proto/Bool.proto'
assert proto_import == 'rosidl_adapter_proto/bool.proto'


def test_to_proto_import_invalid_argument():
Expand All @@ -164,7 +164,7 @@ def test_collect_proto_import(message_idl_file):
for message in messages:
proto_import_set.update(collect_proto_imports(message))
for proto_file in proto_import_set:
assert proto_file == 'rosidl_adapter_proto/Bool.proto'
assert proto_file == 'rosidl_adapter_proto/bool.proto'


def test_collect_proto_import_invalid_argument():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def ros_message_functions_header_c_from_namespace(namespace, name):

def protobuf_message_header(package_name, interface_path):
include_parts = [package_name] + list(interface_path.parents[0].parts)
include_prefix = interface_path.stem
include_prefix = convert_camel_case_to_lower_case_underscore(interface_path.stem)

return '/'.join(include_parts + [include_prefix + '.pb.h'])

Expand Down
Loading