Skip to content

Commit

Permalink
Expose C code generation via rosidl generate CLI.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Feb 15, 2021
1 parent f7a9d3a commit a22d31a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions rosidl_generator_c/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<build_export_depend>rosidl_typesupport_interface</build_export_depend>

<exec_depend>rosidl_cli</exec_depend>
<exec_depend>rosidl_parser</exec_depend>

<test_depend>ament_cmake_gtest</test_depend>
Expand Down
62 changes: 62 additions & 0 deletions rosidl_generator_c/rosidl_generator_c/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# 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.

import os

from ament_index_python import get_package_share_directory
from rosidl_cli.command.generate.extensions import GenerateCommandExtension
from rosidl_cli.command.generate.helpers import generate_visibility_control_file
from rosidl_cli.command.generate.helpers import legacy_generator_arguments_file

from rosidl_generator_c import generate_c


class GenerateC(GenerateCommandExtension):

def generate(
self,
package_name,
interface_files,
include_paths,
output_path
):
package_share_path = \
get_package_share_directory(
'rosidl_generator_c'
)
templates_path = os.path.join(
package_share_path, 'resource'
)

# Generate visibility control file
visibility_control_file_template_path = os.path.join(
templates_path, 'rosidl_generator_c__visibility_control.h.in')
visibility_control_file_path = os.path.join(
output_path, 'msg', 'rosidl_generator_c__visibility_control.h')

generate_visibility_control_file(
package_name=package_name,
template_path=visibility_control_file_template_path,
output_path=visibility_control_file_path
)

# Generate code
with legacy_generator_arguments_file(
package_name=package_name,
interface_files=interface_files,
include_paths=include_paths,
templates_path=templates_path,
output_path=output_path
) as path_to_arguments_file:
generate_c(path_to_arguments_file)
3 changes: 3 additions & 0 deletions rosidl_generator_c/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[options.entry_points]
rosidl_cli.command.generate.type_extensions =
c = rosidl_generator_c.cli:GenerateC

0 comments on commit a22d31a

Please sign in to comment.