ROS2之assert False, "Failed to find '// Generated: ' line"

举报
zhangrelay 发表于 2021/07/15 04:25:32 2021/07/15
【摘要】 使用colcon build编译turtlesim2,可能会出现如下错误: 需要修改,/opt/ros/dashing/lib/python3.6/site-packages/rosidl_typesupport_opensplice_cpp/__init__.py 使用如下代码进行替换,2019-08-05。 # Copyright 2014-2018 Open ...

使用colcon build编译turtlesim2,可能会出现如下错误:

需要修改,/opt/ros/dashing/lib/python3.6/site-packages/rosidl_typesupport_opensplice_cpp/__init__.py

使用如下代码进行替换,2019-08-05。


  
  1. # Copyright 2014-2018 Open Source Robotics Foundation, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import subprocess
  16. from rosidl_cmake import generate_files
  17. def generate_dds_opensplice_cpp(
  18. pkg_name, dds_interface_files, dds_interface_base_path, deps, output_basepath, idl_pp
  19. ):
  20. include_dirs = [dds_interface_base_path]
  21. for dep in deps:
  22. # only take the first : for separation, as Windows follows with a C:\
  23. dep_parts = dep.split(':', 1)
  24. assert len(dep_parts) == 2, "The dependency '%s' must contain a double colon" % dep
  25. idl_path = dep_parts[1]
  26. idl_base_path = os.path.dirname(
  27. os.path.dirname(os.path.dirname(os.path.normpath(idl_path))))
  28. if idl_base_path not in include_dirs:
  29. include_dirs.append(idl_base_path)
  30. if 'OSPL_TMPL_PATH' in os.environ:
  31. include_dirs.append(os.environ['OSPL_TMPL_PATH'])
  32. for idl_file in dds_interface_files:
  33. assert os.path.exists(idl_file), 'Could not find IDL file: ' + idl_file
  34. # get two level of parent folders for idl file
  35. folder = os.path.dirname(idl_file)
  36. parent_folder = os.path.dirname(folder)
  37. output_path = os.path.join(
  38. output_basepath,
  39. os.path.basename(parent_folder),
  40. os.path.basename(folder))
  41. try:
  42. os.makedirs(output_path)
  43. except FileExistsError:
  44. pass
  45. # idlpp doesn't like long path arguments over 256 chars, get just the filename
  46. filename = os.path.basename(idl_file)
  47. cmd = [idl_pp]
  48. for include_dir in include_dirs:
  49. cmd += ['-I', include_dir]
  50. cmd += [
  51. '-S',
  52. '-l', 'cpp',
  53. '-N',
  54. '-d', output_path,
  55. '-o', 'maintain-include-namespace',
  56. filename
  57. ]
  58. if os.name == 'nt':
  59. cmd[-1:-1] = [
  60. '-P',
  61. 'ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_%s,%s' % (
  62. pkg_name,
  63. '%s/msg/rosidl_typesupport_opensplice_cpp__visibility_control.h' % pkg_name)]
  64. subprocess.check_call(cmd, cwd=folder)
  65. # modify generated code to
  66. # remove path information of the building machine as well as timestamps
  67. msg_name = os.path.splitext(filename)[0]
  68. idl_path = os.path.join(
  69. pkg_name, os.path.basename(parent_folder), filename)
  70. h_filename = os.path.join(output_path, '%s.h' % msg_name)
  71. _modify(h_filename, msg_name, _replace_path_and_timestamp, idl_path=idl_path)
  72. cpp_filename = os.path.join(output_path, '%s.cpp' % msg_name)
  73. _modify(cpp_filename, msg_name, _replace_path_and_timestamp, idl_path=idl_path)
  74. dcps_h_filename = os.path.join(output_path, '%sDcps.h' % msg_name)
  75. _modify(dcps_h_filename, msg_name, _replace_path_and_timestamp, idl_path=idl_path)
  76. dcps_cpp_filename = os.path.join(output_path, '%sDcps.cpp' % msg_name)
  77. _modify(dcps_cpp_filename, msg_name, _replace_path_and_timestamp, idl_path=idl_path)
  78. return 0
  79. def _modify(filename, msg_name, callback, idl_path=None):
  80. with open(filename, 'r') as h:
  81. lines = h.read().split('\n')
  82. modified = callback(lines, msg_name, idl_path=idl_path)
  83. if modified:
  84. with open(filename, 'w') as h:
  85. h.write('\n'.join(lines))
  86. def _replace_path_and_timestamp(lines, msg_name, idl_path):
  87. found_source = False
  88. for i, line in enumerate(lines):
  89. if line.startswith('// Source: '):
  90. assert not found_source, "More than one '// Source: ' line was found"
  91. found_source = True
  92. lines[i] = '// Source: ' + idl_path
  93. continue
  94. if line.startswith('// Generated: '):
  95. assert found_source, "No '// Source: ' line was found before"
  96. lines[i] = '// Generated: timestamp removed to make the build reproducible'
  97. break
  98. return lines
  99. def generate_typesupport_opensplice_cpp(arguments_file):
  100. mapping = {
  101. 'idl__rosidl_typesupport_opensplice_cpp.hpp.em': # noqa
  102. '%s__rosidl_typesupport_opensplice_cpp.hpp',
  103. 'idl__dds_opensplice__type_support.cpp.em': 'dds_opensplice/%s__type_support.cpp',
  104. }
  105. generate_files(arguments_file, mapping)

https://github.com/ros2/rosidl_typesupport_opensplice/blob/master/rosidl_typesupport_opensplice_cpp/rosidl_typesupport_opensplice_cpp/__init__.py

具体原因分析参考:

1. https://github.com/ADLINK-IST/opensplice/issues/92

2. https://github.com/ros2/rosidl_typesupport_opensplice/pull/33

 

文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。

原文链接:zhangrelay.blog.csdn.net/article/details/98500543

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。