Skip to content

Commit c272bf6

Browse files
committed
Use snake_case for generated proto files.
From the Protocol Buffers style guide: "Files should be named lower_snake_case.proto." (https://protobuf.dev/programming-guides/style/)
1 parent e3de421 commit c272bf6

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

rosidl_adapter_proto/bin/rosidl_adapter_proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import sys
2323
import pathlib
2424
import os
2525

26-
from rosidl_cmake import read_generator_arguments
26+
from rosidl_cmake import read_generator_arguments, convert_camel_case_to_lower_case_underscore
2727
from rosidl_adapter_proto import generate_proto
2828
from rosidl_adapter_proto import compile_proto
2929

@@ -65,10 +65,11 @@ def main(argv=sys.argv[1:]):
6565
assert len(idl_parts) == 2
6666
idl_rel_path = pathlib.Path(idl_parts[1])
6767
idl_stem = idl_rel_path.stem
68+
proto_stem = convert_camel_case_to_lower_case_underscore(idl_stem)
6869
generated_file = os.path.join(
6970
generator_args['output_dir'],
7071
str(idl_rel_path.parent),
71-
idl_stem + ".proto"
72+
proto_stem + ".proto"
7273
)
7374
proto_files.append(str(pathlib.Path(generated_file).resolve()))
7475

rosidl_adapter_proto/cmake/rosidl_adapt_proto_interfaces.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
6262
get_filename_component(_parent_folder "${_abs_idl_file}" DIRECTORY)
6363
get_filename_component(_parent_folder "${_parent_folder}" NAME)
6464
get_filename_component(_idl_name "${_abs_idl_file}" NAME_WE)
65-
list(APPEND rosidl_adapter_proto_GENERATED_CPP "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.pb.cc")
66-
list(APPEND rosidl_adapter_proto_GENERATED_H "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.pb.h")
67-
list(APPEND rosidl_adapter_proto_GENERATED_PROTO "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.proto")
65+
string_camel_case_to_lower_case_underscore("${_idl_name}" _idl_name_lower)
66+
67+
list(APPEND rosidl_adapter_proto_GENERATED_CPP "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name_lower}.pb.cc")
68+
list(APPEND rosidl_adapter_proto_GENERATED_H "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name_lower}.pb.h")
69+
list(APPEND rosidl_adapter_proto_GENERATED_PROTO "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name_lower}.proto")
6870
endforeach()
6971

7072
add_custom_command(

rosidl_adapter_proto/resource/idl.proto.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ for action in content.get_elements_of_type(Action):
124124
interface_path=interface_path,
125125
action=action,
126126
)
127-
}@
127+
}@

rosidl_adapter_proto/rosidl_adapter_proto/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import subprocess
2020
import zlib
2121

22-
from rosidl_cmake import generate_files
22+
from rosidl_cmake import generate_files, convert_camel_case_to_lower_case_underscore
2323
import rosidl_parser.definition as rosidl
2424

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

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

8888

8989
def collect_proto_imports(rosidl_message):
@@ -108,7 +108,12 @@ def generate_proto(generator_arguments_file):
108108
mapping = {
109109
'idl.proto.em': '%s.proto',
110110
}
111-
generate_files(generator_arguments_file, mapping, keep_case=True)
111+
generate_files(
112+
generator_arguments_file,
113+
mapping,
114+
# Don't keep case - we want snake case
115+
keep_case=False
116+
)
112117
return 0
113118

114119

rosidl_adapter_proto/test/test_adapter_proto_message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_message_proto_generated(message_idl_file):
8888

8989
proto_file_name = IdlLocator(
9090
pathlib.Path(__file__).parent,
91-
pathlib.Path('msg') / 'BoolTest.proto')
91+
pathlib.Path('msg') / 'bool_test.proto')
9292

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

155155

156156
def test_to_proto_import_invalid_argument():
@@ -164,7 +164,7 @@ def test_collect_proto_import(message_idl_file):
164164
for message in messages:
165165
proto_import_set.update(collect_proto_imports(message))
166166
for proto_file in proto_import_set:
167-
assert proto_file == 'rosidl_adapter_proto/Bool.proto'
167+
assert proto_file == 'rosidl_adapter_proto/bool.proto'
168168

169169

170170
def test_collect_proto_import_invalid_argument():

rosidl_typesupport_protobuf/rosidl_typesupport_protobuf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def ros_message_functions_header_c_from_namespace(namespace, name):
8080

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

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

0 commit comments

Comments
 (0)