Skip to content

Commit

Permalink
Feature to show deprecation warning for msg/srv
Browse files Browse the repository at this point in the history
Depends on ros/genmsg#76
  • Loading branch information
wkentaro committed May 14, 2018
1 parent b41ee30 commit a1d3905
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmake/gencpp-extras.cmake.em
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(GENCPP_TEMPLATE_DIR "${gencpp_DIR}/..")

# Generate .msg->.h for cpp
# The generated .h files should be added ALL_GEN_OUTPUT_FILES_cpp
macro(_generate_msg_cpp ARG_PKG ARG_MSG ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_DIR)
macro(_generate_msg_cpp ARG_PKG ARG_MSG ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_DIR ARG_IS_DEPRECATED)
file(MAKE_DIRECTORY ${ARG_GEN_OUTPUT_DIR})

#Create input and output filenames
Expand All @@ -35,6 +35,10 @@ macro(_generate_msg_cpp ARG_PKG ARG_MSG ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_D
set(MSG_PLUGIN)
endif()

if(${ARG_IS_DEPRECATED})
set(COMMAND_DEPRECATED_FLAG "-d")
endif()

assert(CATKIN_ENV)
add_custom_command(OUTPUT ${GEN_OUTPUT_FILE}
DEPENDS ${GENCPP_BIN} ${ARG_MSG} ${ARG_MSG_DEPS} ${MSG_PLUGIN} "${GENCPP_TEMPLATE_DIR}/msg.h.template" ${ARGN}
Expand All @@ -43,6 +47,7 @@ macro(_generate_msg_cpp ARG_PKG ARG_MSG ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_D
-p ${ARG_PKG}
-o ${ARG_GEN_OUTPUT_DIR}
-e ${GENCPP_TEMPLATE_DIR}
${COMMAND_DEPRECATED_FLAG}
COMMENT "Generating C++ code from ${ARG_PKG}/${MSG_NAME}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
Expand All @@ -53,8 +58,8 @@ macro(_generate_msg_cpp ARG_PKG ARG_MSG ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_D
endmacro()

#gencpp uses the same program to generate srv and msg files, so call the same macro
macro(_generate_srv_cpp ARG_PKG ARG_SRV ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_DIR)
_generate_msg_cpp(${ARG_PKG} ${ARG_SRV} "${ARG_IFLAGS}" "${ARG_MSG_DEPS}" ${ARG_GEN_OUTPUT_DIR} "${GENCPP_TEMPLATE_DIR}/srv.h.template")
macro(_generate_srv_cpp ARG_PKG ARG_SRV ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_DIR ARG_IS_DEPRECATED)
_generate_msg_cpp(${ARG_PKG} ${ARG_SRV} "${ARG_IFLAGS}" "${ARG_MSG_DEPS}" ${ARG_GEN_OUTPUT_DIR} ${ARG_IS_DEPRECATED} "${GENCPP_TEMPLATE_DIR}/srv.h.template")
endmacro()

macro(_generate_module_cpp)
Expand Down
8 changes: 8 additions & 0 deletions scripts/msg.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@# - file_name_in (String) Source file
@# - spec (msggen.MsgSpec) Parsed specification of the .msg file
@# - md5sum (String) MD5Sum of the .msg specification
@# - is_deprecated (Boolean) Flag for deprecated message
@###############################################
// Generated by gencpp from file @(spec.package)/@(spec.short_name).msg
// DO NOT EDIT!
Expand Down Expand Up @@ -64,6 +65,13 @@ for field in spec.parsed_fields():
#include <@(spec.package)/plugin/@(spec.short_name).h>
@[end if]@

@##############################
@# Deprecation Warning
@##############################
@[if is_deprecated]@
#warning "ROS message @(spec.package)/@(spec.short_name).msg is deprecated. Please stop using it."
@[end if]@

namespace @(spec.package)
{
template <class ContainerAllocator>
Expand Down
8 changes: 8 additions & 0 deletions scripts/srv.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@# - file_name_in (String) Source .srv file
@# - spec (msggen.SrvSpec) Parsed specification of the .srv file
@# - md5sum (String) MD5Sum of the .srv specification
@# - is_deprecated (Boolean) Flag for deprecated service
@###############################################
// Generated by gencpp from file @(spec.package)/@(spec.short_name).msg
// DO NOT EDIT!
Expand All @@ -33,6 +34,13 @@ cpp_full_name = cpp_namespace+cpp_class
#include <@(spec.package)/@(spec.short_name)Request.h>
#include <@(spec.package)/@(spec.short_name)Response.h>

@##############################
@# Deprecation Warning
@##############################
@[if is_deprecated]@
#warning "ROS service @(spec.package)/@(spec.short_name).srv is deprecated. Please stop using it."
@[end if]@

@###############################################
@# Service Struct
@###############################################
Expand Down

0 comments on commit a1d3905

Please sign in to comment.