Skip to content
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

change generators to IDL-based pipeline #14

Merged
merged 20 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import argparse
import os
import sys

from rosidl_cmake import read_generator_arguments
from rosidl_parser import UnknownMessageType
from rosidl_typesupport_fastrtps_c import generate_typesupport_fastrtps_c

Expand All @@ -28,10 +27,8 @@ def main(argv=sys.argv[1:]):
help='The location of the file containing the generator arguments')
args = parser.parse_args(argv)

generator_args = read_generator_arguments(args.generator_arguments_file)

try:
rc = generate_typesupport_fastrtps_c(generator_args)
rc = generate_typesupport_fastrtps_c(args.generator_arguments_file)
except UnknownMessageType as e:
print(str(e), file=sys.stderr)
return 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Open Source Robotics Foundation, Inc.
# Copyright 2016-2018 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.
Expand All @@ -19,64 +19,49 @@ find_package(FastRTPS REQUIRED MODULE)

set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_c/${PROJECT_NAME}")
set(_generated_files "")
foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES})
get_filename_component(_parent_folder "${_idl_file}" DIRECTORY)
foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
get_filename_component(_parent_folder "${_abs_idl_file}" DIRECTORY)
get_filename_component(_parent_folder "${_parent_folder}" NAME)
get_filename_component(_extension "${_idl_file}" EXT)
get_filename_component(_msg_name "${_idl_file}" NAME_WE)
string_camel_case_to_lower_case_underscore("${_msg_name}" _header_name)
if(_extension STREQUAL ".msg")
set(_allowed_parent_folders "msg" "srv" "action")
if(NOT _parent_folder IN_LIST _allowed_parent_folders)
message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}")
endif()
elseif(_extension STREQUAL ".srv")
set(_allowed_parent_folders "srv" "action")
if(NOT _parent_folder IN_LIST _allowed_parent_folders)
message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}")
endif()
else()
message(FATAL_ERROR "Interface file with unknown extension: ${_idl_file}")
endif()
list(APPEND _generated_files "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_c.h")
list(APPEND _generated_files "${_output_path}/${_parent_folder}/dds_fastrtps_c/${_header_name}__type_support_c.cpp")
get_filename_component(_idl_name "${_abs_idl_file}" NAME_WE)
string_camel_case_to_lower_case_underscore("${_idl_name}" _header_name)
list(APPEND _generated_files
"${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_c.h"
"${_output_path}/${_parent_folder}/${_header_name}__type_support_c.cpp")
endforeach()

set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
foreach(_idl_file ${${_pkg_name}_INTERFACE_FILES})
get_filename_component(_extension "${_idl_file}" EXT)
if(_extension STREQUAL ".msg")
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endif()
foreach(_idl_file ${${_pkg_name}_IDL_FILES})
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endforeach()
endforeach()

set(target_dependencies
"${rosidl_typesupport_fastrtps_c_BIN}"
${rosidl_typesupport_fastrtps_c_GENERATOR_FILES}
"${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/idl__rosidl_typesupport_fastrtps_c.h.em"
"${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/idl__type_support_c.cpp.em"
"${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/msg__rosidl_typesupport_fastrtps_c.h.em"
"${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/msg__type_support_c.cpp.em"
"${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__rosidl_typesupport_fastrtps_c.h.em"
"${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__type_support_c.cpp.em"
${rosidl_generate_interfaces_IDL_FILES}
${rosidl_generate_interfaces_ABS_IDL_FILES}
${_dependency_files})
foreach(dep ${target_dependencies})
if(NOT EXISTS "${dep}")
get_property(is_generated SOURCE "${dep}" PROPERTY GENERATED)
if(NOT ${_is_generated})
message(FATAL_ERROR "Target dependency '${dep}' does not exist")
endif()
message(FATAL_ERROR "Target dependency '${dep}' does not exist")
endif()
endforeach()

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_c__arguments.json")
rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
ROS_INTERFACE_FILES "${rosidl_generate_interfaces_IDL_FILES}"
IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// generated from rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em
// with input from @(package_name):@(interface_path)
// generated code does not contain a copyright notice
@
@#######################################################################
@# EmPy template for generating <idl>__rosidl_typesupport_fastrtps_c.h files
@#
@# Context:
@# - package_name (string)
@# - interface_path (Path relative to the directory named after the package)
@# - content (IdlContent, list of elements, e.g. Messages or Services)
@#######################################################################
@
@{
from rosidl_cmake import convert_camel_case_to_lower_case_underscore
include_parts = [package_name] + list(interface_path.parents[0].parts) + \
[convert_camel_case_to_lower_case_underscore(interface_path.stem)]
header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \
'__ROSIDL_TYPESUPPORT_FASTRTPS_C_H_'
}@
#ifndef @(header_guard_variable)
#define @(header_guard_variable)

