Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion rosidl_generator_rs/bin/rosidl_generator_rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ def main(argv=sys.argv[1:]):
'--typesupport-impls',
required=True,
help='All the available typesupport implementations')
parser.add_argument(
'--package-version',
required=True,
help='The version of interface package')
args = parser.parse_args(argv)

return generate_rs(args.generator_arguments_file, args.typesupport_impls)
return generate_rs(
args.generator_arguments_file,
args.typesupport_impls,
args.package_version,
)


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions rosidl_generator_rs/cmake/custom_command.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_custom_command(
COMMAND ${PYTHON_EXECUTABLE} ${rosidl_generator_rs_BIN}
--generator-arguments-file "${generator_arguments_file}"
--typesupport-impls "${_typesupport_impls}"
--package-version "${package_version}"
DEPENDS ${target_dependencies}
COMMENT "Generating Rust code for ROS interfaces"
VERBATIM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ foreach(dep ${target_dependencies})
endforeach()

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_rs__arguments.json")
set(package_version "${${PROJECT_NAME}_VERSION}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of using a separate variable for storing the package version, you can reuse the arguments file and write the value of ${${PROJECT_NAME}_VERSION} there.

Copy link
Contributor Author

@wep21 wep21 Jun 5, 2022

Choose a reason for hiding this comment

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

I appended a package version into a generator argument file in 0c78e27.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sample json

{
  "package_name": "action_msgs",
  "output_dir": "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_generator_rs/action_msgs",
  "template_dir": "/home/daisuke/workspace/ros2_rust_ws/install/rosidl_generator_rs/share/rosidl_generator_rs/cmake/../resource",
  "idl_tuples": [
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs:msg/GoalInfo.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs:msg/GoalStatus.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs:msg/GoalStatusArray.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs:srv/CancelGoal.idl"
  ],
  "ros_interface_files": [
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalInfo.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalStatus.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalStatusArray.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/srv/CancelGoal.idl"
  ],
  "ros_interface_dependencies": [
    "builtin_interfaces:/home/daisuke/workspace/ros2_rust_ws/install/builtin_interfaces/share/builtin_interfaces/msg/Duration.idl",
    "builtin_interfaces:/home/daisuke/workspace/ros2_rust_ws/install/builtin_interfaces/share/builtin_interfaces/msg/Time.idl",
    "unique_identifier_msgs:/opt/ros/humble/share/unique_identifier_msgs/msg/UUID.idl"
  ],
  "target_dependencies": [
    "/home/daisuke/workspace/ros2_rust_ws/install/rosidl_generator_rs/share/rosidl_generator_rs/cmake/../../../lib/rosidl_generator_rs/rosidl_generator_rs",
    "/home/daisuke/workspace/ros2_rust_ws/install/rosidl_generator_rs/share/rosidl_generator_rs/cmake/../../../local/lib/python3.10/dist-packages/rosidl_generator_rs/__init__.py",
    "/home/daisuke/workspace/ros2_rust_ws/install/rosidl_generator_rs/share/rosidl_generator_rs/cmake/../resource/msg.rs.em",
    "/home/daisuke/workspace/ros2_rust_ws/install/rosidl_generator_rs/share/rosidl_generator_rs/cmake/../resource/srv.rs.em",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalInfo.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalStatus.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalStatusArray.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/srv/CancelGoal.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalInfo.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalStatus.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/msg/GoalStatusArray.idl",
    "/home/daisuke/workspace/ros2_rust_ws/build/action_msgs/rosidl_adapter/action_msgs/srv/CancelGoal.idl",
    "/home/daisuke/workspace/ros2_rust_ws/install/builtin_interfaces/share/builtin_interfaces/msg/Duration.idl",
    "/home/daisuke/workspace/ros2_rust_ws/install/builtin_interfaces/share/builtin_interfaces/msg/Time.idl",
    "/opt/ros/humble/share/unique_identifier_msgs/msg/UUID.idl"
  ],
  "package_version": "1.2.0"
}

rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
Expand Down
4 changes: 1 addition & 3 deletions rosidl_generator_rs/resource/Cargo.toml.em
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[package]
name = "@(package_name)"
@# The version should ideally be taken from package.xml, see
@# https://github.com/ros2-rust/ros2_rust/issues/116
version = "0.2.0"
version = "@(package_version)"
edition = "2021"

[dependencies]
Expand Down
3 changes: 2 additions & 1 deletion rosidl_generator_rs/rosidl_generator_rs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def convert_lower_case_underscore_to_camel_case(word):
return ''.join(x.capitalize() or '_' for x in word.split('_'))


def generate_rs(generator_arguments_file, typesupport_impls):
def generate_rs(generator_arguments_file, typesupport_impls, package_version):
args = read_generator_arguments(generator_arguments_file)
package_name = args['package_name']

Expand Down Expand Up @@ -157,6 +157,7 @@ def generate_rs(generator_arguments_file, typesupport_impls):
cargo_toml_data = {
'dependency_packages': dependency_packages,
'package_name': args['package_name'],
'package_version': package_version,
}
expand_template(
os.path.join(template_dir, 'Cargo.toml.em'),
Expand Down