Skip to content

Commit 7c32b41

Browse files
committed
Merge #13230: Simplify include analysis by enforcing the developer guide's include syntax
16e3cd3 Clarify include recommendation (practicalswift) 6d10f43 Enforce the use of bracket syntax includes ("#include <foo.h>") (practicalswift) 906bee8 Use bracket syntax includes ("#include <foo.h>") (practicalswift) Pull request description: When analysing includes in the project it is often assumed that the preferred bracket include syntax (`#include <foo.h>`) mentioned in `developer-docs.md` is used consistently. @sipa:s excellent circular dependencies script [`circular-dependencies.py`](https://github.com/sipa/bitcoin/blob/50c69b78011c1bc55885ebfd216db60ed490ebea/contrib/devtools/circular-dependencies.py) (#13228) is an example of a script making this reasonable assumption. This PR enables automatic Travis checking of the include syntax making sure that the bracket syntax includes (`#include <foo.h>`) is used consistently. Tree-SHA512: a414921aabe8e487ebed42f3f1cbd02fecd1add385065c1f2244cd602c31889e61fea5a801507ec501ef9bd309b05d3c999f915cec1c2b44f085bb0d2835c182
2 parents 43ae5ee + 16e3cd3 commit 7c32b41

File tree

7 files changed

+33
-22
lines changed

7 files changed

+33
-22
lines changed

doc/developer-notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@ namespace {
622622

623623
- *Rationale*: Avoids confusion about the namespace context
624624

625-
- Prefer `#include <primitives/transaction.h>` bracket syntax instead of
626-
`#include "primitives/transactions.h"` quote syntax when possible.
625+
- Use `#include <primitives/transaction.h>` bracket syntax instead of
626+
`#include "primitives/transactions.h"` quote syntax.
627627

628628
- *Rationale*: Bracket syntax is less ambiguous because the preprocessor
629629
searches a fixed list of include directories without taking location of the

src/bench/merkle_root.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include "bench.h"
5+
#include <bench/bench.h>
66

7-
#include "uint256.h"
8-
#include "random.h"
9-
#include "consensus/merkle.h"
7+
#include <uint256.h>
8+
#include <random.h>
9+
#include <consensus/merkle.h>
1010

1111
static void MerkleRoot(benchmark::State& state)
1212
{

src/crypto/sha256_avx2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <x86intrin.h>
88
#endif
99

10-
#include "crypto/sha256.h"
11-
#include "crypto/common.h"
10+
#include <crypto/sha256.h>
11+
#include <crypto/common.h>
1212

1313
namespace sha256d64_avx2 {
1414
namespace {

src/crypto/sha256_sse41.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <x86intrin.h>
88
#endif
99

10-
#include "crypto/sha256.h"
11-
#include "crypto/common.h"
10+
#include <crypto/sha256.h>
11+
#include <crypto/common.h>
1212

1313
namespace sha256d64_sse41 {
1414
namespace {

src/test/blockchain_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <boost/test/unit_test.hpp>
22

3-
#include "stdlib.h"
3+
#include <stdlib.h>
44

5-
#include "rpc/blockchain.h"
6-
#include "test/test_bitcoin.h"
5+
#include <rpc/blockchain.h>
6+
#include <test/test_bitcoin.h>
77

88
/* Equality between doubles is imprecise. Comparison should be done
99
* with a small threshold of tolerance, rather than exact equality.

src/wallet/test/coinselector_tests.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include "wallet/wallet.h"
6-
#include "wallet/coinselection.h"
7-
#include "wallet/coincontrol.h"
8-
#include "amount.h"
9-
#include "primitives/transaction.h"
10-
#include "random.h"
11-
#include "test/test_bitcoin.h"
12-
#include "wallet/test/wallet_test_fixture.h"
5+
#include <wallet/wallet.h>
6+
#include <wallet/coinselection.h>
7+
#include <wallet/coincontrol.h>
8+
#include <amount.h>
9+
#include <primitives/transaction.h>
10+
#include <random.h>
11+
#include <test/test_bitcoin.h>
12+
#include <wallet/test/wallet_test_fixture.h>
1313

1414
#include <boost/test/unit_test.hpp>
1515
#include <random>

test/lint/lint-includes.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
#
77
# Check for duplicate includes.
88
# Guard against accidental introduction of new Boost dependencies.
9+
# Check includes: Check for duplicate includes. Enforce bracket syntax includes.
10+
11+
IGNORE_REGEXP="/(leveldb|secp256k1|univalue)/"
912

1013
filter_suffix() {
11-
git ls-files | grep -E "^src/.*\.${1}"'$' | grep -Ev "/(leveldb|secp256k1|univalue)/"
14+
git ls-files | grep -E "^src/.*\.${1}"'$' | grep -Ev "${IGNORE_REGEXP}"
1215
}
1316

1417
EXIT_CODE=0
@@ -105,4 +108,12 @@ for EXPECTED_BOOST_INCLUDE in "${EXPECTED_BOOST_INCLUDES[@]}"; do
105108
fi
106109
done
107110

111+
QUOTE_SYNTAX_INCLUDES=$(git grep '^#include "' -- "*.cpp" "*.h" | grep -Ev "${IGNORE_REGEXP}")
112+
if [[ ${QUOTE_SYNTAX_INCLUDES} != "" ]]; then
113+
echo "Please use bracket syntax includes (\"#include <foo.h>\") instead of quote syntax includes:"
114+
echo "${QUOTE_SYNTAX_INCLUDES}"
115+
echo
116+
EXIT_CODE=1
117+
fi
118+
108119
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)