-
Notifications
You must be signed in to change notification settings - Fork 54
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
code: cleanup includes - use "include what you use" model #1089
Closed
mhofstetter
wants to merge
4
commits into
cilium:main
from
mhofstetter:pr/mhofstetter/clangd-cleanup-imports
Closed
code: cleanup includes - use "include what you use" model #1089
mhofstetter
wants to merge
4
commits into
cilium:main
from
mhofstetter:pr/mhofstetter/clangd-cleanup-imports
+980
−205
Conversation
This file contains 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
mhofstetter
force-pushed
the
pr/mhofstetter/clangd-cleanup-imports
branch
3 times, most recently
from
January 3, 2025 15:38
c9f1f5a
to
77609f3
Compare
mhofstetter
added a commit
to mhofstetter/proxy
that referenced
this pull request
Jan 3, 2025
Upstream Envoy linting prevents usages of `std::mutex` in favor of `Thread::MutexBasicLockable`. See https://github.com/envoyproxy/envoy/blob/main/tools/code_format/check_format.py#L605-L610 ``` report_error( "Don't use <mutex> or <condition_variable*>, switch to " "Thread::MutexBasicLockable in source/common/common/thread.h") ``` This error occurred while trying to cleanup the imports - and therefore adding the direct dependency to `<mutex>`. See cilium#1089 Signed-off-by: Marco Hofstetter <[email protected]>
mhofstetter
added a commit
to mhofstetter/proxy
that referenced
this pull request
Jan 3, 2025
Upstream Envoy linting prevents usages of `std::mutex` in favor of `Thread::MutexBasicLockable`. See https://github.com/envoyproxy/envoy/blob/main/tools/code_format/check_format.py#L605-L610 ``` report_error( "Don't use <mutex> or <condition_variable*>, switch to " "Thread::MutexBasicLockable in source/common/common/thread.h") ``` This error occurred while trying to cleanup the imports - and therefore adding the direct dependency to `<mutex>`. See cilium#1089 Signed-off-by: Marco Hofstetter <[email protected]>
mhofstetter
changed the title
code: cleanup imports - use "import what you use" model
code: cleanup imports - use "include what you use" model
Jan 3, 2025
mhofstetter
changed the title
code: cleanup imports - use "include what you use" model
code: cleanup includes - use "include what you use" model
Jan 3, 2025
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jan 7, 2025
Upstream Envoy linting prevents usages of `std::mutex` in favor of `Thread::MutexBasicLockable`. See https://github.com/envoyproxy/envoy/blob/main/tools/code_format/check_format.py#L605-L610 ``` report_error( "Don't use <mutex> or <condition_variable*>, switch to " "Thread::MutexBasicLockable in source/common/common/thread.h") ``` This error occurred while trying to cleanup the imports - and therefore adding the direct dependency to `<mutex>`. See #1089 Signed-off-by: Marco Hofstetter <[email protected]>
mhofstetter
force-pushed
the
pr/mhofstetter/clangd-cleanup-imports
branch
5 times, most recently
from
January 7, 2025 09:21
da22633
to
366a4b6
Compare
Currently, the C++ files are either including unused files or heavily rely on transtive includes and doesn't define the actual required includes. Therefore, this commit fixes all includes so that all files are defining their includes according to their needs - following the model "import what you use". See https://clangd.llvm.org/guides/include-cleaner Advantages: * Get rid of warnings when using clangd as LSP server * Remove unused imports * Define all direct imports helps understanding the code and the dependencies Signed-off-by: Marco Hofstetter <[email protected]>
To prevent upstream Envoy lint issues, this commit refactors the includes to use `source/common/protobuf/protobuf.h` instead of the `google/protobuf/...` includes. Signed-off-by: Marco Hofstetter <[email protected]>
Instantiate strings for assertion with `std:string` instead of raw string literals to prevent clangd importing `bits/basic_string.h` which leads to potential compiler errors. Signed-off-by: Marco Hofstetter <[email protected]>
mhofstetter
force-pushed
the
pr/mhofstetter/clangd-cleanup-imports
branch
from
January 7, 2025 09:44
366a4b6
to
6cd8a15
Compare
Signed-off-by: Marco Hofstetter <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, the C++ files are either including unused files or heavily rely on transtive includes and doesn't define the actual required includes.
Therefore, this commit fixes all includes so that all files are defining their includes according to their needs - following the model "include what you use".
See https://clangd.llvm.org/guides/include-cleaner
Advantages:
Note: For the time being there will not be any validation in CI. It's more or less just a cleanup and a potential start to establish this pattern because I think this helps for others to familiarize with the codebase.
Related to #1087