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

Separate writing arguments files from the code generation and build #148

Draft
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Draft
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
4 changes: 0 additions & 4 deletions rosidl_typesupport_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ ament_package(
CONFIG_EXTRAS "rosidl_typesupport_c-extras.cmake.in"
)

install(
PROGRAMS bin/rosidl_typesupport_c
DESTINATION lib/rosidl_typesupport_c
)
install(
DIRECTORY cmake resource
DESTINATION share/${PROJECT_NAME}
Expand Down
28 changes: 0 additions & 28 deletions rosidl_typesupport_c/bin/rosidl_typesupport_c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2018 Open Source Robotics Foundation, Inc.
# Copyright 2016-2023 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 Down Expand Up @@ -34,57 +34,6 @@ foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
)
endforeach()

set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
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_c_BIN}"
${rosidl_typesupport_c_GENERATOR_FILES}
"${rosidl_typesupport_c_TEMPLATE_DIR}/action__type_support.c.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/idl__type_support.cpp.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/msg__type_support.cpp.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/srv__type_support.cpp.em"
${rosidl_generate_interfaces_ABS_IDL_FILES}
${_dependency_files})
foreach(dep ${target_dependencies})
if(NOT EXISTS "${dep}")
message(FATAL_ERROR "Target dependency '${dep}' does not exist")
endif()
endforeach()

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_c__arguments.json")
rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "${rosidl_typesupport_c_TEMPLATE_DIR}"
TARGET_DEPENDENCIES ${target_dependencies}
)

find_package(Python3 REQUIRED COMPONENTS Interpreter)

get_used_typesupports(typesupports "rosidl_typesupport_c")
add_custom_command(
OUTPUT ${_generated_sources}
COMMAND Python3::Interpreter
ARGS ${rosidl_typesupport_c_BIN}
--generator-arguments-file "${generator_arguments_file}"
--typesupports ${typesupports}
DEPENDS ${target_dependencies}
COMMENT "Generating C type support dispatch for ROS interfaces"
VERBATIM
)

set(_target_suffix "__rosidl_typesupport_c")

add_library(${rosidl_generate_interfaces_TARGET}${_target_suffix} ${rosidl_typesupport_c_LIBRARY_TYPE} ${_generated_sources})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2023 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.

set(_output_path
"${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_c/${PROJECT_NAME}")

set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
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_c_GENERATOR_FILES}
"${rosidl_typesupport_c_TEMPLATE_DIR}/action__type_support.c.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/idl__type_support.cpp.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/msg__type_support.cpp.em"
"${rosidl_typesupport_c_TEMPLATE_DIR}/srv__type_support.cpp.em"
${rosidl_generate_interfaces_ABS_IDL_FILES}
${_dependency_files})
foreach(dep ${target_dependencies})
if(NOT EXISTS "${dep}")
message(FATAL_ERROR "Target dependency '${dep}' does not exist")
endif()
endforeach()

get_used_typesupports(typesupports "rosidl_typesupport_c")

set(additional_context_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_c__additional_context.json")
rosidl_write_additional_context(
"${additional_context_file}"
TYPE_SUPPORTS ${typesupports}
)

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_c__arguments.json")
rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "${rosidl_typesupport_c_TEMPLATE_DIR}"
TARGET_DEPENDENCIES ${target_dependencies}
GENERATOR_FILES "${rosidl_typesupport_c_GENERATOR_FILES}"
ADDITIONAL_CONTEXT_FILE "${additional_context_file}"
)

list(APPEND rosidl_generator_arguments_files ${generator_arguments_file})
11 changes: 6 additions & 5 deletions rosidl_typesupport_c/rosidl_typesupport_c-extras.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ foreach(_typesupport ${_typesupports})
endforeach()

find_package(ament_cmake_core QUIET REQUIRED)

ament_register_extension(
"rosidl_write_generator_arguments_extensions"
"rosidl_typesupport_c"
"rosidl_typesupport_c_write_arguments.cmake")

ament_register_extension(
"rosidl_generate_idl_interfaces"
"rosidl_typesupport_c"
"rosidl_typesupport_c_generate_interfaces.cmake")

set(rosidl_typesupport_c_BIN
"${rosidl_typesupport_c_DIR}/../../../lib/rosidl_typesupport_c/rosidl_typesupport_c")
normalize_path(rosidl_typesupport_c_BIN
"${rosidl_typesupport_c_BIN}")

