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

Feature to show deprecation warning for msg/srv #76

Open
wants to merge 2 commits into
base: kinetic-devel
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions cmake/genmsg-extras.cmake.em
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ macro(_prepend_path ARG_PATH ARG_FILES ARG_OUTPUT_VAR)
endmacro()

macro(add_message_files)
cmake_parse_arguments(ARG "NOINSTALL" "DIRECTORY;BASE_DIR" "FILES" ${ARGN})
cmake_parse_arguments(ARG "NOINSTALL;DEPRECATED" "DIRECTORY;BASE_DIR" "FILES" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "add_message_files() called with unused arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
Expand Down Expand Up @@ -116,6 +116,7 @@ macro(add_message_files)
list(APPEND ${PROJECT_NAME}_MESSAGE_FILES ${FILES_W_PATH})
foreach(file ${FILES_W_PATH})
assert_file_exists(${file} "message file not found")
list(APPEND ${PROJECT_NAME}_MESSAGE_FILE_DEPRECATED_FLAGS ${ARG_DEPRECATED})
endforeach()

# remember path to messages to resolve them as dependencies
Expand All @@ -138,7 +139,7 @@ macro(add_message_files)
endmacro()

macro(add_service_files)
cmake_parse_arguments(ARG "NOINSTALL" "DIRECTORY" "FILES" ${ARGN})
cmake_parse_arguments(ARG "NOINSTALL;DEPRECATED" "DIRECTORY" "FILES" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "add_service_files() called with unused arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
Expand Down Expand Up @@ -173,6 +174,7 @@ macro(add_service_files)
list(APPEND ${PROJECT_NAME}_SERVICE_FILES ${FILES_W_PATH})
foreach(file ${FILES_W_PATH})
assert_file_exists(${file} "service file not found")
list(APPEND ${PROJECT_NAME}_SERVICE_FILE_DEPRECATED_FLAGS ${ARG_DEPRECATED})
endforeach()

if(NOT ARG_NOINSTALL)
Expand Down Expand Up @@ -203,7 +205,9 @@ macro(generate_messages)
endif()

set(ARG_MESSAGES ${${PROJECT_NAME}_MESSAGE_FILES})
set(ARG_MESSAGE_DEPRECATED_FLAGS ${${PROJECT_NAME}_MESSAGE_FILE_DEPRECATED_FLAGS})
set(ARG_SERVICES ${${PROJECT_NAME}_SERVICE_FILES})
set(ARG_SERVICE_DEPRECATED_FLAGS ${${PROJECT_NAME}_SERVICE_FILE_DEPRECATED_FLAGS})
set(ARG_DEPENDENCIES ${ARG_DEPENDENCIES})

if(ARG_LANGS)
Expand Down
4 changes: 4 additions & 0 deletions cmake/pkg-genmsg.cmake.em
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import genmsg.gentools

# split incoming variables
messages = messages_str.split(';') if messages_str != '' else []
message_deprecated_flags = {m: d == 'TRUE' for m, d in zip(messages, message_deprecated_flags_bool.split(';'))}
services = services_str.split(';') if services_str != '' else []
service_deprecated_flags = {s: d == 'TRUE' for s, d in zip(services, service_deprecated_flags_bool.split(';'))}
dependencies = dependencies_str.split(';') if dependencies_str != '' else []
dep_search_paths = dep_include_paths_str.split(';') if dep_include_paths_str != '' else []

Expand Down Expand Up @@ -92,6 +94,7 @@ _generate_msg_@(l[3:])(@pkg_name
"${MSG_I_FLAGS}"
"@(';'.join(msg_deps[m]).replace("\\","/"))"
${CATKIN_DEVEL_PREFIX}/${@(l)_INSTALL_DIR}/@pkg_name
"@message_deprecated_flags[m]"
)
@[end for]@# messages

Expand All @@ -102,6 +105,7 @@ _generate_srv_@(l[3:])(@pkg_name
"${MSG_I_FLAGS}"
"@(';'.join(srv_deps[s]).replace("\\","/"))"
${CATKIN_DEVEL_PREFIX}/${@(l)_INSTALL_DIR}/@pkg_name
"@service_deprecated_flags[s]"
)
@[end for]@# services

Expand Down
2 changes: 2 additions & 0 deletions cmake/pkg-genmsg.context.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# generated from genmsg/cmake/pkg-genmsg.context.in

messages_str = "@ARG_MESSAGES@"
message_deprecated_flags_bool = "@ARG_MESSAGE_DEPRECATED_FLAGS@"
services_str = "@ARG_SERVICES@"
service_deprecated_flags_bool = "@ARG_SERVICE_DEPRECATED_FLAGS@"
pkg_name = "@PROJECT_NAME@"
dependencies_str = "@ARG_DEPENDENCIES@"
langs = "@GEN_LANGS@"
Expand Down
32 changes: 20 additions & 12 deletions src/genmsg/template_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

# generate msg or srv files from a template file
# template_map of the form { 'template_file':'output_file'} output_file can contain @NAME@ which will be replaced by the message/service name
def _generate_from_spec(input_file, output_dir, template_dir, msg_context, spec, template_map, search_path):
def _generate_from_spec(input_file, output_dir, template_dir, msg_context, spec, template_map, search_path, is_deprecated):

md5sum = genmsg.gentools.compute_md5(msg_context, spec)

Expand All @@ -68,7 +68,8 @@ def _generate_from_spec(input_file, output_dir, template_dir, msg_context, spec,
"spec": spec,
"md5sum": md5sum,
"search_path": search_path,
"msg_context": msg_context
"msg_context": msg_context,
"is_deprecated": is_deprecated,
}
if isinstance(spec, genmsg.msgs.MsgSpec):
g['msg_definition'] = msg_definition
Expand All @@ -82,7 +83,7 @@ def _generate_from_spec(input_file, output_dir, template_dir, msg_context, spec,
interpreter.file(open(template_file)) #todo try
interpreter.shutdown()

def _generate_msg_from_file(input_file, output_dir, template_dir, search_path, package_name, msg_template_dict):
def _generate_msg_from_file(input_file, output_dir, template_dir, search_path, package_name, msg_template_dict, is_deprecated):
# Read MsgSpec from .msg file
msg_context = genmsg.msg_loader.MsgContext.create_default()
full_type_name = genmsg.gentools.compute_full_type_name(package_name, os.path.basename(input_file))
Expand All @@ -96,9 +97,10 @@ def _generate_msg_from_file(input_file, output_dir, template_dir, search_path, p
msg_context,
spec,
msg_template_dict,
search_path)
search_path,
is_deprecated)

def _generate_srv_from_file(input_file, output_dir, template_dir, search_path, package_name, srv_template_dict, msg_template_dict):
def _generate_srv_from_file(input_file, output_dir, template_dir, search_path, package_name, srv_template_dict, msg_template_dict, is_deprecated):
# Read MsgSpec from .srv.file
msg_context = genmsg.msg_loader.MsgContext.create_default()
full_type_name = genmsg.gentools.compute_full_type_name(package_name, os.path.basename(input_file))
Expand All @@ -112,26 +114,29 @@ def _generate_srv_from_file(input_file, output_dir, template_dir, search_path, p
msg_context,
spec,
srv_template_dict,
search_path)
search_path,
is_deprecated)
# Generate the language dependent msg file for the srv request
_generate_from_spec(input_file,
output_dir,
template_dir,
msg_context,
spec.request,
msg_template_dict,
search_path)
search_path,
is_deprecated)
# Generate the language dependent msg file for the srv response
_generate_from_spec(input_file,
output_dir,
template_dir,
msg_context,
spec.response,
msg_template_dict,
search_path)
search_path,
is_deprecated)

