Skip to content

Commit 3bcc005

Browse files
Add lint-include-guards.sh which checks include guard consistency
1 parent 8fd6af8 commit 3bcc005

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 include guards.
8+
9+
HEADER_ID_PREFIX="BITCOIN_"
10+
HEADER_ID_SUFFIX="_H"
11+
12+
REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/)"
13+
14+
EXIT_CODE=0
15+
for HEADER_FILE in $(git ls-files -- "*.h" | grep -vE "^${REGEXP_EXCLUDE_FILES_WITH_PREFIX}")
16+
do
17+
HEADER_ID_BASE=$(cut -f2- -d/ <<< "${HEADER_FILE}" | sed "s/\.h$//g" | tr / _ | tr "[:lower:]" "[:upper:]")
18+
HEADER_ID="${HEADER_ID_PREFIX}${HEADER_ID_BASE}${HEADER_ID_SUFFIX}"
19+
if [[ $(grep -cE "^#(ifndef|define) ${HEADER_ID}" "${HEADER_FILE}") != 2 ]]; then
20+
echo "${HEADER_FILE} seems to be missing the expected include guard:"
21+
echo " #ifndef ${HEADER_ID}"
22+
echo " #define ${HEADER_ID}"
23+
echo " ..."
24+
echo " #endif // ${HEADER_ID}"
25+
echo
26+
EXIT_CODE=1
27+
fi
28+
done
29+
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)