Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions contrib/devtools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,14 @@ It will do the following automatically:
- add missing translations to the build system (TODO)

See doc/translation-process.md for more information.

circular-dependencies.py
========================

Run this script from the root of the source tree (`src/`) to find circular dependencies in the source code.
This looks only at which files include other files, treating the `.cpp` and `.h` file as one unit.

Example usage:

cd .../src
../contrib/devtools/circular-dependencies.py {*,*/*,*/*/*}.{h,cpp}
79 changes: 79 additions & 0 deletions contrib/devtools/circular-dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3

import sys
import re

MAPPING = {
'core_read.cpp': 'core_io.cpp',
'core_write.cpp': 'core_io.cpp',
}

def module_name(path):
if path in MAPPING:
path = MAPPING[path]
if path.endswith(".h"):
return path[:-2]
if path.endswith(".c"):
return path[:-2]
if path.endswith(".cpp"):
return path[:-4]
return None

files = dict()
deps = dict()

RE = re.compile("^#include <(.*)>")

# Iterate over files, and create list of modules
for arg in sys.argv[1:]:
module = module_name(arg)
if module is None:
print("Ignoring file %s (does not constitute module)\n" % arg)
else:
files[arg] = module
deps[module] = set()

# Iterate again, and build list of direct dependencies for each module
# TODO: implement support for multiple include directories
for arg in sorted(files.keys()):
module = files[arg]
with open(arg, 'r') as f:
for line in f:
match = RE.match(line)
if match:
include = match.group(1)
included_module = module_name(include)
if included_module is not None and included_module in deps and included_module != module:
deps[module].add(included_module)

# Loop to find the shortest (remaining) circular dependency
have_cycle = False
while True:
shortest_cycle = None
for module in sorted(deps.keys()):
# Build the transitive closure of dependencies of module
closure = dict()
for dep in deps[module]:
closure[dep] = []
while True:
old_size = len(closure)
old_closure_keys = sorted(closure.keys())
for src in old_closure_keys:
for dep in deps[src]:
if dep not in closure:
closure[dep] = closure[src] + [src]
if len(closure) == old_size:
break
# If module is in its own transitive closure, it's a circular dependency; check if it is the shortest
if module in closure and (shortest_cycle is None or len(closure[module]) + 1 < len(shortest_cycle)):
shortest_cycle = [module] + closure[module]
if shortest_cycle is None:
break
# We have the shortest circular dependency; report it
module = shortest_cycle[0]
print("Circular dependency: %s" % (" -> ".join(shortest_cycle + [module])))
# And then break the dependency to avoid repeating in other cycles
deps[shortest_cycle[-1]] = deps[shortest_cycle[-1]] - set([module])
have_cycle = True

sys.exit(1 if have_cycle else 0)
29 changes: 29 additions & 0 deletions contrib/devtools/lint-include-guards.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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 include guards.

HEADER_ID_PREFIX="BITCOIN_"
HEADER_ID_SUFFIX="_H"

REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/|ctpl.h|bls/|crypto/sph)"

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:]" | tr - _)
HEADER_ID="${HEADER_ID_PREFIX}${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
fi
done
exit ${EXIT_CODE}
10 changes: 10 additions & 0 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,16 @@ namespace {
source file into account. This allows quoted includes to stand out more when
the location of the source file actually is relevant.

- 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.

```c++
#ifndef BITCOIN_FOO_BAR_H
#define BITCOIN_FOO_BAR_H
...
#endif // BITCOIN_FOO_BAR_H
```

GUI
-----

Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ BITCOIN_CORE_H = \
llmq/quorums_signing.h \
llmq/quorums_signing_shares.h \
llmq/quorums_utils.h \
logging.h \
masternode/activemasternode.h \
masternode/masternode-meta.h \
masternode/masternode-payments.h \
Expand Down Expand Up @@ -544,6 +545,7 @@ libdash_util_a_SOURCES = \
compat/glibcxx_sanity.cpp \
compat/strnlen.cpp \
fs.cpp \
logging.cpp \
random.cpp \
rpc/protocol.cpp \
stacktraces.cpp \
Expand Down
6 changes: 3 additions & 3 deletions src/batchedlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef DASH_BATCHEDLOGGER_H
#define DASH_BATCHEDLOGGER_H
#ifndef BITCOIN_BATCHEDLOGGER_H
#define BITCOIN_BATCHEDLOGGER_H

#include <tinyformat.h>

Expand All @@ -29,4 +29,4 @@ class CBatchedLogger
void Flush();
};

#endif//DASH_BATCHEDLOGGER_H
#endif//BITCOIN_BATCHEDLOGGER_H
6 changes: 3 additions & 3 deletions src/bench/perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

/** Functions for measurement of CPU cycles */
#ifndef H_PERF
#define H_PERF
#ifndef BITCOIN_BENCH_PERF_H
#define BITCOIN_BENCH_PERF_H

#include <stdint.h>

Expand Down Expand Up @@ -34,4 +34,4 @@ uint64_t perf_cpucycles(void);
void perf_init(void);
void perf_fini(void);

#endif // H_PERF
#endif // BITCOIN_BENCH_PERF_H
6 changes: 3 additions & 3 deletions src/bip39.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef DASH_BIP39_H
#define DASH_BIP39_H
#ifndef BITCOIN_BIP39_H
#define BITCOIN_BIP39_H

#include <support/allocators/secure.h>

Expand All @@ -36,4 +36,4 @@ class CMnemonic
static void ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet);
};

