lints: Use Zcash-specific include guards for new files
This commit is contained in:
parent
d89f31dc43
commit
f318ab3776
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue