diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2017-12-12 17:39:24 +0100 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2018-04-09 09:18:49 +0200 |
commit | c36b720d009f1ab1c3900750e05c1f17412e564d (patch) | |
tree | 72bda98aa8ccc37f27fc1ce711885a44dfe171fe | |
parent | 280023f31d7007694f9f77e07868ae122c55cfd7 (diff) |
Add Travis check for duplicate includes
This enforces parts of the project header include guidelines (added by @sipa in #10575).
-rwxr-xr-x | contrib/devtools/lint-includes.sh | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/devtools/lint-includes.sh b/contrib/devtools/lint-includes.sh new file mode 100755 index 0000000000..baca2f8a1f --- /dev/null +++ b/contrib/devtools/lint-includes.sh @@ -0,0 +1,43 @@ +#!/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 for duplicate includes. + +filter_suffix() { + git ls-files | grep -E "^src/.*\.${1}"'$' | grep -Ev "/(leveldb|secp256k1|univalue)/" +} + +EXIT_CODE=0 +for HEADER_FILE in $(filter_suffix h); do + DUPLICATE_INCLUDES_IN_HEADER_FILE=$(grep -E "^#include " < "${HEADER_FILE}" | sort | uniq -d) + if [[ ${DUPLICATE_INCLUDES_IN_HEADER_FILE} != "" ]]; then + echo "Duplicate include(s) in ${HEADER_FILE}:" + echo "${DUPLICATE_INCLUDES_IN_HEADER_FILE}" + echo + EXIT_CODE=1 + fi + CPP_FILE=${HEADER_FILE/%\.h/.cpp} + 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) + if [[ ${DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES} != "" ]]; then + echo "Include(s) from ${HEADER_FILE} duplicated in ${CPP_FILE}:" + echo "${DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES}" + echo + EXIT_CODE=1 + fi +done +for CPP_FILE in $(filter_suffix cpp); do + DUPLICATE_INCLUDES_IN_CPP_FILE=$(grep -E "^#include " < "${CPP_FILE}" | sort | uniq -d) + if [[ ${DUPLICATE_INCLUDES_IN_CPP_FILE} != "" ]]; then + echo "Duplicate include(s) in ${CPP_FILE}:" + echo "${DUPLICATE_INCLUDES_IN_CPP_FILE}" + echo + EXIT_CODE=1 + fi +done +exit ${EXIT_CODE} |