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 1 commit
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
18 changes: 14 additions & 4 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 @@ -113,7 +113,11 @@ macro(add_message_files)
endif()
_prepend_path(${MESSAGE_DIR} "${ARG_FILES}" FILES_W_PATH)

list(APPEND ${PROJECT_NAME}_MESSAGE_FILES ${FILES_W_PATH})
if(ARG_DEPRECATED)
list(APPEND ${PROJECT_NAME}_DEPRECATED_MESSAGE_FILES ${FILES_W_PATH})
else()
list(APPEND ${PROJECT_NAME}_MESSAGE_FILES ${FILES_W_PATH})
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using two different lists doesn't seem to be a good data structure for this. As a consequence you have to change code which shouldn't need to be touched.

Instead I would suggest to keep ${PROJECT_NAME}_MESSAGE_FILES as it is and have a second map which additionally stores the ones which are deprecated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated.

foreach(file ${FILES_W_PATH})
assert_file_exists(${file} "message file not found")
endforeach()
Expand All @@ -138,7 +142,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 @@ -170,7 +174,11 @@ macro(add_service_files)
endif()
_prepend_path(${SERVICE_DIR} "${ARG_FILES}" FILES_W_PATH)

list(APPEND ${PROJECT_NAME}_SERVICE_FILES ${FILES_W_PATH})
if(ARG_DEPRECATED)
list(APPEND ${PROJECT_NAME}_DEPRECATED_SERVICE_FILES ${FILES_W_PATH})
else()
list(APPEND ${PROJECT_NAME}_SERVICE_FILES ${FILES_W_PATH})
endif()
foreach(file ${FILES_W_PATH})
assert_file_exists(${file} "service file not found")
endforeach()
Expand Down Expand Up @@ -203,7 +211,9 @@ macro(generate_messages)
endif()

set(ARG_MESSAGES ${${PROJECT_NAME}_MESSAGE_FILES})
set(ARG_DEPRECATED_MESSAGES ${${PROJECT_NAME}_DEPRECATED_MESSAGE_FILES})
set(ARG_SERVICES ${${PROJECT_NAME}_SERVICE_FILES})
set(ARG_DEPRECATED_SERVICES ${${PROJECT_NAME}_DEPRECATED_SERVICE_FILES})
set(ARG_DEPENDENCIES ${ARG_DEPENDENCIES})

if(ARG_LANGS)
Expand Down
40 changes: 25 additions & 15 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 []
deprecated_messages = deprecated_messages_str.split(';') if deprecated_messages_str != '' else []
services = services_str.split(';') if services_str != '' else []
deprecated_services = deprecated_services_str.split(';') if deprecated_services_str != '' else []
dependencies = dependencies_str.split(';') if dependencies_str != '' else []
dep_search_paths = dep_include_paths_str.split(';') if dep_include_paths_str != '' else []

Expand All @@ -30,28 +32,34 @@ for val in dep_search_paths:
is_even = True
dep_search_paths = dep_search_paths_dict

if not messages and not services:
if not messages and not deprecated_messages and not services and not deprecated_services:
print('message(WARNING "Invoking generate_messages() without having added any message or service file before.\nYou should either add add_message_files() and/or add_service_files() calls or remove the invocation of generate_messages().")')

msg_deps = {}
msg_dep_types = {}
for m in messages:
try:
_deps = genmsg.deps.find_msg_dependencies_with_type(pkg_name, m, dep_search_paths)
msg_deps[m] = [d[1] for d in _deps]
msg_dep_types[m] = [d[0] for d in _deps]
except genmsg.MsgNotFound as e:
print('message(FATAL_ERROR "Could not find messages which \'%s\' depends on. Did you forget to specify generate_messages(DEPENDENCIES ...)?\n%s")' % (m, str(e).replace('"', '\\"')))
msg_is_deprecated = {}
for is_deprecated, msgs in zip([0, 1], [messages, deprecated_messages]):
for m in msgs:
try:
_deps = genmsg.deps.find_msg_dependencies_with_type(pkg_name, m, dep_search_paths)
msg_deps[m] = [d[1] for d in _deps]
msg_dep_types[m] = [d[0] for d in _deps]
msg_is_deprecated[m] = is_deprecated
except genmsg.MsgNotFound as e:
print('message(FATAL_ERROR "Could not find messages which \'%s\' depends on. Did you forget to specify generate_messages(DEPENDENCIES ...)?\n%s")' % (m, str(e).replace('"', '\\"')))

srv_deps = {}
srv_dep_types = {}
for s in services:
try:
_deps = genmsg.deps.find_srv_dependencies_with_type(pkg_name, s, dep_search_paths)
srv_deps[s] = [d[1] for d in _deps]
srv_dep_types[s] = [d[0] for d in _deps]
except genmsg.MsgNotFound as e:
print('message(FATAL_ERROR "Could not find messages which \'%s\' depends on. Did you forget to specify generate_messages(DEPENDENCIES ...)?\n%s")' % (s, str(e).replace('"', '\\"')))
srv_is_deprecated = {}
for is_deprecated, srvs in zip([0, 1], [services, deprecated_services]):
for s in srvs:
try:
_deps = genmsg.deps.find_srv_dependencies_with_type(pkg_name, s, dep_search_paths)
srv_deps[s] = [d[1] for d in _deps]
srv_dep_types[s] = [d[0] for d in _deps]
srv_is_deprecated[s] = is_deprecated
except genmsg.MsgNotFound as e:
print('message(FATAL_ERROR "Could not find messages which \'%s\' depends on. Did you forget to specify generate_messages(DEPENDENCIES ...)?\n%s")' % (s, str(e).replace('"', '\\"')))

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

Expand All @@ -102,6 +111,7 @@ _generate_srv_@(l[3:])(@pkg_name
"${MSG_I_FLAGS}"
"@(';'.join(srv_deps[s]).replace("\\","/"))"
${CATKIN_DEVEL_PREFIX}/${@(l)_INSTALL_DIR}/@pkg_name
"@srv_is_deprecated[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@"
deprecated_messages_str = "@ARG_DEPRECATED_MESSAGES@"
services_str = "@ARG_SERVICES@"
deprecated_services_str = "@ARG_DEPRECATED_SERVICES@"
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