diff options
author | MarcoFalke <falke.marco@gmail.com> | 2018-05-19 10:27:54 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2018-05-24 12:02:15 -0400 |
commit | fa3c910bfeab00703c947c5200a64c21225b50ef (patch) | |
tree | 6d8e8ad2d248c22fece1f5c1bebd6cf9ace38db0 /test/lint/lint-include-guards.sh | |
parent | d9ebb63919fb311ace0ae977e3183ccb80ed7d3c (diff) |
test: Move linters to test/lint, add readme
Diffstat (limited to 'test/lint/lint-include-guards.sh')
-rwxr-xr-x | test/lint/lint-include-guards.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/lint/lint-include-guards.sh b/test/lint/lint-include-guards.sh new file mode 100755 index 0000000000..6a0dd556bb --- /dev/null +++ b/test/lint/lint-include-guards.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# Copyright (c) 2018 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +# +# Check include guards. + +HEADER_ID_PREFIX="BITCOIN_" +HEADER_ID_SUFFIX="_H" + +REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/)" + +EXIT_CODE=0 +for HEADER_FILE in $(git ls-files -- "*.h" | grep -vE "^${REGEXP_EXCLUDE_FILES_WITH_PREFIX}") +do + HEADER_ID_BASE=$(cut -f2- -d/ <<< "${HEADER_FILE}" | sed "s/\.h$//g" | tr / _ | tr "[:lower:]" "[:upper:]") + HEADER_ID="${HEADER_ID_PREFIX}${HEADER_ID_BASE}${HEADER_ID_SUFFIX}" + if [[ $(grep -cE "^#(ifndef|define) ${HEADER_ID}" "${HEADER_FILE}") != 2 ]]; then + echo "${HEADER_FILE} seems to be missing the expected include guard:" + echo " #ifndef ${HEADER_ID}" + echo " #define ${HEADER_ID}" + echo " ..." + echo " #endif // ${HEADER_ID}" + echo + EXIT_CODE=1 + fi +done +exit ${EXIT_CODE} |