-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Header include guideline #10575
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
Header include guideline #10575
Conversation
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.
ACK
ACK! |
ACK a090d1c |
ACK a090d1c |
Good! |
Makes sense. Is there a good way to check/review this, though? Would be useful to add suggestion for reviewing. I'm also afraid this will generate lots of 'mess around with headers' PRs, so we probably want to add that this holds for new code. |
@laanwj I wrote the following script ... #!/bin/bash
for H in $(git grep "" -- "*.h" | cut -f1 -d: | uniq); do
CPP=${H/%\.h/.cpp}
if [[ ! -e $CPP ]]; then
continue
fi
cat "$H" "$CPP" | grep -E "^#include " | sort | uniq -c | \
grep " 2 #include" && echo "$CPP" && echo
done ... to identify |
Well yes but I'm more interested in the first point:
So how to check that a .cpp or .h is using functionality that is only indirectly included? Seems like a lot of work to do manually, at least. |
Iwyu is great and it would be really nice if it works on bitcoin source. It manages forward declarations as well as includes and will automatically add/remove/convert between them as appropriate. |
Perhaps we should have iwyu included in our build system, and then refer to it in developer-notes.md? |
Has anyone tried? Edit: anyhow, that discussion does not have to block this. If you get that tool to work, it would be appreciated if you file a PR how to use it with our source. |
a090d1c Header include guideline (Pieter Wuille) Tree-SHA512: 44c46a3e249c946303b0fa45ddeba1abc40ec4f993b78f10894d6f43de2b62c493d74f8a24b5b69d3c71cd5c1b3cdb638c8eabdade3dc60e376bc933a8f10940
…ing .h file already included a720b92 Remove includes in .cpp files for things the corresponding .h file already included (practicalswift) Pull request description: Remove includes in .cpp files for things the corresponding .h file already included. Example case: * `addrdb.cpp` includes `addrdb.h` and `fs.h` * `addrdb.h` includes `fs.h` Then remove the direct inclusion of `fs.h` in `addrman.cpp` and rely on the indirect inclusion of `fs.h` via the included `addrdb.h`. In line with the header include guideline (see #10575). Tree-SHA512: 8704b9de3011a4c234db336a39f7d2c139e741cf0f7aef08a5d3e05197e1e18286b863fdab25ae9638af4ff86b3d52e5cab9eed66bfa2476063aa5c79f9b0346
This enforces parts of the project header include guidelines (added by @sipa in bitcoin#10575).
c36b720 Add Travis check for duplicate includes (practicalswift) 280023f Remove duplicate includes (practicalswift) Pull request description: This enforces parts of the project header include guidelines (added by @sipa in #10575). Example run: ``` $ git diff diff --git a/src/warnings.cpp b/src/warnings.cpp index c52a1fd..d8994dd 100644 --- a/src/warnings.cpp +++ b/src/warnings.cpp @@ -5,6 +5,8 @@ #include <sync.h> #include <clientversion.h> +#include <string> #include <util.h> #include <warnings.h> +#include <util.h> diff --git a/src/warnings.h b/src/warnings.h index e8e982c..8d2252e 100644 --- a/src/warnings.h +++ b/src/warnings.h @@ -7,6 +7,7 @@ #define BITCOIN_WARNINGS_H #include <stdlib.h> #include <string> +#include <stdlib.h> void SetMiscWarning(const std::string& strWarning); $ contrib/devtools/lint-includes.sh Duplicate include(s) in src/warnings.h: #include <stdlib.h> Include(s) from src/warnings.h duplicated in src/warnings.cpp: #include <string> Duplicate include(s) in src/warnings.cpp: #include <util.h> $ echo $? 1 $ git checkout . $ contrib/devtools/lint-includes.sh $ echo $? 0 ``` Tree-SHA512: f653d23c58ebc024dfc5b1fb8570698fd3c515c75b60b5cabbc43595548c488fca92349fa4c8b64460edbe61c879ff1d24f37f959e18552e202a7342460ddbf1
This enforces parts of the project header include guidelines (added by @sipa in bitcoin#10575).
This enforces parts of the project header include guidelines (added by @sipa in bitcoin#10575).
a090d1c Header include guideline (Pieter Wuille) Tree-SHA512: 44c46a3e249c946303b0fa45ddeba1abc40ec4f993b78f10894d6f43de2b62c493d74f8a24b5b69d3c71cd5c1b3cdb638c8eabdade3dc60e376bc933a8f10940
a090d1c Header include guideline (Pieter Wuille) Tree-SHA512: 44c46a3e249c946303b0fa45ddeba1abc40ec4f993b78f10894d6f43de2b62c493d74f8a24b5b69d3c71cd5c1b3cdb638c8eabdade3dc60e376bc933a8f10940
a090d1c Header include guideline (Pieter Wuille) Tree-SHA512: 44c46a3e249c946303b0fa45ddeba1abc40ec4f993b78f10894d6f43de2b62c493d74f8a24b5b69d3c71cd5c1b3cdb638c8eabdade3dc60e376bc933a8f10940
a090d1c Header include guideline (Pieter Wuille) Tree-SHA512: 44c46a3e249c946303b0fa45ddeba1abc40ec4f993b78f10894d6f43de2b62c493d74f8a24b5b69d3c71cd5c1b3cdb638c8eabdade3dc60e376bc933a8f10940
a090d1c Header include guideline (Pieter Wuille) Tree-SHA512: 44c46a3e249c946303b0fa45ddeba1abc40ec4f993b78f10894d6f43de2b62c493d74f8a24b5b69d3c71cd5c1b3cdb638c8eabdade3dc60e376bc933a8f10940
a090d1c Header include guideline (Pieter Wuille) Tree-SHA512: 44c46a3e249c946303b0fa45ddeba1abc40ec4f993b78f10894d6f43de2b62c493d74f8a24b5b69d3c71cd5c1b3cdb638c8eabdade3dc60e376bc933a8f10940
a090d1c Header include guideline (Pieter Wuille) Tree-SHA512: 44c46a3e249c946303b0fa45ddeba1abc40ec4f993b78f10894d6f43de2b62c493d74f8a24b5b69d3c71cd5c1b3cdb638c8eabdade3dc60e376bc933a8f10940
…responding .h file already included a720b92 Remove includes in .cpp files for things the corresponding .h file already included (practicalswift) Pull request description: Remove includes in .cpp files for things the corresponding .h file already included. Example case: * `addrdb.cpp` includes `addrdb.h` and `fs.h` * `addrdb.h` includes `fs.h` Then remove the direct inclusion of `fs.h` in `addrman.cpp` and rely on the indirect inclusion of `fs.h` via the included `addrdb.h`. In line with the header include guideline (see bitcoin#10575). Tree-SHA512: 8704b9de3011a4c234db336a39f7d2c139e741cf0f7aef08a5d3e05197e1e18286b863fdab25ae9638af4ff86b3d52e5cab9eed66bfa2476063aa5c79f9b0346
…responding .h file already included a720b92 Remove includes in .cpp files for things the corresponding .h file already included (practicalswift) Pull request description: Remove includes in .cpp files for things the corresponding .h file already included. Example case: * `addrdb.cpp` includes `addrdb.h` and `fs.h` * `addrdb.h` includes `fs.h` Then remove the direct inclusion of `fs.h` in `addrman.cpp` and rely on the indirect inclusion of `fs.h` via the included `addrdb.h`. In line with the header include guideline (see bitcoin#10575). Tree-SHA512: 8704b9de3011a4c234db336a39f7d2c139e741cf0f7aef08a5d3e05197e1e18286b863fdab25ae9638af4ff86b3d52e5cab9eed66bfa2476063aa5c79f9b0346
…responding .h file already included a720b92 Remove includes in .cpp files for things the corresponding .h file already included (practicalswift) Pull request description: Remove includes in .cpp files for things the corresponding .h file already included. Example case: * `addrdb.cpp` includes `addrdb.h` and `fs.h` * `addrdb.h` includes `fs.h` Then remove the direct inclusion of `fs.h` in `addrman.cpp` and rely on the indirect inclusion of `fs.h` via the included `addrdb.h`. In line with the header include guideline (see bitcoin#10575). Tree-SHA512: 8704b9de3011a4c234db336a39f7d2c139e741cf0f7aef08a5d3e05197e1e18286b863fdab25ae9638af4ff86b3d52e5cab9eed66bfa2476063aa5c79f9b0346
…responding .h file already included a720b92 Remove includes in .cpp files for things the corresponding .h file already included (practicalswift) Pull request description: Remove includes in .cpp files for things the corresponding .h file already included. Example case: * `addrdb.cpp` includes `addrdb.h` and `fs.h` * `addrdb.h` includes `fs.h` Then remove the direct inclusion of `fs.h` in `addrman.cpp` and rely on the indirect inclusion of `fs.h` via the included `addrdb.h`. In line with the header include guideline (see bitcoin#10575). Tree-SHA512: 8704b9de3011a4c234db336a39f7d2c139e741cf0f7aef08a5d3e05197e1e18286b863fdab25ae9638af4ff86b3d52e5cab9eed66bfa2476063aa5c79f9b0346
…responding .h file already included a720b92 Remove includes in .cpp files for things the corresponding .h file already included (practicalswift) Pull request description: Remove includes in .cpp files for things the corresponding .h file already included. Example case: * `addrdb.cpp` includes `addrdb.h` and `fs.h` * `addrdb.h` includes `fs.h` Then remove the direct inclusion of `fs.h` in `addrman.cpp` and rely on the indirect inclusion of `fs.h` via the included `addrdb.h`. In line with the header include guideline (see bitcoin#10575). Tree-SHA512: 8704b9de3011a4c234db336a39f7d2c139e741cf0f7aef08a5d3e05197e1e18286b863fdab25ae9638af4ff86b3d52e5cab9eed66bfa2476063aa5c79f9b0346
…responding .h file already included a720b92 Remove includes in .cpp files for things the corresponding .h file already included (practicalswift) Pull request description: Remove includes in .cpp files for things the corresponding .h file already included. Example case: * `addrdb.cpp` includes `addrdb.h` and `fs.h` * `addrdb.h` includes `fs.h` Then remove the direct inclusion of `fs.h` in `addrman.cpp` and rely on the indirect inclusion of `fs.h` via the included `addrdb.h`. In line with the header include guideline (see bitcoin#10575). Tree-SHA512: 8704b9de3011a4c234db336a39f7d2c139e741cf0f7aef08a5d3e05197e1e18286b863fdab25ae9638af4ff86b3d52e5cab9eed66bfa2476063aa5c79f9b0346
c36b720 Add Travis check for duplicate includes (practicalswift) 280023f Remove duplicate includes (practicalswift) Pull request description: This enforces parts of the project header include guidelines (added by @sipa in bitcoin#10575). Example run: ``` $ git diff diff --git a/src/warnings.cpp b/src/warnings.cpp index c52a1fd..d8994dd 100644 --- a/src/warnings.cpp +++ b/src/warnings.cpp @@ -5,6 +5,8 @@ #include <sync.h> #include <clientversion.h> +#include <string> #include <util.h> #include <warnings.h> +#include <util.h> diff --git a/src/warnings.h b/src/warnings.h index e8e982c..8d2252e 100644 --- a/src/warnings.h +++ b/src/warnings.h @@ -7,6 +7,7 @@ #define BITCOIN_WARNINGS_H #include <stdlib.h> #include <string> +#include <stdlib.h> void SetMiscWarning(const std::string& strWarning); $ contrib/devtools/lint-includes.sh Duplicate include(s) in src/warnings.h: #include <stdlib.h> Include(s) from src/warnings.h duplicated in src/warnings.cpp: #include <string> Duplicate include(s) in src/warnings.cpp: #include <util.h> $ echo $? 1 $ git checkout . $ contrib/devtools/lint-includes.sh $ echo $? 0 ``` Tree-SHA512: f653d23c58ebc024dfc5b1fb8570698fd3c515c75b60b5cabbc43595548c488fca92349fa4c8b64460edbe61c879ff1d24f37f959e18552e202a7342460ddbf1
c36b720 Add Travis check for duplicate includes (practicalswift) 280023f Remove duplicate includes (practicalswift) Pull request description: This enforces parts of the project header include guidelines (added by @sipa in bitcoin#10575). Example run: ``` $ git diff diff --git a/src/warnings.cpp b/src/warnings.cpp index c52a1fd..d8994dd 100644 --- a/src/warnings.cpp +++ b/src/warnings.cpp @@ -5,6 +5,8 @@ #include <sync.h> #include <clientversion.h> +#include <string> #include <util.h> #include <warnings.h> +#include <util.h> diff --git a/src/warnings.h b/src/warnings.h index e8e982c..8d2252e 100644 --- a/src/warnings.h +++ b/src/warnings.h @@ -7,6 +7,7 @@ #define BITCOIN_WARNINGS_H #include <stdlib.h> #include <string> +#include <stdlib.h> void SetMiscWarning(const std::string& strWarning); $ contrib/devtools/lint-includes.sh Duplicate include(s) in src/warnings.h: #include <stdlib.h> Include(s) from src/warnings.h duplicated in src/warnings.cpp: #include <string> Duplicate include(s) in src/warnings.cpp: #include <util.h> $ echo $? 1 $ git checkout . $ contrib/devtools/lint-includes.sh $ echo $? 0 ``` Tree-SHA512: f653d23c58ebc024dfc5b1fb8570698fd3c515c75b60b5cabbc43595548c488fca92349fa4c8b64460edbe61c879ff1d24f37f959e18552e202a7342460ddbf1
No description provided.