lints: Use Zcash-specific include guards for new files

This commit is contained in:
Jack Grigg 2020-10-27 11:35:23 +00:00
parent d89f31dc43
commit f318ab3776
2 changed files with 18 additions and 13 deletions

View File

@ -305,13 +305,13 @@ Source code organization
-------------------------- --------------------------
- Use include guards to avoid the problem of double inclusion. The header file - 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++ ```c++
#ifndef BITCOIN_FOO_BAR_H #ifndef ZCASH_FOO_BAR_H
#define BITCOIN_FOO_BAR_H #define ZCASH_FOO_BAR_H
... ...
#endif // BITCOIN_FOO_BAR_H #endif // ZCASH_FOO_BAR_H
``` ```
Scripted diffs Scripted diffs

View File

@ -1,30 +1,35 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Copyright (c) 2018 The Bitcoin Core developers # Copyright (c) 2018 The Bitcoin Core developers
# Copyright (c) 2020 The Zcash developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
# #
# Check include guards. # Check include guards.
export LC_ALL=C export LC_ALL=C
HEADER_ID_PREFIX="BITCOIN_" HEADER_ID_PREFIX="ZCASH_"
HEADER_ID_PREFIX_UPSTREAM="BITCOIN_"
HEADER_ID_SUFFIX="_H" 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 EXIT_CODE=0
for HEADER_FILE in $(git ls-files -- "*.h" | grep -vE "^${REGEXP_EXCLUDE_FILES_WITH_PREFIX}") for HEADER_FILE in $(git ls-files -- "*.h" | grep -vE "^${REGEXP_EXCLUDE_FILES_WITH_PREFIX}")
do do
HEADER_ID_BASE=$(cut -f2- -d/ <<< "${HEADER_FILE}" | sed "s/\.h$//g" | tr / _ | tr "[:lower:]" "[:upper:]") 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="${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 if [[ $(grep -cE "^#(ifndef|define) ${HEADER_ID}" "${HEADER_FILE}") != 2 ]]; then
echo "${HEADER_FILE} seems to be missing the expected include guard:" if [[ $(grep -cE "^#(ifndef|define) ${HEADER_ID_UPSTREAM}" "${HEADER_FILE}") != 2 ]]; then
echo " #ifndef ${HEADER_ID}" echo "${HEADER_FILE} seems to be missing the expected include guard:"
echo " #define ${HEADER_ID}" echo " #ifndef ${HEADER_ID}"
echo " ..." echo " #define ${HEADER_ID}"
echo " #endif // ${HEADER_ID}" echo " ..."
echo echo " #endif // ${HEADER_ID}"
EXIT_CODE=1 echo
EXIT_CODE=1
fi
fi fi
done done
exit ${EXIT_CODE} exit ${EXIT_CODE}