Skip to content

fix(interfaces): strip self-package qualifier from same-package .msg field types#17

Open
xiangguomin wants to merge 1 commit into
rai-opensource:mainfrom
xiangguomin:fix/strip-self-package-qualifier-in-msg-output
Open

fix(interfaces): strip self-package qualifier from same-package .msg field types#17
xiangguomin wants to merge 1 commit into
rai-opensource:mainfrom
xiangguomin:fix/strip-self-package-qualifier-in-msg-output

Conversation

@xiangguomin
Copy link
Copy Markdown

Problem

dump_message_specification() emits fully qualified type references for fields
whose type belongs to the same package as the message being serialised. For
example, proto2ros/List.msg is generated as:

proto2ros/Value[] values

This violates the rosidl convention: same-package references must be bare
(Value[] values), while cross-package references use the pkg/Type form.
When the generated .msg files are consumed by a Bazel ros2_interface_library
target, rosidl's type-description generator fails with:

KeyError: 'proto2ros'

because it looks up proto2ros in its include map and cannot find the package's
own entry there.

Fix

In dump_message_specification(), after serialising each field to a string,
check whether field.type.pkg_name matches the enclosing message's package
(message_spec.base_type.pkg_name). If so, strip the self-package prefix from
the output line. Cross-package references and primitive fields (where
field.type.pkg_name is None) are unaffected.

Tests

Three unit tests added to proto2ros/output/test_interfaces.py:

  • test_dump_strips_self_package_qualifier — verifies the fix
  • test_dump_preserves_cross_package_qualifier — verifies cross-package refs are untouched
  • test_dump_preserves_primitive_fields — verifies messages with no cross-package fields are unaffected

…field types

rosidl's type-description generator fails with KeyError when a package's
own .msg files use fully qualified self-references such as
`proto2ros/Value[] values` (where the enclosing message also belongs to
`proto2ros`). The rosidl convention — followed by every other ROS package
— is to use bare type names for same-package references and fully qualified
names only for cross-package references.

Fix dump_message_specification() to strip the self-package prefix from a
field's serialised type string when field.type.pkg_name matches the
message's own package. Cross-package references and primitive fields are
unaffected.

Adds three unit tests covering: self-reference stripping, cross-package
preservation, and primitive (no-package) fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants