-
Notifications
You must be signed in to change notification settings - Fork 146
Make sure that the headers are self-contained; fixes #528 #531
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
Conversation
Summary of ChangesHello @liuzicheng1987, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness and maintainability of the Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request aims to make headers self-contained by adding missing includes. The changes across the header files look correct. However, the CMake logic to verify self-contained headers is flawed. I've provided a suggestion to fix it. The main issue is that the test targets for each header are not configured with the necessary include paths and dependencies, which my suggestion addresses by linking them against the main reflectcpp library.
| if(REFLECTCPP_CHECK_HEADERS) | ||
| file(GLOB_RECURSE PROJECT_HEADERS "include/*.hpp") | ||
|
|
||
| set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/self_contained_tests") | ||
| file(MAKE_DIRECTORY "${TEST_DIR}") | ||
|
|
||
| foreach(HEADER_FILE ${PROJECT_HEADERS}) | ||
| string(MAKE_C_IDENTIFIER ${HEADER_FILE} HEADER_NAME) | ||
| set(TEST_SOURCE_FILE "${TEST_DIR}/test_${HEADER_NAME}.cpp") | ||
|
|
||
| file(GENERATE | ||
| OUTPUT ${TEST_SOURCE_FILE} | ||
| CONTENT "#include \"${HEADER_FILE}\"\n" | ||
| ) | ||
|
|
||
| add_library(check_header_${HEADER_NAME} "${TEST_SOURCE_FILE}") | ||
|
|
||
| target_include_directories(check_header_${HEADER_NAME} PRIVATE | ||
| ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ${ADDITIONAL_INCLUDE_DIRS} | ||
| ) | ||
|
|
||
| add_custom_target(check_${HEADER_NAME} ALL DEPENDS check_header_${HEADER_NAME}) | ||
| endforeach() | ||
| endif() |
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.
The current implementation for checking if headers are self-contained is not correctly configured. The check_header_* targets are missing the necessary include directories and link dependencies from third-party libraries (like avro, bson, etc.). This will cause the compilation of the test sources to fail.
A better approach is to create executables for each header check and link them against the reflectcpp target. This ensures they inherit all the necessary public/interface dependencies and include paths. Using an executable also verifies that linking succeeds, which is a more thorough check than just compiling a static library.
I've also added a main function to the generated source file to make it a valid executable source.
if(REFLECTCPP_CHECK_HEADERS)
file(GLOB_RECURSE PROJECT_HEADERS "include/*.hpp")
set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/self_contained_tests")
file(MAKE_DIRECTORY "${TEST_DIR}")
foreach(HEADER_FILE ${PROJECT_HEADERS})
string(MAKE_C_IDENTIFIER ${HEADER_FILE} HEADER_NAME)
set(TEST_SOURCE_FILE "${TEST_DIR}/test_${HEADER_NAME}.cpp")
file(GENERATE
OUTPUT ${TEST_SOURCE_FILE}
CONTENT "#include \"${HEADER_FILE}\"\nint main() { return 0; }\n"
)
add_executable(check_header_${HEADER_NAME} "${TEST_SOURCE_FILE}")
target_link_libraries(check_header_${HEADER_NAME} PRIVATE reflectcpp)
add_custom_target(check_${HEADER_NAME} ALL DEPENDS check_header_${HEADER_NAME})
endforeach()
endif()
No description provided.