# uniform interface for genering either srv or msg files
def generate_from_file(input_file, package_name, output_dir, template_dir, include_path, msg_template_dict, srv_template_dict):
def generate_from_file(input_file, package_name, output_dir, template_dir, include_path, msg_template_dict, srv_template_dict, is_deprecated=False):
# Normalize paths
input_file = os.path.abspath(input_file)
output_dir = os.path.abspath(output_dir)
Expand All @@ -151,9 +156,9 @@ def generate_from_file(input_file, package_name, output_dir, template_dir, inclu

# Generate the file(s)
if input_file.endswith(".msg"):
_generate_msg_from_file(input_file, output_dir, template_dir, search_path, package_name, msg_template_dict)
_generate_msg_from_file(input_file, output_dir, template_dir, search_path, package_name, msg_template_dict, is_deprecated)
elif input_file.endswith(".srv"):
_generate_srv_from_file(input_file, output_dir, template_dir, search_path, package_name, srv_template_dict, msg_template_dict)
_generate_srv_from_file(input_file, output_dir, template_dir, search_path, package_name, srv_template_dict, msg_template_dict, is_deprecated)
else:
assert False, "Uknown file extension for %s"%input_file

Expand Down Expand Up @@ -199,6 +204,9 @@ def generate_from_command_line_options(argv, msg_template_dict, srv_template_dic
parser.add_option("-e", dest='emdir',
help="directory containing template files",
default=sys.path[0])
parser.add_option("-d", dest='deprecated',
help="flag of deprecated msg",
action='store_true', default=False)

(options, argv) = parser.parse_args(argv)

Expand All @@ -210,7 +218,7 @@ def generate_from_command_line_options(argv, msg_template_dict, srv_template_dic
generate_module(options.package, options.outdir, options.emdir, module_template_dict)
else:
if len(argv) > 1:
generate_from_file(argv[1], options.package, options.outdir, options.emdir, options.includepath, msg_template_dict, srv_template_dict)
generate_from_file(argv[1], options.package, options.outdir, options.emdir, options.includepath, msg_template_dict, srv_template_dict, options.deprecated)
else:
parser.print_help()
exit(-1)
Expand Down