本文主要是介绍ROS2快速实现ament_lint_auto自动代码审查,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ROS2快速实现ament_lint_auto自动代码审查
文章目录
- 前言
- 正文
- 参考CMakeLists.txt
- 参数说明
- 编译及测试
- 代码格式化不符合要求报警
- 总结
前言
本文用来记录ROS2 ament_cmake
如何快速实现代码自动审查测试。
正文
参考CMakeLists.txt
源代码在gitee代码库,地址如下**Bing Lee / Learn Ros2 Moveit**
cmake_minimum_required(VERSION 3.8)
project(ros2_control_demo_example_5)if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")add_compile_options(-Wall -Wextra -Wpedantic)
endif()# find dependencies
set(THIS_PACKAGE_INCLUDE_DEPENDShardware_interfacepluginlibrclcpprclcpp_lifecycle
)# find dependencies
find_package(ament_cmake REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)## COMPILE
add_library(ros2_control_demo_example_5SHAREDhardware/external_rrbot_force_torque_sensor.cpphardware/rrbot.cpp
)
target_compile_features(ros2_control_demo_example_5 PUBLIC cxx_std_17)
target_include_directories(ros2_control_demo_example_5 PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/hardware/include>
$<INSTALL_INTERFACE:include/ros2_control_demo_example_5>
)
ament_target_dependencies(ros2_control_demo_example_5 PUBLIC${THIS_PACKAGE_INCLUDE_DEPENDS}
)# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_EXAMPLE_5_BUILDING_DLL")# Export hardware plugins
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_example_5.xml)# INSTALL
install(DIRECTORY hardware/include/DESTINATION include/ros2_control_demo_example_5
)
install(DIRECTORY description/launch description/ros2_control description/urdf description/rvizDESTINATION share/ros2_control_demo_example_5
)
install(DIRECTORY bringup/launch bringup/configDESTINATION share/ros2_control_demo_example_5
)
install(TARGETS ros2_control_demo_example_5EXPORT export_ros2_control_demo_example_5ARCHIVE DESTINATION libLIBRARY DESTINATION libRUNTIME DESTINATION bin
)if(BUILD_TESTING)find_package(ament_lint_auto REQUIRED)set(ament_cmake_uncrustify_FOUND TRUE)set(ament_cmake_xmllint_FOUND TRUE)ament_lint_auto_find_test_dependencies()
endif()## EXPORTS
ament_export_targets(export_ros2_control_demo_example_5 HAS_LIBRARY_TARGET)
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
ament_package()
参数说明
# CMakeLists.txtif(BUILD_TESTING)## 配置自动检测find_package(ament_lint_auto REQUIRED)## 忽略uncrustify错误set(ament_cmake_uncrustify_FOUND TRUE)## 忽略xmllint错误set(ament_cmake_xmllint_FOUND TRUE)## 自动查找匹配文件并testament_lint_auto_find_test_dependencies()
endif()
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3"><name>ros2_control_demo_example_5</name><version>0.0.0</version><description>TODO: Package description</description><maintainer email="lilinxin75@gmail.com">Bing Lee</maintainer><url type="website">https://blog.csdn.net/Bing_Lee</url><license>TODO: License declaration</license><buildtool_depend>ament_cmake</buildtool_depend><depend>hardware_interface</depend><depend>pluginlib</depend><depend>rclcpp</depend><depend>rclcpp_lifecycle</depend><exec_depend>controller_manager</exec_depend><exec_depend>forward_command_controller</exec_depend><exec_depend>joint_state_broadcaster</exec_depend><exec_depend>joint_state_publisher_gui</exec_depend><exec_depend>robot_state_publisher</exec_depend><exec_depend>ros2_control_demo_description</exec_depend><exec_depend>ros2_controllers_test_nodes</exec_depend><exec_depend>ros2controlcli</exec_depend><exec_depend>ros2launch</exec_depend><exec_depend>rviz2</exec_depend><exec_depend>xacro</exec_depend><!-- 下边这两个是必须要加上的 --><test_depend>ament_lint_common</test_depend><test_depend>ament_lint_auto</test_depend><export><build_type>ament_cmake</build_type></export>
</package>
编译及测试
# 编译目标程序
colcon build --packages-up-to ros2_control_demo_example_5 # 自动测试目标程序
colcon test --packages-up-to ros2_control_demo_example_5
日志会自动生成在本地log文件中。
代码格式化不符合要求报警
[0.950508] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: 2 files with code style divergence\n'}
[0.950534] (ros2_control_demo_example_5) StdoutLine: {'line': b"7: No code style divergence in file 'hardware/include/ros2_control_demo_example_5/external_rrbot_force_torque_sensor.hpp'\n"}
[0.950559] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: \n'}
[0.950585] (ros2_control_demo_example_5) StdoutLine: {'line': b"7: No code style divergence in file 'hardware/include/ros2_control_demo_example_5/rrbot.hpp'\n"}
[0.950609] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: \n'}
[0.950634] (ros2_control_demo_example_5) StdoutLine: {'line': b"7: No code style divergence in file 'hardware/include/ros2_control_demo_example_5/visibility_control.h'\n"}
[0.950661] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: \n'}
[0.953409] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: -- run_test.py: return code 1\n'}
[0.953489] (ros2_control_demo_example_5) StdoutLine: {'line': b"7: -- run_test.py: verify result file '/home/dev/workspace/learn_ros_moveit/build/ros2_control_demo_example_5/test_results/ros2_control_demo_example_5/uncrustify.xunit.xml'\n"}
# ============================== 错误1 ============================
[0.958686] (ros2_control_demo_example_5) StdoutLine: {'line': b'7/8 Test #7: uncrustify .......................***Failed 0.10 sec\n'}
...
[1.616985] (ros2_control_demo_example_5) StdoutLine: {'line': b"8: File 'package.xml' is invalid:\n"}
[1.617088] (ros2_control_demo_example_5) StdoutLine: {'line': b"8: /home/dev/workspace/learn_ros_moveit/ros2_control_demos/ros2_control_demo_example_5/package.xml:8: element url: Schemas validity error : Element 'url': This element is not expected. Expected is one of ( maintainer, license ).\n"}
[1.617126] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: /home/dev/workspace/learn_ros_moveit/ros2_control_demos/ros2_control_demo_example_5/package.xml fails to validate\n'}
[1.617158] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: \n'}
[1.617187] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: 1 files are invalid\n'}
[1.617216] (ros2_control_demo_example_5) StdoutLine: {'line': b"8: File 'ros2_control_demo_example_5.xml' is valid\n"}
[1.617243] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: \n'}
[1.633089] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: -- run_test.py: return code 1\n'}
[1.633246] (ros2_control_demo_example_5) StdoutLine: {'line': b"8: -- run_test.py: verify result file '/home/dev/workspace/learn_ros_moveit/build/ros2_control_demo_example_5/test_results/ros2_control_demo_example_5/xmllint.xunit.xml'\n"}
# ============================== 错误2 ============================
[1.644917] (ros2_control_demo_example_5) StdoutLine: {'line': b'8/8 Test #8: xmllint ..........................***Failed 0.69 sec\n'}
[1.645272] (ros2_control_demo_example_5) StdoutLine: {'line': b'\n'}
[1.645510] (ros2_control_demo_example_5) StdoutLine: {'line': b'75% tests passed\x1b[0;0m, \x1b[0;31m2 tests failed\x1b[0;0m out of 8\n'}
[1.645693] (ros2_control_demo_example_5) StdoutLine: {'line': b'\n'}
[1.645774] (ros2_control_demo_example_5) StdoutLine: {'line': b'Label Time Summary:\n'}
[1.645848] (ros2_control_demo_example_5) StdoutLine: {'line': b'copyright = 0.18 sec*proc (1 test)\n'}
[1.645916] (ros2_control_demo_example_5) StdoutLine: {'line': b'cppcheck = 0.09 sec*proc (1 test)\n'}
[1.645985] (ros2_control_demo_example_5) StdoutLine: {'line': b'cpplint = 0.17 sec*proc (1 test)\n'}
[1.646055] (ros2_control_demo_example_5) StdoutLine: {'line': b'flake8 = 0.15 sec*proc (1 test)\n'}
[1.646124] (ros2_control_demo_example_5) StdoutLine: {'line': b'lint_cmake = 0.08 sec*proc (1 test)\n'}
[1.646192] (ros2_control_demo_example_5) StdoutLine: {'line': b'linter = 1.56 sec*proc (8 tests)\n'}
[1.646271] (ros2_control_demo_example_5) StdoutLine: {'line': b'pep257 = 0.11 sec*proc (1 test)\n'}
[1.646341] (ros2_control_demo_example_5) StdoutLine: {'line': b'uncrustify = 0.10 sec*proc (1 test)\n'}
[1.646411] (ros2_control_demo_example_5) StdoutLine: {'line': b'xmllint = 0.69 sec*proc (1 test)\n'}
[1.646479] (ros2_control_demo_example_5) StdoutLine: {'line': b'\n'}
[1.646550] (ros2_control_demo_example_5) StdoutLine: {'line': b'Total Test time (real) = 1.56 sec\n'}
[1.646622] (ros2_control_demo_example_5) StdoutLine: {'line': b'\n'}[1.646690] (ros2_control_demo_example_5) StdoutLine: {'line': b'The following tests FAILED:\n'}
# ============================== 错误1 ============================
[1.646761] (ros2_control_demo_example_5) StdoutLine: {'line': b'\t\x1b[0;31m 7 - uncrustify (Failed)\x1b[0;0m\n'}
# ============================== 错误2 ============================
[1.646836] (ros2_control_demo_example_5) StdoutLine: {'line': b'\t\x1b[0;31m 8 - xmllint (Failed)\x1b[0;0m\n'}
[1.673562] (ros2_control_demo_example_5) StderrLine: {'line': b'Errors while running CTest\n'}
[1.674189] (ros2_control_demo_example_5) StderrLine: {'line': b'Output from these tests are in: /home/dev/workspace/learn_ros_moveit/build/ros2_control_demo_example_5/Testing/Temporary/LastTest.log\n'}
[1.674550] (ros2_control_demo_example_5) StderrLine: {'line': b'Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.\n'}
[1.679593] (ros2_control_demo_example_5) CommandEnded: {'returncode': 8}
[1.682088] (ros2_control_demo_example_5) TestFailure: {'identifier': 'ros2_control_demo_example_5'}
[1.682270] (ros2_control_demo_example_5) JobEnded: {'identifier': 'ros2_control_demo_example_5', 'rc': 0}
[1.683575] (-) EventReactorShutdown: {}
总结
本文提供一种在ROS2 程序ament_cmake
CI编译时自动自动审查测试的方法,也可以单独设置ament_cmake_pycodestyle ament_cmake_cppcheck ament_cmake_clang_format ament_cmake_flake8 ...
等1,其中还有有一些规范设置等参数,感兴趣的朋友可以自行研究。
Github/ament/ament_lint_auto ↩︎
这篇关于ROS2快速实现ament_lint_auto自动代码审查的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!