set(rosidl_typesupport_c_GENERATOR_FILES
"${rosidl_typesupport_c_DIR}/../../../@PYTHON_INSTALL_DIR@/rosidl_typesupport_c/__init__.py")
normalize_path(rosidl_typesupport_c_GENERATOR_FILES
Expand Down
12 changes: 8 additions & 4 deletions rosidl_typesupport_c/rosidl_typesupport_c/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2018 Open Source Robotics Foundation, Inc.
# Copyright 2016-2023 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 @@ -15,16 +15,20 @@
from rosidl_pycommon import generate_files


def get_template_mapping():
return {
'idl__type_support.cpp.em': '%s__type_support.cpp',
}


def generate_c(generator_arguments_file, type_supports):
"""
Generate the C type support to handle ROS messages.

:param generator_arguments_file: Path location of the file containing the generator arguments
:param type_support: List of type supports to be used
"""
mapping = {
'idl__type_support.cpp.em': '%s__type_support.cpp',
}
mapping = get_template_mapping()
return generate_files(
generator_arguments_file, mapping,
additional_context={'type_supports': type_supports})
4 changes: 0 additions & 4 deletions rosidl_typesupport_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ ament_package(
CONFIG_EXTRAS "rosidl_typesupport_cpp-extras.cmake.in"
)

install(
PROGRAMS bin/rosidl_typesupport_cpp
DESTINATION lib/rosidl_typesupport_cpp
)
install(
DIRECTORY cmake resource
DESTINATION share/${PROJECT_NAME}
Expand Down
28 changes: 0 additions & 28 deletions rosidl_typesupport_cpp/bin/rosidl_typesupport_cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2018 Open Source Robotics Foundation, Inc.
# Copyright 2016-2023 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 Down Expand Up @@ -31,57 +31,6 @@ foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
)
endforeach()

set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
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_cpp_BIN}"
${rosidl_typesupport_cpp_GENERATOR_FILES}
"${rosidl_typesupport_cpp_TEMPLATE_DIR}/action__type_support.cpp.em"
"${rosidl_typesupport_cpp_TEMPLATE_DIR}/idl__type_support.cpp.em"
"${rosidl_typesupport_cpp_TEMPLATE_DIR}/msg__type_support.cpp.em"
"${rosidl_typesupport_cpp_TEMPLATE_DIR}/srv__type_support.cpp.em"
${rosidl_generate_interfaces_ABS_IDL_FILES}
${_dependency_files})
foreach(dep ${target_dependencies})
if(NOT EXISTS "${dep}")
message(FATAL_ERROR "Target dependency '${dep}' does not exist")
endif()
endforeach()

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_cpp__arguments.json")
rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "${rosidl_typesupport_cpp_TEMPLATE_DIR}"
TARGET_DEPENDENCIES ${target_dependencies}
)

find_package(Python3 REQUIRED COMPONENTS Interpreter)

get_used_typesupports(typesupports "rosidl_typesupport_cpp")
add_custom_command(
OUTPUT ${_generated_sources}
COMMAND Python3::Interpreter
ARGS ${rosidl_typesupport_cpp_BIN}
--generator-arguments-file "${generator_arguments_file}"
--typesupports ${typesupports}
DEPENDS ${target_dependencies}
COMMENT "Generating C++ type support dispatch for ROS interfaces"
VERBATIM
)

set(_target_suffix "__rosidl_typesupport_cpp")

add_library(${rosidl_generate_interfaces_TARGET}${_target_suffix} ${rosidl_typesupport_cpp_LIBRARY_TYPE} ${_generated_sources})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2023 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.

set(_output_path
"${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_cpp/${PROJECT_NAME}")

set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
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_cpp_GENERATOR_FILES}
"${rosidl_typesupport_cpp_TEMPLATE_DIR}/action__type_support.cpp.em"
"${rosidl_typesupport_cpp_TEMPLATE_DIR}/idl__type_support.cpp.em"
"${rosidl_typesupport_cpp_TEMPLATE_DIR}/msg__type_support.cpp.em"
"${rosidl_typesupport_cpp_TEMPLATE_DIR}/srv__type_support.cpp.em"
${rosidl_generate_interfaces_ABS_IDL_FILES}
${_dependency_files})
foreach(dep ${target_dependencies})
if(NOT EXISTS "${dep}")
message(FATAL_ERROR "Target dependency '${dep}' does not exist")
endif()
endforeach()

set(additional_context_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_cpp__additional_context.json")
rosidl_write_additional_context(
"${additional_context_file}"
TYPE_SUPPORTS ${typesupports}
)

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_cpp__arguments.json")
rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "${rosidl_typesupport_cpp_TEMPLATE_DIR}"
TARGET_DEPENDENCIES ${target_dependencies}
GENERATOR_FILES "${rosidl_typesupport_cpp_GENERATOR_FILES}"
ADDITIONAL_CONTEXT_FILE ${additional_context_file}
)

list(APPEND rosidl_generator_arguments_files ${generator_arguments_file})
Loading