#endif
#endif // BITCOIN_BIP39_H
5 changes: 5 additions & 0 deletions src/bip39_english.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef BITCOIN_BIP39_ENGLISH_H
#define BITCOIN_BIP39_ENGLISH_H

const char * const wordlist[] = {
"abandon",
"ability",
Expand Down Expand Up @@ -2072,3 +2075,5 @@ const char * const wordlist[] = {
"zoo",
0,
};

#endif // BITCOIN_BIP39_ENGLISH_H
6 changes: 3 additions & 3 deletions src/blockencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_BLOCK_ENCODINGS_H
#define BITCOIN_BLOCK_ENCODINGS_H
#ifndef BITCOIN_BLOCKENCODINGS_H
#define BITCOIN_BLOCKENCODINGS_H

#include <primitives/block.h>

Expand Down Expand Up @@ -209,4 +209,4 @@ class PartiallyDownloadedBlock {
ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing);
};

#endif
#endif // BITCOIN_BLOCKENCODINGS_H
6 changes: 3 additions & 3 deletions src/cachemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef CACHEMAP_H_
#define CACHEMAP_H_
#ifndef BITCOIN_CACHEMAP_H
#define BITCOIN_CACHEMAP_H

#include <map>
#include <list>
Expand Down Expand Up @@ -186,4 +186,4 @@ class CacheMap
}
};

#endif /* CACHEMAP_H_ */
#endif // BITCOIN_CACHEMAP_H
6 changes: 3 additions & 3 deletions src/cachemultimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef CACHEMULTIMAP_H_
#define CACHEMULTIMAP_H_
#ifndef BITCOIN_CACHEMULTIMAP_H
#define BITCOIN_CACHEMULTIMAP_H

#include <cstddef>
#include <map>
Expand Down Expand Up @@ -245,4 +245,4 @@ class CacheMultiMap
}
};

