merge bitcoin#24915: Convert lint-circular-dependencies.sh to Python

This commit is contained in:
Kittywhiskers Van Gogh 2022-04-19 00:57:30 +02:00
parent e3dc4b1e27
commit 0321fa053a
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 150 additions and 133 deletions

View File

@ -0,0 +1,150 @@
#!/usr/bin/env python3
#
# Copyright (c) 2020-2022 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 for circular dependencies
import glob
import os
import re
import subprocess
import sys
EXPECTED_CIRCULAR_DEPENDENCIES = (
"chainparamsbase -> util/system -> chainparamsbase",
"node/blockstorage -> validation -> node/blockstorage",
"index/coinstatsindex -> node/coinstats -> index/coinstatsindex",
"policy/fees -> txmempool -> policy/fees",
"qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel",
"qt/recentrequeststablemodel -> qt/walletmodel -> qt/recentrequeststablemodel",
"qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel",
"wallet/fees -> wallet/wallet -> wallet/fees",
"wallet/wallet -> wallet/walletdb -> wallet/wallet",
"node/coinstats -> validation -> node/coinstats",
# Dash
"banman -> common/bloom -> evo/assetlocktx -> llmq/quorums -> net -> banman",
"banman -> common/bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> banman",
"coinjoin/client -> net_processing -> coinjoin/client",
"coinjoin/client -> net_processing -> coinjoin/context -> coinjoin/client",
"coinjoin/coinjoin -> llmq/chainlocks -> net -> coinjoin/coinjoin",
"coinjoin/context -> coinjoin/server -> net_processing -> coinjoin/context",
"coinjoin/server -> net_processing -> coinjoin/server",
"common/bloom -> evo/assetlocktx -> llmq/quorums -> net -> common/bloom",
"common/bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> merkleblock -> common/bloom",
"consensus/tx_verify -> evo/assetlocktx -> validation -> consensus/tx_verify",
"consensus/tx_verify -> evo/assetlocktx -> validation -> txmempool -> consensus/tx_verify",
"core_io -> evo/cbtx -> evo/simplifiedmns -> core_io",
"dsnotificationinterface -> llmq/chainlocks -> node/blockstorage -> dsnotificationinterface",
"evo/assetlocktx -> validation -> txmempool -> evo/assetlocktx",
"evo/cbtx -> evo/simplifiedmns -> evo/cbtx",
"evo/chainhelper -> evo/specialtxman -> validation -> evo/chainhelper",
"evo/deterministicmns -> llmq/commitment -> evo/deterministicmns",
"evo/deterministicmns -> llmq/utils -> evo/deterministicmns",
"evo/deterministicmns -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns -> evo/deterministicmns",
"evo/deterministicmns -> llmq/utils -> net -> evo/deterministicmns",
"evo/deterministicmns -> validation -> evo/deterministicmns",
"evo/deterministicmns -> validation -> txmempool -> evo/deterministicmns",
"evo/deterministicmns -> validationinterface -> evo/deterministicmns",
"evo/deterministicmns -> validationinterface -> governance/vote -> evo/deterministicmns",
"evo/mnhftx -> validation -> evo/mnhftx",
"evo/simplifiedmns -> llmq/blockprocessor -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns",
"evo/specialtxman -> validation -> evo/specialtxman",
"governance/governance -> governance/object -> governance/governance",
"governance/governance -> masternode/sync -> governance/governance",
"governance/governance -> net_processing -> governance/governance",
"governance/governance -> validation -> governance/governance",
"governance/vote -> masternode/node -> validationinterface -> governance/vote",
"llmq/blockprocessor -> llmq/utils -> llmq/snapshot -> llmq/blockprocessor",
"llmq/chainlocks -> llmq/instantsend -> llmq/chainlocks",
"llmq/chainlocks -> llmq/instantsend -> net_processing -> llmq/chainlocks",
"llmq/chainlocks -> validation -> llmq/chainlocks",
"llmq/commitment -> llmq/utils -> llmq/snapshot -> llmq/commitment",
"llmq/context -> llmq/instantsend -> net_processing -> llmq/context",
"llmq/dkgsession -> llmq/dkgsessionmgr -> llmq/dkgsessionhandler -> llmq/dkgsession",
"llmq/dkgsessionhandler -> net_processing -> llmq/dkgsessionmgr -> llmq/dkgsessionhandler",
"llmq/instantsend -> net_processing -> llmq/instantsend",
"llmq/instantsend -> txmempool -> llmq/instantsend",
"llmq/instantsend -> validation -> llmq/instantsend",
"llmq/signing -> llmq/signing_shares -> llmq/signing",
"llmq/signing -> masternode/node -> validationinterface -> llmq/signing",
"llmq/signing -> net_processing -> llmq/signing",
"llmq/signing_shares -> net_processing -> llmq/signing_shares",
"logging -> util/system -> logging",
"logging -> util/system -> stacktraces -> logging",
"logging -> util/system -> sync -> logging",
"logging -> util/system -> sync -> logging/timer -> logging",
"logging -> util/system -> util/getuniquepath -> random -> logging",
"masternode/payments -> validation -> masternode/payments",
"masternode/sync -> validation -> masternode/sync",
"net -> netmessagemaker -> net",
"net_processing -> spork -> net_processing",
"netaddress -> netbase -> netaddress",
"policy/policy -> policy/settings -> policy/policy",
"qt/appearancewidget -> qt/guiutil -> qt/appearancewidget",
"qt/appearancewidget -> qt/guiutil -> qt/optionsdialog -> qt/appearancewidget",
"qt/bitcoinaddressvalidator -> qt/guiutil -> qt/bitcoinaddressvalidator",
"qt/bitcoingui -> qt/guiutil -> qt/bitcoingui",
"qt/guiutil -> qt/optionsdialog -> qt/guiutil",
"qt/guiutil -> qt/optionsdialog -> qt/optionsmodel -> qt/guiutil",
"qt/guiutil -> qt/qvalidatedlineedit -> qt/guiutil",
"rpc/blockchain -> rpc/server -> rpc/blockchain"
)
CODE_DIR = "src"
def main():
circular_dependencies = []
exit_code = 0
os.chdir(
CODE_DIR
) # We change dir before globbing since glob.glob's root_dir option is only available in Python 3.10
# Using glob.glob since subprocess.run's globbing won't work without shell=True
files = []
for path in ["*", "*/*", "*/*/*"]:
for extension in ["h", "cpp"]:
files.extend(glob.glob(f"{path}.{extension}"))
command = ["python3", "../contrib/devtools/circular-dependencies.py", *files]
dependencies_output = subprocess.run(
command,
stdout=subprocess.PIPE,
universal_newlines=True,
)
for dependency_str in dependencies_output.stdout.rstrip().split("\n"):
circular_dependencies.append(
re.sub("^Circular dependency: ", "", dependency_str)
)
# Check for an unexpected dependencies
for dependency in circular_dependencies:
if dependency not in EXPECTED_CIRCULAR_DEPENDENCIES:
exit_code = 1
print(
f'A new circular dependency in the form of "{dependency}" appears to have been introduced.\n',
file=sys.stderr,
)
# Check for missing expected dependencies
for expected_dependency in EXPECTED_CIRCULAR_DEPENDENCIES:
if expected_dependency not in circular_dependencies:
exit_code = 1
print(
f'Good job! The circular dependency "{expected_dependency}" is no longer present.',
)
print(
f"Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in {__file__}",
)
print(
"to make sure this circular dependency is not accidentally reintroduced.\n",
)
sys.exit(exit_code)
if __name__ == "__main__":
main()

