Skip to content

Commit d6689e0

Browse files
authored
Hand-code logging_macros.h (ros2#502)
In my opinion, this makes it far more readable for humans, and thus easier to update/maintain in the future. This ends up removing ~500 lines of python code, empy templates, and associated machinery, plus 1500 lines of generated code. This also has the the nice side effect of making it so that rosdoc2 will generate the documentation for all of these macros. Signed-off-by: Chris Lalancette <clalancette@gmail.com>
1 parent ead8874 commit d6689e0

7 files changed

Lines changed: 914 additions & 535 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,8 @@ endif()
1414
include(CheckLibraryExists)
1515

1616
find_package(ament_cmake REQUIRED)
17-
find_package(ament_cmake_python REQUIRED)
1817
find_package(ament_cmake_ros_core REQUIRED)
1918

20-
# By default, without the settings below, find_package(Python3) will attempt
21-
# to find the newest python version it can, and additionally will find the
22-
# most specific version. For instance, on a system that has
23-
# /usr/bin/python3.10, /usr/bin/python3.11, and /usr/bin/python3, it will find
24-
# /usr/bin/python3.11, even if /usr/bin/python3 points to /usr/bin/python3.10.
25-
# The behavior we want is to prefer the "system" installed version unless the
26-
# user specifically tells us othewise through the Python3_EXECUTABLE hint.
27-
# Setting CMP0094 to NEW means that the search will stop after the first
28-
# python version is found. Setting Python3_FIND_UNVERSIONED_NAMES means that
29-
# the search will prefer /usr/bin/python3 over /usr/bin/python3.11. And that
30-
# latter functionality is only available in CMake 3.20 or later, so we need
31-
# at least that version.
32-
cmake_policy(SET CMP0094 NEW)
33-
set(Python3_FIND_UNVERSIONED_NAMES FIRST)
34-
35-
find_package(Python3 REQUIRED COMPONENTS Interpreter)
36-
37-
ament_python_install_package(${PROJECT_NAME})
38-
3919
if(UNIX AND NOT APPLE)
4020
include(cmake/check_c_compiler_uses_glibc.cmake)
4121
check_c_compiler_uses_glibc(USES_GLIBC)
@@ -99,46 +79,11 @@ set_source_files_properties(
9979
${rcutils_sources}
10080
PROPERTIES language "C")
10181

102-
# "watch" template/inputs for changes
103-
configure_file(
104-
"resource/logging_macros.h.em"
105-
"logging_macros.h.em.watch"
106-
COPYONLY)
107-
configure_file(
108-
"rcutils/logging.py"
109-
"logging.py.watch"
110-
COPYONLY)
111-
# generate header with logging macros
112-
set(rcutils_module_path ${CMAKE_CURRENT_SOURCE_DIR})
113-
set(python_code
114-
"import em" # implicitly added ; between python statements due to CMake list
115-
"\
116-
em.invoke( \
117-
[ \
118-
'-o', 'include/rcutils/logging_macros.h', \
119-
'-D', 'rcutils_module_path=\"${rcutils_module_path}\"', \
120-
'${CMAKE_CURRENT_SOURCE_DIR}/resource/logging_macros.h.em' \
121-
] \
122-
)")
123-
string(REPLACE ";" "$<SEMICOLON>" python_code "${python_code}")
124-
add_custom_command(OUTPUT include/rcutils/logging_macros.h
125-
COMMAND ${CMAKE_COMMAND} -E make_directory "include/rcutils"
126-
COMMAND Python3::Interpreter ARGS -c "${python_code}"
127-
DEPENDS
128-
"${CMAKE_CURRENT_BINARY_DIR}/logging_macros.h.em.watch"
129-
"${CMAKE_CURRENT_BINARY_DIR}/logging.py.watch"
130-
COMMENT "Expanding logging_macros.h.em"
131-
VERBATIM
132-
)
133-
list(APPEND rcutils_sources
134-
include/rcutils/logging_macros.h)
135-
13682
add_library(
13783
${PROJECT_NAME}
13884
${rcutils_sources})
13985
target_include_directories(${PROJECT_NAME} PUBLIC
14086
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
141-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
14287
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
14388

14489
# Causes the visibility macros to use dllexport rather than dllimport,
@@ -166,7 +111,6 @@ if(BUILD_TESTING)
166111

167112
find_package(ament_cmake_gmock REQUIRED)
168113
find_package(ament_cmake_gtest REQUIRED)
169-
find_package(ament_cmake_pytest REQUIRED)
170114
find_package(ament_lint_auto REQUIRED)
171115
# cppcheck 1.90 doesn't understand some of the syntax in remove_noexcept.hpp
172116
# Since we already have cppcheck disabled on Linux, just disable it completely
@@ -185,27 +129,6 @@ if(BUILD_TESTING)
185129
ament_export_link_flags("-latomic")
186130
endif()
187131

188-
if(ament_cmake_cppcheck_FOUND)
189-
ament_cppcheck(
190-
TESTNAME "cppcheck_logging_macros"
191-
"${CMAKE_CURRENT_BINARY_DIR}/include/rcutils/logging_macros.h")
192-
endif()
193-
if(ament_cmake_cpplint_FOUND)
194-
ament_cpplint(
195-
TESTNAME "cpplint_logging_macros"
196-
# the generated code might contain longer lines for templated types
197-
MAX_LINE_LENGTH 999
198-
ROOT "${CMAKE_CURRENT_BINARY_DIR}/include"
199-
"${CMAKE_CURRENT_BINARY_DIR}/include/rcutils/logging_macros.h")
200-
endif()
201-
if(ament_cmake_uncrustify_FOUND)
202-
ament_uncrustify(
203-
TESTNAME "uncrustify_logging_macros"
204-
# the generated code might contain longer lines for templated types
205-
MAX_LINE_LENGTH 0
206-
"${CMAKE_CURRENT_BINARY_DIR}/include/rcutils/logging_macros.h")
207-
endif()
208-
209132
find_package(mimick_vendor REQUIRED)
210133

211134
find_package(osrf_testing_tools_cpp REQUIRED)
@@ -629,5 +552,5 @@ ament_export_dependencies(ament_cmake)
629552
ament_package()
630553

631554
install(
632-
DIRECTORY include/ ${CMAKE_CURRENT_BINARY_DIR}/include/
555+
DIRECTORY include/
633556
DESTINATION include/${PROJECT_NAME})

‎Doxyfile‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ PROJECT_NAME = "rcutils"
44
PROJECT_NUMBER = master
55
PROJECT_BRIEF = "C API providing common utilities and data structures."
66

7-
# Use these lines to include the generated logging_macro.h (update install path if needed)
8-
# Otherwise just generate for the local (non-generated header files)
97
INPUT = CONTRIBUTING.md README.md QUALITY_DECLARATION.md ./include
108
EXCLUDE_PATTERNS = */stdatomic_helper/*
119
USE_MDFILE_AS_MAINPAGE = README.md
@@ -20,6 +18,21 @@ GENERATE_LATEX = NO
2018
ENABLE_PREPROCESSING = YES
2119
MACRO_EXPANSION = YES
2220
EXPAND_ONLY_PREDEF = YES
21+
EXCLUDE_SYMBOLS += RCUTILS_LOG_NAMED
22+
EXCLUDE_SYMBOLS += RCUTILS_LOG
23+
EXCLUDE_SYMBOLS += RCUTILS_LOG_ONCE_NAMED
24+
EXCLUDE_SYMBOLS += RCUTILS_LOG_ONCE
25+
EXCLUDE_SYMBOLS += RCUTILS_LOG_CONDITION_NAMED
26+
EXCLUDE_SYMBOLS += RCUTILS_LOG_EXPRESSION_NAMED
27+
EXCLUDE_SYMBOLS += RCUTILS_LOG_EXPRESSION
28+
EXCLUDE_SYMBOLS += RCUTILS_LOG_FUNCTION_NAMED
29+
EXCLUDE_SYMBOLS += RCUTILS_LOG_FUNCTION
30+
EXCLUDE_SYMBOLS += RCUTILS_LOG_SKIPFIRST_NAMED
31+
EXCLUDE_SYMBOLS += RCUTILS_LOG_SKIPFIRST
32+
EXCLUDE_SYMBOLS += RCUTILS_LOG_THROTTLE_NAMED
33+
EXCLUDE_SYMBOLS += RCUTILS_LOG_THROTTLE
34+
EXCLUDE_SYMBOLS += RCUTILS_LOG_SKIPFIRST_THROTTLE_NAMED
35+
EXCLUDE_SYMBOLS += RCUTILS_LOG_SKIPFIRST_THROTTLE
2336
PREDEFINED += RCUTILS_PUBLIC=
2437
PREDEFINED += RCUTILS_PUBLIC_TYPE=
2538
PREDEFINED += RCUTILS_WARN_UNUSED=

0 commit comments

Comments
 (0)