Skip to content

Add --message field to the creation of ROS2 packages.#1202

Open
leander-dsouza wants to merge 3 commits intoros2:rollingfrom
leander-dsouza:add-msg-field-ros2pkg
Open

Add --message field to the creation of ROS2 packages.#1202
leander-dsouza wants to merge 3 commits intoros2:rollingfrom
leander-dsouza:add-msg-field-ros2pkg

Conversation

@leander-dsouza
Copy link
Contributor

@leander-dsouza leander-dsouza commented Mar 2, 2026

Basic Info

Info Please fill out this column
Ticket(s) this addresses Assists #1015
Primary OS tested on Ubuntu

Description

  • Adds the --message field to the ros2 pkg create command.
  • The boilerplate for each custom message is as follows:
    MyMsg.msg
    # TODO: Define the message fields here.
    # For example:
    # bool my_flag
    # string my_string
    # int32 my_number
    
  • Include a regex validation that only allows CamelCase alphanumeric message types to exist.
  • The message field is restricted to only the ament_cmake build type.
  • The tests have been modified to include checks for two messages - MyMsg and OtherMsg.

Usage

  • You can include the --message field followed by an indefinite number of messages as follows:

    $ ros2 pkg create tutorial_interfaces --build-type ament_cmake --license Apache-2.0 --message MyMsg OtherMsg
    
    going to create a new package
    package name: tutorial_interfaces
    destination directory: <destination path>
    package format: 3
    version: 0.0.0
    description: TODO: Package description
    maintainer: ["<your name> <your email address>"]
    licenses: ['Apache-2.0']
    build type: ament_cmake
    dependencies: []
    messages: ['MyMsg', 'OtherMsg']
    creating folder ./tutorial_interfaces
    creating ./tutorial_interfaces/package.xml
    creating source and include folder
    creating folder ./tutorial_interfaces/src
    creating folder ./tutorial_interfaces/include/tutorial_interfaces
    creating ./tutorial_interfaces/CMakeLists.txt
    creating folder ./tutorial_interfaces/msg
    creating ./tutorial_interfaces/msg/MyMsg.msg
    creating ./tutorial_interfaces/msg/OtherMsg.msg   
  • If you include an invalid message name, it would fail the creation step:

    $ ros2 pkg create tutorial_interfaces --build-type ament_cmake --license Apache-2.0 --message mymsg
    
    Aborted: invalid message name(s): mymsg. Message names must be CamelCase and alphanumeric (e.g. MyMsg).
  • The creation step would also fail if the build type is not ament_cmake:

    $ ros2 pkg create tutorial_interfaces --build-type ament_python --license Apache-2.0 --message MyMsg
    
    Aborted: --message is only supported with 'ament_cmake' build type.

Is this user-facing behaviour change?

Yes, please refer to the Usage section for more details on how the implementation affects the user's creation of the ROS2 package.

Did you use Generative AI?

No

Additional Information

Future work can include adding fields for actions and services.

@leander-dsouza leander-dsouza marked this pull request as ready for review March 2, 2026 03:19
Copy link
Contributor

@peci1 peci1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have a few small comments, but nothing important.

@@ -0,0 +1,5 @@
# TODO: Define the message fields here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License text is missing. However, the other template files also don't have it, so maybe let's leave it to another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure.
We can add the license texts to all the template files in a future PR.

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