-
Notifications
You must be signed in to change notification settings - Fork 214
Add --message field to the creation of ROS2 packages.
#1202
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
base: rolling
Are you sure you want to change the base?
Changes from 3 commits
8d51b18
fdcd93c
c78fd5c
2b2272b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2026 Leander Stephen Desouza | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # TODO: Define the message fields here. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sure. |
||
| # For example: | ||
| # bool my_flag | ||
| # string my_string | ||
| # int32 my_number | ||
leander-dsouza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # if you use a non-trivial message type, do not forget to add its package to package.xml and CMakeLists.txt | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| import getpass | ||
| import os | ||
| import re | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
|
|
@@ -33,6 +34,7 @@ | |
| from ros2pkg.api.create import populate_cmake | ||
| from ros2pkg.api.create import populate_cpp_library | ||
| from ros2pkg.api.create import populate_cpp_node | ||
| from ros2pkg.api.create import populate_messages | ||
| from ros2pkg.api.create import populate_python_libary | ||
| from ros2pkg.api.create import populate_python_node | ||
| from ros2pkg.api.create import populate_rust_node | ||
|
|
@@ -90,6 +92,12 @@ def add_arguments(self, parser, cli_name): | |
| parser.add_argument( | ||
| '--library-name', | ||
| help='name of the empty library') | ||
| parser.add_argument( | ||
| '--message', | ||
| nargs='+', | ||
| default=[], | ||
| metavar='MESSAGE_NAME', | ||
| help='name(s) of message files to create in msg/') | ||
|
|
||
| def main(self, *, args): | ||
|
|
||
|
|
@@ -136,12 +144,26 @@ def get_git_config(key: str) -> Optional[str]: | |
| print('[WARNING] node name can not be equal to the library name', file=sys.stderr) | ||
| print('[WARNING] renaming node to %s' % node_name, file=sys.stderr) | ||
|
|
||
| if args.message: | ||
| if args.build_type != 'ament_cmake': | ||
| return "Aborted: --message is only supported with 'ament_cmake' build type." | ||
|
|
||
| invalid = [ | ||
| name for name in args.message | ||
| if not re.match(r'^[A-Z][A-Za-z0-9]*$', name) | ||
|
||
| ] | ||
| if invalid: | ||
| return 'Aborted: invalid message name(s): ' + ', '.join(invalid) + \ | ||
| '. Message names must be CamelCase and alphanumeric (e.g. MyMsg).' | ||
|
Comment on lines
+147
to
+157
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we check the message duplication check here? e.g
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a check to prevent duplicate messages :) |
||
|
|
||
| buildtool_depends = [] | ||
| if args.build_type == 'ament_cmake': | ||
| if args.library_name: | ||
| buildtool_depends = ['ament_cmake_ros'] | ||
| else: | ||
| buildtool_depends = ['ament_cmake'] | ||
| if args.message: | ||
| buildtool_depends.append('rosidl_default_generators') | ||
|
|
||
| if args.build_type == 'ament_cargo': | ||
| buildtool_depends = ['ament_cargo'] | ||
|
|
@@ -153,6 +175,12 @@ def get_git_config(key: str) -> Optional[str]: | |
| test_dependencies = ['ament_copyright', 'ament_flake8', 'ament_mypy', 'ament_pep257', | ||
| 'ament_xmllint', 'python3-pytest'] | ||
|
|
||
| member_of_group_depends = [] | ||
| exec_depends = [] | ||
| if args.message: | ||
| member_of_group_depends.append('rosidl_interface_packages') | ||
| exec_depends.append('rosidl_default_runtime') | ||
|
|
||
| if args.build_type == 'ament_python' and args.package_name == 'test': | ||
| # If the package name is 'test', there will be a conflict between | ||
| # the directory the source code for the package goes in and the | ||
|
|
@@ -169,6 +197,8 @@ def get_git_config(key: str) -> Optional[str]: | |
| licenses=[args.license], | ||
| buildtool_depends=[Dependency(dep) for dep in buildtool_depends], | ||
| build_depends=[Dependency(dep) for dep in args.dependencies], | ||
| exec_depends=[Dependency(dep) for dep in exec_depends], | ||
| member_of_groups=member_of_group_depends, | ||
| test_depends=[Dependency(dep) for dep in test_dependencies], | ||
| exports=[Export('build_type', content=args.build_type)] | ||
| ) | ||
|
|
@@ -192,6 +222,8 @@ def get_git_config(key: str) -> Optional[str]: | |
| print('node_name:', node_name) | ||
| if library_name: | ||
| print('library_name:', library_name) | ||
| if args.message: | ||
| print('messages:', args.message) | ||
|
|
||
| package_directory, source_directory, include_directory = \ | ||
| create_package_environment(package, args.destination_directory) | ||
|
|
@@ -202,7 +234,8 @@ def get_git_config(key: str) -> Optional[str]: | |
| populate_cmake(package, package_directory, node_name, library_name) | ||
|
|
||
| if args.build_type == 'ament_cmake': | ||
| populate_ament_cmake(package, package_directory, node_name, library_name) | ||
| populate_ament_cmake(package, package_directory, node_name, library_name, | ||
| message_names=args.message) | ||
|
|
||
| if args.build_type == 'ament_cargo': | ||
| populate_ament_cargo(package, package_directory, library_name) | ||
|
|
@@ -239,6 +272,9 @@ def get_git_config(key: str) -> Optional[str]: | |
| node_name | ||
| ) | ||
|
|
||
| if args.message: | ||
| populate_messages(package_directory, args.message) | ||
|
|
||
| if args.license in available_licenses: | ||
| with open(os.path.join(package_directory, 'LICENSE'), 'w') as outfp: | ||
| for lic in available_licenses[args.license]: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.