From f318ab377626bc248326f60131b974195dbb46cb Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 27 Oct 2020 11:35:23 +0000 Subject: [PATCH] lints: Use Zcash-specific include guards for new files --- doc/developer-notes.md | 8 ++++---- test/lint/lint-include-guards.sh | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index a4465a27b..e7df0cc53 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -305,13 +305,13 @@ Source code organization -------------------------- - Use include guards to avoid the problem of double inclusion. The header file - `foo/bar.h` should use the include guard identifier `BITCOIN_FOO_BAR_H`, e.g. + `foo/bar.h` should use the include guard identifier `ZCASH_FOO_BAR_H`, e.g. ```c++ -#ifndef BITCOIN_FOO_BAR_H -#define BITCOIN_FOO_BAR_H +#ifndef ZCASH_FOO_BAR_H +#define ZCASH_FOO_BAR_H ... -#endif // BITCOIN_FOO_BAR_H +#endif // ZCASH_FOO_BAR_H ``` Scripted diffs diff --git a/test/lint/lint-include-guards.sh b/test/lint/lint-include-guards.sh index 464969794..950e8b664 100755 --- a/test/lint/lint-include-guards.sh +++ b/test/lint/lint-include-guards.sh @@ -1,30 +1,35 @@ #!/usr/bin/env bash # # Copyright (c) 2018 The Bitcoin Core developers +# Copyright (c) 2020 The Zcash developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. # # Check include guards. export LC_ALL=C -HEADER_ID_PREFIX="BITCOIN_" +HEADER_ID_PREFIX="ZCASH_" +HEADER_ID_PREFIX_UPSTREAM="BITCOIN_" HEADER_ID_SUFFIX="_H" -REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/)" +REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|leveldb/|rust/|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}" + HEADER_ID_UPSTREAM="${HEADER_ID_PREFIX_UPSTREAM}${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 + if [[ $(grep -cE "^#(ifndef|define) ${HEADER_ID_UPSTREAM}" "${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 fi done exit ${EXIT_CODE}