@{
include_directives = set()
}@
@#######################################################################
@# Handle message
@#######################################################################
@{
from rosidl_parser.definition import Message
}@
@[for message in content.get_elements_of_type(Message)]@

@{
TEMPLATE(
'msg__rosidl_typesupport_fastrtps_c.h.em',
package_name=package_name, interface_path=interface_path, message=message,
include_directives=include_directives)
}@
@[end for]@
@
@#######################################################################
@# Handle service
@#######################################################################
@{
from rosidl_parser.definition import Service
}@
@[for service in content.get_elements_of_type(Service)]@

@{
TEMPLATE(
'srv__rosidl_typesupport_fastrtps_c.h.em',
package_name=package_name, interface_path=interface_path, service=service,
include_directives=include_directives)
}@
@[end for]@
@
@#######################################################################
@# Handle action
@#######################################################################
@{
from rosidl_parser.definition import Action
}@
@[for action in content.get_elements_of_type(Action)]@

@{
TEMPLATE(
'msg__rosidl_typesupport_fastrtps_c.h.em',
package_name=package_name, interface_path=interface_path, message=action.goal,
include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__rosidl_typesupport_fastrtps_c.h.em',
package_name=package_name, interface_path=interface_path, message=action.result,
include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__rosidl_typesupport_fastrtps_c.h.em',
package_name=package_name, interface_path=interface_path, message=action.feedback,
include_directives=include_directives)
}@

@{
TEMPLATE(
'srv__rosidl_typesupport_fastrtps_c.h.em',
package_name=package_name, interface_path=interface_path, service=action.send_goal_service,
include_directives=include_directives)
}@

@{
TEMPLATE(
'srv__rosidl_typesupport_fastrtps_c.h.em',
package_name=package_name, interface_path=interface_path, service=action.get_result_service,
include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__rosidl_typesupport_fastrtps_c.h.em',
package_name=package_name, interface_path=interface_path, message=action.feedback_message,
include_directives=include_directives)
}@
@[end for]@

#endif // @(header_guard_variable)
106 changes: 106 additions & 0 deletions rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// generated from rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em
// with input from @(package_name):@(interface_path)
// generated code does not contain a copyright notice
@
@#######################################################################
@# EmPy template for generating <idl>__type_support.cpp files
@#
@# Context:
@# - package_name (string)
@# - interface_path (Path relative to the directory named after the package)
@# - content (IdlContent, list of elements, e.g. Messages or Services)
@#######################################################################
@
@{
from rosidl_cmake import convert_camel_case_to_lower_case_underscore
include_parts = [package_name] + list(interface_path.parents[0].parts) + \
[convert_camel_case_to_lower_case_underscore(interface_path.stem)]
include_base = '/'.join(include_parts)
}@
#include "@(include_base)__rosidl_typesupport_fastrtps_c.h"

@{
include_directives = set()
}@
@#######################################################################
@# Handle message
@#######################################################################
@{
from rosidl_parser.definition import Message
}@
@[for message in content.get_elements_of_type(Message)]@

@{
TEMPLATE(
'msg__type_support_c.cpp.em',
package_name=package_name, interface_path=interface_path, message=message,
include_directives=include_directives)
}@
@[end for]@
@
@#######################################################################
@# Handle service
@#######################################################################
@{
from rosidl_parser.definition import Service
}@
@[for service in content.get_elements_of_type(Service)]@

@{
TEMPLATE(
'srv__type_support_c.cpp.em',
package_name=package_name, interface_path=interface_path, service=service,
include_directives=include_directives)
}@
@[end for]@
@
@#######################################################################
@# Handle action
@#######################################################################
@{
from rosidl_parser.definition import Action
}@
@[for action in content.get_elements_of_type(Action)]@

@{
TEMPLATE(
'msg__type_support_c.cpp.em',
package_name=package_name, interface_path=interface_path,
message=action.goal, include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__type_support_c.cpp.em',
package_name=package_name, interface_path=interface_path,
message=action.result, include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__type_support_c.cpp.em',
package_name=package_name, interface_path=interface_path,
message=action.feedback, include_directives=include_directives)
}@

@{
TEMPLATE(
'srv__type_support_c.cpp.em',
package_name=package_name, interface_path=interface_path,
service=action.send_goal_service, include_directives=include_directives)
}@

@{
TEMPLATE(
'srv__type_support_c.cpp.em',
package_name=package_name, interface_path=interface_path,
service=action.get_result_service, include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__type_support_c.cpp.em',
package_name=package_name, interface_path=interface_path,
message=action.feedback_message, include_directives=include_directives)
}@
@[end for]@
Loading