View File

@ -1,133 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (c) 2018-2020 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 for circular dependencies
export LC_ALL=C
EXPECTED_CIRCULAR_DEPENDENCIES=(
"chainparamsbase -> util/system -> chainparamsbase"
"node/blockstorage -> validation -> node/blockstorage"
"index/coinstatsindex -> node/coinstats -> index/coinstatsindex"
"policy/fees -> txmempool -> policy/fees"
"qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel"
"qt/recentrequeststablemodel -> qt/walletmodel -> qt/recentrequeststablemodel"
"qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel"
"wallet/fees -> wallet/wallet -> wallet/fees"
"wallet/wallet -> wallet/walletdb -> wallet/wallet"
"node/coinstats -> validation -> node/coinstats"
# Dash
"dsnotificationinterface -> llmq/chainlocks -> node/blockstorage -> dsnotificationinterface"
"evo/cbtx -> evo/simplifiedmns -> evo/cbtx"
"evo/deterministicmns -> llmq/commitment -> evo/deterministicmns"
"evo/deterministicmns -> llmq/utils -> evo/deterministicmns"
"governance/governance -> governance/object -> governance/governance"
"governance/governance -> masternode/sync -> governance/governance"
"llmq/chainlocks -> llmq/instantsend -> llmq/chainlocks"
"llmq/dkgsessionhandler -> net_processing -> llmq/dkgsessionmgr -> llmq/dkgsessionhandler"
"llmq/instantsend -> net_processing -> llmq/instantsend"
"llmq/instantsend -> txmempool -> llmq/instantsend"
"llmq/instantsend -> validation -> llmq/instantsend"
"llmq/signing -> llmq/signing_shares -> llmq/signing"
"llmq/signing -> net_processing -> llmq/signing"
"llmq/signing_shares -> net_processing -> llmq/signing_shares"
"logging -> util/system -> logging"
"masternode/payments -> validation -> masternode/payments"
"masternode/sync -> validation -> masternode/sync"
"net -> netmessagemaker -> net"
"netaddress -> netbase -> netaddress"
"qt/appearancewidget -> qt/guiutil -> qt/appearancewidget"
"qt/bitcoinaddressvalidator -> qt/guiutil -> qt/bitcoinaddressvalidator"
"qt/bitcoingui -> qt/guiutil -> qt/bitcoingui"
"qt/guiutil -> qt/optionsdialog -> qt/guiutil"
"qt/guiutil -> qt/qvalidatedlineedit -> qt/guiutil"
"core_io -> evo/cbtx -> evo/simplifiedmns -> core_io"
"llmq/dkgsession -> llmq/dkgsessionmgr -> llmq/dkgsessionhandler -> llmq/dkgsession"
"logging -> util/system -> sync -> logging"
"logging -> util/system -> stacktraces -> logging"
"logging -> util/system -> util/getuniquepath -> random -> logging"
"qt/appearancewidget -> qt/guiutil -> qt/optionsdialog -> qt/appearancewidget"
"qt/guiutil -> qt/optionsdialog -> qt/optionsmodel -> qt/guiutil"
"common/bloom -> evo/assetlocktx -> llmq/quorums -> net -> common/bloom"
"common/bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> merkleblock -> common/bloom"
"banman -> common/bloom -> evo/assetlocktx -> llmq/quorums -> net -> banman"
"banman -> common/bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> banman"
"llmq/chainlocks -> validation -> llmq/chainlocks"
"coinjoin/coinjoin -> llmq/chainlocks -> net -> coinjoin/coinjoin"
"evo/assetlocktx -> validation -> txmempool -> evo/assetlocktx"
"evo/deterministicmns -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns -> evo/deterministicmns"
"evo/deterministicmns -> llmq/utils -> net -> evo/deterministicmns"
"evo/deterministicmns -> validation -> txmempool -> evo/deterministicmns"
"policy/policy -> policy/settings -> policy/policy"
"consensus/tx_verify -> evo/assetlocktx -> validation -> consensus/tx_verify"
"consensus/tx_verify -> evo/assetlocktx -> validation -> txmempool -> consensus/tx_verify"
"evo/simplifiedmns -> llmq/blockprocessor -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns"
"llmq/blockprocessor -> llmq/utils -> llmq/snapshot -> llmq/blockprocessor"
"llmq/commitment -> llmq/utils -> llmq/snapshot -> llmq/commitment"
"governance/governance -> validation -> governance/governance"
"evo/deterministicmns -> validationinterface -> governance/vote -> evo/deterministicmns"
"governance/vote -> masternode/node -> validationinterface -> governance/vote"
"llmq/signing -> masternode/node -> validationinterface -> llmq/signing"
"evo/mnhftx -> validation -> evo/mnhftx"
"evo/deterministicmns -> validation -> evo/deterministicmns"
"evo/specialtxman -> validation -> evo/specialtxman"
"evo/chainhelper -> evo/specialtxman -> validation -> evo/chainhelper"
"evo/deterministicmns -> validationinterface -> evo/deterministicmns"
"logging -> util/system -> sync -> logging/timer -> logging"
"coinjoin/client -> net_processing -> coinjoin/client"
"coinjoin/client -> net_processing -> coinjoin/context -> coinjoin/client"
"coinjoin/context -> coinjoin/server -> net_processing -> coinjoin/context"
"coinjoin/server -> net_processing -> coinjoin/server"
"llmq/context -> llmq/instantsend -> net_processing -> llmq/context"
"llmq/chainlocks -> llmq/instantsend -> net_processing -> llmq/chainlocks"
"net_processing -> spork -> net_processing"
"governance/governance -> net_processing -> governance/governance"
"rpc/blockchain -> rpc/server -> rpc/blockchain"
)
EXIT_CODE=0
CIRCULAR_DEPENDENCIES=()
IFS=$'\n'
for CIRC in $(cd src && ../contrib/devtools/circular-dependencies.py {*,*/*,*/*/*}.{h,cpp} | sed -e 's/^Circular dependency: //'); do
CIRCULAR_DEPENDENCIES+=( "$CIRC" )
IS_EXPECTED_CIRC=0
for EXPECTED_CIRC in "${EXPECTED_CIRCULAR_DEPENDENCIES[@]}"; do
if [[ "${CIRC}" == "${EXPECTED_CIRC}" ]]; then
IS_EXPECTED_CIRC=1
break
fi
done
if [[ ${IS_EXPECTED_CIRC} == 0 ]]; then
echo "A new circular dependency in the form of \"${CIRC}\" appears to have been introduced."
echo
EXIT_CODE=1
fi
done
for EXPECTED_CIRC in "${EXPECTED_CIRCULAR_DEPENDENCIES[@]}"; do
IS_PRESENT_EXPECTED_CIRC=0
for CIRC in "${CIRCULAR_DEPENDENCIES[@]}"; do
if [[ "${CIRC}" == "${EXPECTED_CIRC}" ]]; then
IS_PRESENT_EXPECTED_CIRC=1
break
fi
done
if [[ ${IS_PRESENT_EXPECTED_CIRC} == 0 ]]; then
echo "Good job! The circular dependency \"${EXPECTED_CIRC}\" is no longer present."
echo "Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in $0"
echo "to make sure this circular dependency is not accidentally reintroduced."
echo
EXIT_CODE=1
fi
done
exit ${EXIT_CODE}