-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add Travis check for duplicate includes #11878
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
c614e4c
to
b1b9c43
Compare
b1b9c43
to
4dbfc1a
Compare
I just want to point that sometimes the include in the header is unnecessary if a forward declaration is possible. With this check the natural fix is to remove the include from the source. @practicalswift have you checked Iwyu as referenced in #10575? |
I've used iwyu with bitcoin a few times before, though not since we switched from "" to <> style includes. It makes a lot of changes, so it's best to run it manually and selectively on individual source files, rather than in some automated place like a travis script. sudo apt install libclang-dev
cd ~/src
git clone github:include-what-you-use/include-what-you-use.git iwyu
cd iwyu
git checkout clang_3.8
mkdir build && cd build
cmake -DIWYU_LLVM_ROOT_PATH=/usr/lib/llvm-3.8 ..
make
sudo cp -aiv ~/src/iwyu/build/include-what-you-use /usr/lib/llvm-3.8/bin/ Steps to run:
|
@promag Yes, |
Even if it were fast, output isn't really useful or stable enough to run in an automated way. IWYU is most useful as a manual tool to remove unused includes after you add a new source file or split up a existing one. In any case, as instructions above indicate it is awkward to run, and it IMO would have to be a lot easier to run locally to even consider running it on travis. |
Any chance of getting this reviewed? Let me know if it is a NACK and I'll close :-) FWIW, these types of duplicate includes have been recurring and this check is very quick so the costs of introducing it is hopefully near zero :-) |
What? This contradicts the guidelines. If warnings.h references std::string and warnings.cpp uses std::string, both of them should include <string> |
@luke-jr From the header include guideline:
|
@MarcoFalke Would you be willing to review (context: I saw that you mentioned this PR in #11884)? :-) |
utACK. Why is this not included in Travis? |
@sipa |
utACK 4dbfc1a83f79e2208890501b75253b85730e56cc |
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.
Besides the pedantic shell comments I gave, I don't think this is right because you're not going to be able to handle preprocessor statements adequately with this approach.
contrib/devtools/lint-includes.sh
Outdated
|
||
EXIT_CODE=0 | ||
for HEADER_FILE in $(git ls-files | grep -E '^src/.*\.h$' | grep -Ev '/(leveldb|secp256k1|univalue)/'); do | ||
DUPLICATE_INCLUDES_IN_HEADER_FILE=$(grep -E '^#include ' < "${HEADER_FILE}" | sort | uniq -d) |
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.
Why are you using redirection here?
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.
Do you mean why I'm storing the output in DUPLICATE_INCLUDES_IN_HEADER_FILE
? :-) That is the only redirection taking place here, right? :-)
I need the output to print it below. I'm guessing that's not what you meant? :-)
contrib/devtools/lint-includes.sh
Outdated
if [[ ! -e $CPP_FILE ]]; then | ||
continue | ||
fi | ||
DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES=$(grep -hE '^#include ' <(sort -u < "${HEADER_FILE}") <(sort -u < "${CPP_FILE}") | grep -E '^#include ' | sort | uniq -d) |
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.
Same comment wrt redirection
contrib/devtools/lint-includes.sh
Outdated
done | ||
for CPP_FILE in $(git ls-files | grep -E '^src/.*\.cpp$' | grep -Ev '/(leveldb|secp256k1|univalue)/'); do | ||
DUPLICATE_INCLUDES_IN_CPP_FILE=$(grep -E '^#include ' < "${CPP_FILE}" | sort | uniq -d) | ||
if [[ ${DUPLICATE_INCLUDES_IN_CPP_FILE} != "" ]]; then |
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.
You're using ''
in some places and ""
in others
4dbfc1a
to
b1ef6bd
Compare
@eklitzke Please re-review :-) |
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.
Honestly looks good, sorry for the bash nits. For the nit-feedbackness also feel free to ping me on freenode my handle is eklitzke
. Sometimes GitHub code reviews can get queued up, but for minor changes pinging on IRC works.
contrib/devtools/lint-includes.sh
Outdated
@@ -0,0 +1,39 @@ | |||
#!/bin/bash | |||
# | |||
# Copyright (c) 2017 The Bitcoin Core developers |
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.
nit: 2018
contrib/devtools/lint-includes.sh
Outdated
# Check for duplicate includes. | ||
|
||
EXIT_CODE=0 | ||
for HEADER_FILE in $(git ls-files | grep -E "^src/.*\.h$" | grep -Ev "/(leveldb|secp256k1|univalue)/"); do |
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.
nit: you could do this and the change below as a function, and pass in the .h or .cpp'ness in a bash function, e.g.
filter_suffix() { git ls-files | grep -E "^src/.*\.${1}"'$' | grep -Ev "/(leveldb|secp256k1|univalue)/"; }
And then below would become:
for HEADER_FILE in $(filter_suffix h); do
...
for CPP_FILE in $(filter_suffix cpp); do
...
b1ef6bd
to
eb8ba7a
Compare
@eklitzke Good points. Now updated. Please re-review :-) |
eb8ba7a
to
745513e
Compare
utACK 745513ecb7a825a8129104eda382cbc82d35c097 |
Needs rebase if still relevant |
This enforces parts of the project header include guidelines (added by @sipa in bitcoin#10575).
745513e
to
c36b720
Compare
Rebased and removed 5+ few recently introduced duplicate includes. Still very much relevant :-) Please re-review :-) |
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
@MarcoFalke Thanks for merging! :-) |
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
Backport useful lints from upstream Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6892 - bitcoin/bitcoin#11151 - bitcoin/bitcoin#11300 - bitcoin/bitcoin@96d91b7 - bitcoin/bitcoin#12097 - bitcoin/bitcoin#12098 - bitcoin/bitcoin#12442 - bitcoin/bitcoin#12572 - bitcoin/bitcoin#12757 - bitcoin/bitcoin#11878 - bitcoin/bitcoin#12933 - bitcoin/bitcoin#12871 - bitcoin/bitcoin#12972 - bitcoin/bitcoin#13281 - bitcoin/bitcoin#13385 - bitcoin/bitcoin#13041 - bitcoin/bitcoin#13454 - bitcoin/bitcoin#13448 - bitcoin/bitcoin#13510 - bitcoin/bitcoin#13851 - bitcoin/bitcoin#13863 - bitcoin/bitcoin#14115 - bitcoin/bitcoin#14831 - bitcoin/bitcoin#15164 - bitcoin/bitcoin#15170 - bitcoin/bitcoin#15166 - bitcoin/bitcoin#16036 - bitcoin/bitcoin#16768 Several of the lints fail for our current codebase; these will be addressed in a subsequent PR.
Backport useful lints from upstream Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6892 - bitcoin/bitcoin#11151 - bitcoin/bitcoin#11300 - bitcoin/bitcoin@96d91b7 - bitcoin/bitcoin#12097 - bitcoin/bitcoin#12098 - bitcoin/bitcoin#12442 - bitcoin/bitcoin#12572 - bitcoin/bitcoin#12757 - bitcoin/bitcoin#11878 - bitcoin/bitcoin#12933 - bitcoin/bitcoin#12871 - bitcoin/bitcoin#12972 - bitcoin/bitcoin#13281 - bitcoin/bitcoin#13385 - bitcoin/bitcoin#13041 - bitcoin/bitcoin#13454 - bitcoin/bitcoin#13448 - bitcoin/bitcoin#13510 - bitcoin/bitcoin#13851 - bitcoin/bitcoin#13863 - bitcoin/bitcoin#14115 - bitcoin/bitcoin#14831 - bitcoin/bitcoin#15164 - bitcoin/bitcoin#15170 - bitcoin/bitcoin#15166 - bitcoin/bitcoin#16036 - bitcoin/bitcoin#16768 - bitcoin/bitcoin#13494 Several of the lints fail for our current codebase; these will be addressed in a subsequent PR.
ad5717d Lint: Add lint-includes.sh (Fuzzbawls) faba3f6 [tests] Use FastRandomContext in scheduler_tests.cpp (practicalswift) 2034bf6 Remove unused boost includes in reverselock_tests.cpp (Fuzzbawls) 3256d16 bench: Use non-throwing ParseDouble() (Fuzzbawls) 3c984d1 Remove duplicate includes (Fuzzbawls) b54e396 Declare TorReply parsing functions in torcontrol_tests (Fuzzbawls) Pull request description: This brings in the `lint-includes.sh` shell script from upstream (first introduced in bitcoin#11878) to automatically check for duplicate includes and expanded in bitcoin#13301 and bitcoin#13385 to check for the inclusion of `.cpp` files and the introduction of new boost includes, respectively. The check for enforcing bracket include syntax (bitcoin#13230) is also included, but currently disabled, as we have yet to systematically switch to that syntax preference. Three other upstream PRs are backported here as they are directly related to the removal of some boost dependencies and are very straight forward: - bitcoin#10547 - bitcoin#13291 - bitcoin#13383 **NOTE: #2711 removes the dependency on `boost/tuple/tuple.hpp`, so it makes sense to merge that first. submitting this now so the general concept/functionality can be reviewed prior to that PR being merged** ACKs for top commit: furszy: good ACK ad5717d random-zebra: utACK ad5717d and merging... Tree-SHA512: d9d32d6d5122dac52c9601cda75612d87c4e027c6f196a2382206b227fcfd2bb61d4f72df7cbf5e572d94150ad8ca6db6301bd99b0da647b9627fe342b66873f
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
This enforces parts of the project header include guidelines (added by @sipa in #10575).
Example run: