File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ #
3
+ # Copyright (c) 2018 The Bitcoin Core developers
4
+ # Distributed under the MIT software license, see the accompanying
5
+ # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6
+ #
7
+ # Check for duplicate includes.
8
+
9
+ filter_suffix () {
10
+ git ls-files | grep -E " ^src/.*\.${1} " ' $' | grep -Ev " /(leveldb|secp256k1|univalue)/"
11
+ }
12
+
13
+ EXIT_CODE=0
14
+ for HEADER_FILE in $( filter_suffix h) ; do
15
+ DUPLICATE_INCLUDES_IN_HEADER_FILE=$( grep -E " ^#include " < " ${HEADER_FILE} " | sort | uniq -d)
16
+ if [[ ${DUPLICATE_INCLUDES_IN_HEADER_FILE} != " " ]]; then
17
+ echo " Duplicate include(s) in ${HEADER_FILE} :"
18
+ echo " ${DUPLICATE_INCLUDES_IN_HEADER_FILE} "
19
+ echo
20
+ EXIT_CODE=1
21
+ fi
22
+ CPP_FILE=${HEADER_FILE/% \. h/ .cpp}
23
+ if [[ ! -e $CPP_FILE ]]; then
24
+ continue
25
+ fi
26
+ DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES=$( grep -hE " ^#include " <( sort -u < " ${HEADER_FILE} " ) <( sort -u < " ${CPP_FILE} " ) | grep -E " ^#include " | sort | uniq -d)
27
+ if [[ ${DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES} != " " ]]; then
28
+ echo " Include(s) from ${HEADER_FILE} duplicated in ${CPP_FILE} :"
29
+ echo " ${DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES} "
30
+ echo
31
+ EXIT_CODE=1
32
+ fi
33
+ done
34
+ for CPP_FILE in $( filter_suffix cpp) ; do
35
+ DUPLICATE_INCLUDES_IN_CPP_FILE=$( grep -E " ^#include " < " ${CPP_FILE} " | sort | uniq -d)
36
+ if [[ ${DUPLICATE_INCLUDES_IN_CPP_FILE} != " " ]]; then
37
+ echo " Duplicate include(s) in ${CPP_FILE} :"
38
+ echo " ${DUPLICATE_INCLUDES_IN_CPP_FILE} "
39
+ echo
40
+ EXIT_CODE=1
41
+ fi
42
+ done
43
+ exit ${EXIT_CODE}
You can’t perform that action at this time.
0 commit comments