#endif /* CACHEMULTIMAP_H_ */
#endif // BITCOIN_CACHEMULTIMAP_H
6 changes: 3 additions & 3 deletions src/chainparamsseeds.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DASH_CHAINPARAMSSEEDS_H
#define DASH_CHAINPARAMSSEEDS_H
#ifndef BITCOIN_CHAINPARAMSSEEDS_H
#define BITCOIN_CHAINPARAMSSEEDS_H
/**
* List of fixed seed nodes for the dash network
* AUTOGENERATED by contrib/seeds/generate-seeds.py
Expand Down Expand Up @@ -283,4 +283,4 @@ static SeedSpec6 pnSeed6_test[] = {
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb9,0xd5,0x25,0x01}, 19999},
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb9,0xd5,0x25,0x02}, 19999}
};
#endif // DASH_CHAINPARAMSSEEDS_H
#endif // BITCOIN_CHAINPARAMSSEEDS_H
6 changes: 3 additions & 3 deletions src/consensus/merkle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_MERKLE
#define BITCOIN_MERKLE
#ifndef BITCOIN_CONSENSUS_MERKLE_H
#define BITCOIN_CONSENSUS_MERKLE_H

#include <stdint.h>
#include <vector>
Expand All @@ -20,4 +20,4 @@ uint256 ComputeMerkleRoot(std::vector<uint256> hashes, bool* mutated = nullptr);
*/
uint256 BlockMerkleRoot(const CBlock& block, bool* mutated = nullptr);

#endif
#endif // BITCOIN_CONSENSUS_MERKLE_H
6 changes: 3 additions & 3 deletions src/evo/cbtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef DASH_CBTX_H
#define DASH_CBTX_H
#ifndef BITCOIN_EVO_CBTX_H
#define BITCOIN_EVO_CBTX_H

#include <consensus/validation.h>
#include <primitives/transaction.h>
Expand Down Expand Up @@ -60,4 +60,4 @@ bool CheckCbTxMerkleRoots(const CBlock& block, const CBlockIndex* pindex, CValid
bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, CValidationState& state);
bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, CValidationState& state);

#endif //DASH_CBTX_H
#endif // BITCOIN_EVO_CBTX_H
6 changes: 3 additions & 3 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef DASH_DETERMINISTICMNS_H
#define DASH_DETERMINISTICMNS_H
#ifndef BITCOIN_EVO_DETERMINISTICMNS_H
#define BITCOIN_EVO_DETERMINISTICMNS_H

#include <arith_uint256.h>
#include <bls/bls.h>
Expand Down Expand Up @@ -682,4 +682,4 @@ class CDeterministicMNManager

extern std::unique_ptr<CDeterministicMNManager> deterministicMNManager;

#endif //DASH_DETERMINISTICMNS_H
#endif // BITCOIN_EVO_DETERMINISTICMNS_H
6 changes: 3 additions & 3 deletions src/evo/evodb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef DASH_EVODB_H
#define DASH_EVODB_H
#ifndef BITCOIN_EVO_EVODB_H
#define BITCOIN_EVO_EVODB_H

#include <dbwrapper.h>
#include <sync.h>
Expand Down Expand Up @@ -110,4 +110,4 @@ class CEvoDB

extern std::unique_ptr<CEvoDB> evoDb;

#endif //DASH_EVODB_H
#endif // BITCOIN_EVO_EVODB_H
6 changes: 3 additions & 3 deletions src/evo/mnauth.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef DASH_MNAUTH_H
#define DASH_MNAUTH_H
#ifndef BITCOIN_EVO_MNAUTH_H
#define BITCOIN_EVO_MNAUTH_H

#include <bls/bls.h>
#include <serialize.h>
Expand Down Expand Up @@ -55,4 +55,4 @@ class CMNAuth
};


#endif //DASH_MNAUTH_H
#endif // BITCOIN_EVO_MNAUTH_H
6 changes: 3 additions & 3 deletions src/evo/providertx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef DASH_PROVIDERTX_H
#define DASH_PROVIDERTX_H
#ifndef BITCOIN_EVO_PROVIDERTX_H
#define BITCOIN_EVO_PROVIDERTX_H

#include <bls/bls.h>
#include <consensus/validation.h>
Expand Down Expand Up @@ -240,4 +240,4 @@ bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CVa
bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);
bool CheckProUpRevTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);

#endif //DASH_PROVIDERTX_H
#endif // BITCOIN_EVO_PROVIDERTX_H
Loading