-
Notifications
You must be signed in to change notification settings - Fork 590
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
[c/c++] Formatting tool for c/c++ Includes repo-wide #12441
Comments
Big fan of standardized import formatting. Couple thoghts/questions:
|
Looks good to me. I think it is a good idea to set the header file (1.) corresponding to the current cpp file in the first portion, if applicable. It ensures that the header file is self-contained. Currently, a couple of cpp source files in the repo don't follow this concept. |
Looks great! Will this be compatible with IWYU? As in, would running IWYU undo some of the formatting or vice versa? But since we don't really rely on IWYU in this project, it's probably not a blocker for this. |
Thanks for creating this issue @electronjoe ! This will be really useful in maintaining code quality without burdening the code-owners. I have two questions:
|
This is an excellent point @nstng and I'm already concerned about this. I considered adding what "alphabetical" means - Golang's sort of these imports is for example putting capitals as topologically lesser than lowercase (e.g. I think
Do you mean include statements that are |
@ajahl I'm not quite following this - can you clarify? Are you saying that a couple cpp source files do not include their header file interface anywhere? I could believe this. |
@themarwhal I'm fearful that our codebase is not going to be IWYU compatible (or at least will require custom munging of IWYU outputs) due at least to our mixed c/c++ codebase (I do not believe IWYU automation supports C header includes in cpp with |
@ssanadhya I'm not sure how to find these, aside from randomization of the header includes and looking for failures (which is how these have come up in the past - e.g. sorting header includes). So my plan was:
How does that sound? |
@ssanadhya I think the cpp-lint advice will likely be insufficient due to our mixed c/cpp codebase, but I'll go explore that now. In which case I would disable cpp-lint header findings in that linting tool, at the time of replacement with this CI tool discussed in this GH Issue. |
@electronjoe , that sounds good! Thanks for the clarification! |
In some cpp source files, their header file interfaces are not at the top of the |
This issue or pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs in the next 14 days. |
This issue or pull request has exceeded its lifecylce and was automatically closed. Should you wish to continue working on this, please reopen it. |
What and the Why
The purpose of this tooling is to automate the checking and formatting of
#include
directives across our c/c++ codebase. Existing tooling appears insufficient due to our mixture of C/C++ and frequentextern "C"
annotations (e.g. clang-format must be told not to format includes in today's codebase).Why do this? Primarily - today there is no standard applied across the code-base, and even blocks of includes are not sorted (in part because sorting them sometimes breaks unfortunate inter-header-file-sequence assumptions). This has severe implications for anybody moving code around our repository (as one must either manually touch 100+ files to fix up the order of new
#include "new/path/to/header.h"
or leave the now-modified-path out of sorted order.The goal is to author a tool that:
#includes
in the repoSpecification
Top level Ordering
Where possible we adhere to the Google Style for include ordering. The only modification is to enable the use of
extern "C"
blocks.The includes formatter will res-sort includes such that they adhere to the following.
lte/gateway/.../foo.h
.extern "C"
guarded includesasn1c
orprotoc
generated).Sub-block level ordering
Where the blocks of
#include
statements are sorted alphabetically within 3, 5, 7, 9, 11 above.Per-Include Formatting
#include <header.h>
#include "lte/gateway/path/to/header.h"
. This includes generated headers, e.g. protobuf and grpc.#include "json.hpp"
Example
For example in made-up file
lte/gateway/c/core/common/log.cpp
:Corner Cases
There are some challenges that must be handled by any automated formatting tool.
#ifdef
guarded#include
statements which must be preserved by the tool (ideally these would be removed from teh codebase).Any
message type), others are in-repo but dynamically generated.The text was updated successfully, but these errors were encountered: