-
Notifications
You must be signed in to change notification settings - Fork 455
[CDRIVER-4153] Beginning of Header Hygiene & Verification #2053
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
Open
vector-of-bool
wants to merge
15
commits into
mongodb:master
Choose a base branch
from
vector-of-bool:CDRIVER-4153-header-verification
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e45b0ff
Prepare some core header files for public use.
vector-of-bool ab7c733
Fix C++ and C compatibility in some header files
vector-of-bool 3f9d51b
Add CMake code for header verification.
vector-of-bool 38bad5d
Earthly target and EVG tasks to run header verification
vector-of-bool 5cee4bb
Don't require C++ for VerifyHeaders
vector-of-bool f338ea1
Missing pass-thru of Earthly config args
vector-of-bool 446221f
Merge branch 'master' into CDRIVER-4153-header-verification
vector-of-bool 9d0d43b
Minor speeling and grammars fixes
vector-of-bool b12a44b
Remove bad includes following merge
vector-of-bool d83ed79
Missing license header
vector-of-bool 790a408
Merge branch 'master' into CDRIVER-4153-header-verification
vector-of-bool 8a2dcc8
Minor header verification cleanup
vector-of-bool f8331b5
Conditionally add verification by `ENABLE_TESTS`
vector-of-bool 310f23a
Spelling in Earthfile
vector-of-bool 5b5da27
Missing inclusion for snprintf
vector-of-bool File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
include_guard(DIRECTORY) | ||
|
||
#[==[ | ||
Add header verification targets for given headers: | ||
|
||
mongo_verify_headers( | ||
<tag> | ||
[USES_LIBRARIES [<library> ...]] | ||
[HEADERS [<glob> ...]] | ||
[EXCLUDE_REGEX [<pattern> ...]] | ||
) | ||
|
||
Here `<tag>` is an arbitrary string that is used to qualify the internal target | ||
created for the verification. The `<glob>` expressions are used to automatically | ||
collect sources files (relative to the current source directory). All files | ||
collected by `<glob>` must live within the current source directory. | ||
|
||
After collecting sources according to the `<glob>` patterns, sources are | ||
excluded if the filepath contains any substring that matches any regular | ||
expression in the `<pattern>` list. Each `<pattern>` is tested against the | ||
relative path to the header file that was found by `<glob>`, and not the | ||
absolute path to the file. | ||
|
||
The header verification targets are compiled according to the usage requirements | ||
from all `<library>` arguments. | ||
]==] | ||
function(mongo_verify_headers tag) | ||
list(APPEND CMAKE_MESSAGE_CONTEXT "${CMAKE_CURRENT_FUNCTION}(${tag})") | ||
cmake_parse_arguments( | ||
PARSE_ARGV 1 arg | ||
"" # No flags | ||
"" # No args | ||
"HEADERS;EXCLUDE_REGEX;USE_LIBRARIES" # List args | ||
) | ||
if(arg_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "Unknown arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
# Collect headers according to our patterns | ||
set(headers_to_verify) | ||
foreach(pattern IN LISTS arg_HEADERS) | ||
# Use a recursive glob from the current source dir: | ||
file(GLOB_RECURSE more | ||
# Make the paths relative to the calling dir to prevent parent paths | ||
# from interfering with the exclusion regex logic below | ||
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" | ||
# We need to re-run configuration if any files are added/removed | ||
CONFIGURE_DEPENDS | ||
"${pattern}" | ||
) | ||
# Warn if this pattern didn't match anything. It is probably a mistake | ||
# in the caller's argument list. | ||
if(NOT more) | ||
message(WARNING "Globbing pattern “${pattern}” did not match any files") | ||
endif() | ||
list(APPEND headers_to_verify ${more}) | ||
endforeach() | ||
|
||
# Exclude anything that matches any exclusion regex | ||
foreach(pattern IN LISTS arg_EXCLUDE_REGEX) | ||
list(FILTER headers_to_verify EXCLUDE REGEX "${pattern}") | ||
endforeach() | ||
|
||
# Drop duplicates since globs may grab a file more than once | ||
list(REMOVE_DUPLICATES headers_to_verify) | ||
list(SORT headers_to_verify) | ||
foreach(file IN LISTS headers_to_verify) | ||
message(DEBUG "Verify header file: ${file}") | ||
endforeach() | ||
|
||
# We create two targets: One for C and one for C++ | ||
# C target | ||
set(c_target ${tag}-verify-headers-c) | ||
message(DEBUG "Defining header verification target “${c_target}” (C)") | ||
# Create object libraries. They will only have one empty compiled source file. | ||
# The source file language will tell CMake how to verify the associated header files. | ||
add_library(${c_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.c") | ||
# Define the file set | ||
target_sources(${c_target} PUBLIC FILE_SET HEADERS) | ||
eramongodb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Conditionally do the same thing for C++ | ||
if(CMAKE_CXX_COMPILER) | ||
# C++ is available. define it | ||
set(cxx_target ${tag}-verify-headers-cxx) | ||
message(DEBUG "Defining header verification targets “${cxx_target}” (C++)") | ||
add_library(${cxx_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.cpp") | ||
target_sources(${cxx_target} PUBLIC FILE_SET HEADERS) | ||
else() | ||
message(AUTHOR_WARNING "No C++ compiler is available, so the header-check C++ targets won't be defined") | ||
unset(cxx_target) | ||
eramongodb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endif() | ||
# Populate the properties and file sets. | ||
set_target_properties(${c_target} ${cxx_target} PROPERTIES | ||
eramongodb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# The main header file set: | ||
HEADER_SET "${headers_to_verify}" | ||
# Enable header verification: | ||
VERIFY_INTERFACE_HEADER_SETS TRUE | ||
# Add the usage requirements that propagate to the generated compilation rules: | ||
INTERFACE_LINK_LIBRARIES "${arg_USE_LIBRARIES}" | ||
) | ||
endfunction() | ||
|
||
#[[ | ||
Variable set to TRUE if-and-only-if CMake supports header verification. | ||
]] | ||
set(MONGO_CAN_VERIFY_HEADERS FALSE) | ||
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") | ||
set(MONGO_CAN_VERIFY_HEADERS TRUE) | ||
endif() | ||
|
||
# Try to enable C++, but don't require it. This will be used to conditionally | ||
# define the C++ header-check tests | ||
include(CheckLanguage) | ||
check_language(CXX) | ||
if(CMAKE_CXX_COMPILER) | ||
enable_language(CXX) | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* This is an empty placeholder file used for miscellaneous build system tasks | ||
*/ | ||
#include <stddef.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This is an empty placeholder file used for miscellaneous build system tasks | ||
#include <cstddef> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.