-
Notifications
You must be signed in to change notification settings - Fork 337
Statically allocate string concatenations using FMT formatting #2205
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mini-1235 can you check other parts of code where these kinds of strings are built and can you replace them with fmt ?
Thank you
@saikishor Do I need to do this for the tests as well? |
I don't think it's needed for the tests! |
This pull request is in conflict. Could you fix it @mini-1235? |
e051b0b
to
8332c26
Compare
I can see that the CI is reporting |
For the CI related issues this package may be a good resource to look into: https://github.com/facontidavide/ros2_logging_fmt Probably there are some hints to find here leading to a solution. |
Seems like there is a linking issue. It is missing as a dependency or in the CMakeLists.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great work, I have some comments about dependencies.
I never used fmt, so I might be wrong: Which strings should be allocated with fmt? Every string where any variable is included with format specifiers, or +operator of std::string? I made a quick search and still found some occurrences without fmt
controller_manger.cpp: L117, L130, L137, L591, L598, L607, L1357, L1378, L1380, L1424, L1430, L1520, L1574, L1664, L1677, L1690, etc
I suggest searching once again for %s
, %d
, %f,
%lu
, throw
?
hardware_interface/package.xml
Outdated
|
||
<build_depend>rcutils</build_depend> | ||
<exec_depend>rcutils</exec_depend> | ||
|
||
<test_depend>ament_cmake_gmock</test_depend> | ||
<test_depend>ros2_control_test_assets</test_depend> | ||
<test_depend>fmt</test_depend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<test_depend>fmt</test_depend> |
this is not necessary if there is already a depend
for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
<test_depend>ament_cmake_gmock</test_depend> | ||
<test_depend>fmt</test_depend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<test_depend>fmt</test_depend> |
this is not necessary if there is already a depend
for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -15,10 +15,10 @@ | |||
#ifndef HARDWARE_INTERFACE__COMPONENT_PARSER_HPP_ | |||
#define HARDWARE_INTERFACE__COMPONENT_PARSER_HPP_ | |||
|
|||
#include <fmt/compile.h> | |||
#include <string> | |||
#include <unordered_map> | |||
#include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please re-add this new-line (google code style)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean two new lines after #define
? Or a new line after `<fmt/compile.h>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reformat the header files in the latest commit, can you please check if that is what you mean @christophfroehlich ?
joint_limits/package.xml
Outdated
|
||
<test_depend>ament_cmake_gmock</test_depend> | ||
<test_depend>generate_parameter_library</test_depend> | ||
<test_depend>launch_ros</test_depend> | ||
<test_depend>launch_testing_ament_cmake</test_depend> | ||
<test_depend>fmt</test_depend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<test_depend>fmt</test_depend> |
this is not necessary if there is already a depend
for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
transmission_interface/package.xml
Outdated
|
||
<test_depend>ament_cmake_gmock</test_depend> | ||
<test_depend>ros2_control_test_assets</test_depend> | ||
<test_depend>fmt</test_depend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<test_depend>fmt</test_depend> |
this is not necessary if there is already a depend
for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
fmt::format( | ||
FMT_COMPILE("Failed to set the initial state of the component : %s to %s"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is %s valid fmt syntax? Here they only use it with fmt::fprintf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I don't think we need to add target_link_libraries of fmt::fmt every where, in most cases adding to THIS_PACKAGE_INCLUDE_DEPENDS
alone should do, as it is being used in the ament_target_dependencies
I also observed the missing include of fmt in the controller_interface
and controller_manager
along with the dependency in package.xml
and changes in CMakeLists.txt
-> We need this as we want to be with "include-what-you-use" principle
hardware_interface/CMakeLists.txt
Outdated
@@ -40,6 +41,7 @@ target_include_directories(hardware_interface PUBLIC | |||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | |||
$<INSTALL_INTERFACE:include/hardware_interface> | |||
) | |||
target_link_libraries(hardware_interface PRIVATE fmt::fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(hardware_interface PRIVATE fmt::fmt) |
ament_target_dependencies should alone be enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mini-1235 next time please commit the changes directly from the suggestions above. you can do so by clicking commit button in the UI. If you go to files tab, you can groups changes together and commit it in a single commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mini-1235 next time please commit the changes directly from the suggestions above. you can do so by clicking commit button in the UI. If you go to files tab, you can groups changes together and commit it in a single commit
Ok!
hardware_interface/CMakeLists.txt
Outdated
target_link_libraries(test_joint_handle hardware_interface fmt::fmt) | ||
ament_target_dependencies(test_joint_handle rcpputils fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(test_joint_handle hardware_interface fmt::fmt) | |
ament_target_dependencies(test_joint_handle rcpputils fmt) | |
target_link_libraries(test_joint_handle hardware_interface) | |
ament_target_dependencies(test_joint_handle rcpputils) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
hardware_interface/CMakeLists.txt
Outdated
target_link_libraries(test_component_interfaces hardware_interface fmt::fmt) | ||
ament_target_dependencies(test_component_interfaces ros2_control_test_assets fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(test_component_interfaces hardware_interface fmt::fmt) | |
ament_target_dependencies(test_component_interfaces ros2_control_test_assets fmt) | |
target_link_libraries(test_component_interfaces hardware_interface) | |
ament_target_dependencies(test_component_interfaces ros2_control_test_assets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
hardware_interface/CMakeLists.txt
Outdated
target_link_libraries(test_component_interfaces_custom_export hardware_interface fmt::fmt) | ||
ament_target_dependencies(test_component_interfaces_custom_export ros2_control_test_assets fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(test_component_interfaces_custom_export hardware_interface fmt::fmt) | |
ament_target_dependencies(test_component_interfaces_custom_export ros2_control_test_assets fmt) | |
target_link_libraries(test_component_interfaces_custom_export hardware_interface) | |
ament_target_dependencies(test_component_interfaces_custom_export ros2_control_test_assets) |
I don't think it is needed in these files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
ament_target_dependencies(test_components hardware_interface pluginlib ros2_control_test_assets) | ||
target_link_libraries(test_components fmt::fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ament_target_dependencies(test_components hardware_interface pluginlib ros2_control_test_assets) | |
target_link_libraries(test_components fmt::fmt) | |
ament_target_dependencies(test_components hardware_interface pluginlib ros2_control_test_assets fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
target_link_libraries(test_resource_manager fmt::fmt) | ||
ament_target_dependencies(test_resource_manager hardware_interface ros2_control_test_assets fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(test_resource_manager fmt::fmt) | |
ament_target_dependencies(test_resource_manager hardware_interface ros2_control_test_assets fmt) | |
ament_target_dependencies(test_resource_manager hardware_interface ros2_control_test_assets fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
joint_limits/CMakeLists.txt
Outdated
@@ -73,13 +74,14 @@ if(BUILD_TESTING) | |||
find_package(rclcpp REQUIRED) | |||
|
|||
ament_add_gmock(joint_limits_rosparam_test test/joint_limits_rosparam_test.cpp) | |||
target_link_libraries(joint_limits_rosparam_test joint_limits) | |||
target_link_libraries(joint_limits_rosparam_test joint_limits fmt::fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(joint_limits_rosparam_test joint_limits fmt::fmt) | |
target_link_libraries(joint_limits_rosparam_test joint_limits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, but looks like it needs a link in joint_limits
, so I have addedtarget_link_libraries(joint_limits INTERFACE fmt::fmt)
, otherwise it will report
--- stderr: joint_limits
/usr/bin/ld: CMakeFiles/joint_limits_rosparam_test.dir/test/joint_limits_rosparam_test.cpp.o: undefined reference to symbol '_ZN3fmt2v96detail11assert_failEPKciS3_'
/usr/bin/ld: /lib/x86_64-linux-gnu/libfmt.so.9: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/joint_limits_rosparam_test.dir/build.make:222: joint_limits_rosparam_test] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:270: CMakeFiles/joint_limits_rosparam_test.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
joint_limits/CMakeLists.txt
Outdated
|
||
ament_add_gmock(joint_limits_urdf_test test/joint_limits_urdf_test.cpp) | ||
target_link_libraries(joint_limits_urdf_test joint_limits) | ||
target_link_libraries(joint_limits_urdf_test joint_limits fmt::fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(joint_limits_urdf_test joint_limits fmt::fmt) | |
target_link_libraries(joint_limits_urdf_test joint_limits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
joint_limits/CMakeLists.txt
Outdated
PRIVATE PARAMETERS_FILE_PATH="${CMAKE_CURRENT_LIST_DIR}/test/" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRIVATE PARAMETERS_FILE_PATH="${CMAKE_CURRENT_LIST_DIR}/test/" | |
) | |
PRIVATE PARAMETERS_FILE_PATH="${CMAKE_CURRENT_LIST_DIR}/test/") |
Any particular reason for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I have reverted it
@@ -27,6 +28,7 @@ target_include_directories(transmission_interface PUBLIC | |||
$<INSTALL_INTERFACE:include/transmission_interface> | |||
) | |||
ament_target_dependencies(transmission_interface PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS}) | |||
target_link_libraries(transmission_interface PUBLIC fmt::fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(transmission_interface PUBLIC fmt::fmt) |
As you have added it to the THIS_PACKAGE_INCLUDE_DEPENDS
, it should be automatic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
I think allocating strings are only required when concatenating? Those only with format specifiers like RCLCPP_DEBUG(
rclcpp::get_logger("ControllerManager::utils"),
"Required interface '%s' with prefix '%s' is not a chain interface.", interface_name.c_str(),
interface_prefix.c_str()); are not required, right? @saikishor |
Yes, it is not required for such cases |
This pull request is in conflict. Could you fix it @mini-1235? |
Sorry for the delayed reply here, I was building a new image on my local machine so that I can reproduce the errors reported by the CI :)
My searching pattern was + " / " +, I think that is enough to find all concatenation cases(?)
Added. |
@mini-1235 can you rebase your changes on top of current master? |
Signed-off-by: mini-1235 <[email protected]>
Signed-off-by: mini-1235 <[email protected]>
Signed-off-by: mini-1235 <[email protected]>
Signed-off-by: mini-1235 <[email protected]>
Signed-off-by: mini-1235 <[email protected]>
b131097
to
2f7cb00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mini-1235 most of the files that have the fmt changes are missing the include of the header. Remember the "include_what_you_use" principle.
Also please fix the pre-commit
@@ -62,12 +62,12 @@ ChainableControllerInterface::export_state_interfaces() | |||
{ | |||
if (interface.get_prefix_name().find(get_node()->get_name()) != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mini-1235 the include of the fmt is missing in this file
@@ -27,6 +28,7 @@ target_include_directories(joint_limits INTERFACE | |||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | |||
$<INSTALL_INTERFACE:include/joint_limits> | |||
) | |||
target_link_libraries(joint_limits INTERFACE fmt::fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(joint_limits INTERFACE fmt::fmt) |
Isn't the ament_target_dependencies doing the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I commented out this line, I can see that the compiler reports a linking error:
--- stderr: joint_limits
/usr/bin/ld: CMakeFiles/joint_limits_rosparam_test.dir/test/joint_limits_rosparam_test.cpp.o: undefined reference to symbol '_ZN3fmt2v96detail11assert_failEPKciS3_'
/usr/bin/ld: /lib/x86_64-linux-gnu/libfmt.so.9: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/joint_limits_rosparam_test.dir/build.make:222: joint_limits_rosparam_test] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:270: CMakeFiles/joint_limits_rosparam_test.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
I will discover why
Co-authored-by: Sai Kishor Kothakota <[email protected]>
Signed-off-by: mini-1235 <[email protected]>
closes #1906