merge bitcoin#24982: Port lint-all.sh to lint-all.py

This commit is contained in:
Kittywhiskers Van Gogh 2024-11-25 14:55:24 +00:00
parent b054a0d894
commit bda1e03b24
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
6 changed files with 40 additions and 50 deletions

View File

@ -25,7 +25,7 @@ if [ "$CHECK_DOC" = 1 ]; then
# TODO: Check docs (re-enable after all Bitcoin PRs have been merged and docs fully fixed) # TODO: Check docs (re-enable after all Bitcoin PRs have been merged and docs fully fixed)
#test/lint/check-doc.py #test/lint/check-doc.py
# Run all linters # Run all linters
test/lint/lint-all.sh test/lint/lint-all.py
fi fi
ccache --zero-stats --max-size=$CCACHE_SIZE ccache --zero-stats --max-size=$CCACHE_SIZE

View File

@ -21,7 +21,7 @@ test/lint/git-subtree-check.sh src/minisketch
test/lint/git-subtree-check.sh src/univalue test/lint/git-subtree-check.sh src/univalue
test/lint/git-subtree-check.sh src/leveldb test/lint/git-subtree-check.sh src/leveldb
test/lint/check-doc.py test/lint/check-doc.py
test/lint/lint-all.sh test/lint/lint-all.py
if [ "$CIRRUS_REPO_FULL_NAME" = "dashpay/dash" ] && [ -n "$CIRRUS_CRON" ]; then if [ "$CIRRUS_REPO_FULL_NAME" = "dashpay/dash" ] && [ -n "$CIRRUS_CRON" ]; then
git log --merges --before="2 days ago" -1 --format='%H' > ./contrib/verify-commits/trusted-sha512-root-commit git log --merges --before="2 days ago" -1 --format='%H' > ./contrib/verify-commits/trusted-sha512-root-commit

View File

@ -332,7 +332,7 @@ test/lint/lint-files.py
You can run all the shell-based lint tests by running: You can run all the shell-based lint tests by running:
``` ```
test/lint/lint-all.sh test/lint/lint-all.py
``` ```
# Writing functional tests # Writing functional tests

View File

@ -39,6 +39,6 @@ To do so, add the upstream repository as remote:
git remote add --fetch secp256k1 https://github.com/bitcoin-core/secp256k1.git git remote add --fetch secp256k1 https://github.com/bitcoin-core/secp256k1.git
``` ```
lint-all.sh lint-all.py
=========== ===========
Calls other scripts with the `lint-` prefix. Calls other scripts with the `lint-` prefix.

36
test/lint/lint-all.py Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env python3
#
# Copyright (c) 2017-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.
#
# This script runs all test/lint/lint-* files, and fails if any exit
# with a non-zero status code.
from glob import glob
from os import path as os_path, remove
from pathlib import Path
from shutil import which
from subprocess import run
exit_code = 0
mod_path = Path(__file__).parent
lints = [x for x in glob(f"{mod_path}/lint-*") if x != __file__]
if which("parallel") and which("column"):
logfile = "parallel_out.log"
command = ["parallel", "--jobs", "100%", "--will-cite", "--joblog", logfile, ":::"] + lints
result = run(command)
if result.returncode != 0:
print(f"^---- failure generated")
exit_code = result.returncode
result = run(["column", "-t", logfile])
if os_path.isfile(logfile):
remove(logfile)
else:
for lint in lints:
result = run([lint])
if result.returncode != 0:
print(f"^---- failure generated from {lint.split('/')[-1]}")
exit_code |= result.returncode
exit(exit_code)

View File

@ -1,46 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (c) 2017-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# This script runs all contrib/devtools/lint-* files, and fails if any exit
# with a non-zero status code.
# This script is intentionally locale dependent by not setting "export LC_ALL=C"
# in order to allow for the executed lint scripts to opt in or opt out of locale
# dependence themselves.
set -u
SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}")
LINTALL=$(basename "${BASH_SOURCE[0]}")
EXIT_CODE=0
if ! command -v parallel > /dev/null; then
for f in "${SCRIPTDIR}"/lint-*; do
if [ "$(basename "$f")" != "$LINTALL" ]; then
if ! "$f"; then
echo "^---- failure generated from $f"
EXIT_CODE=1
fi
fi
done
else
SCRIPTS=()
for f in "${SCRIPTDIR}"/lint-*; do
if [ "$(basename "$f")" != "$LINTALL" ]; then
SCRIPTS+=("$f")
fi
done
if ! parallel --jobs 100% --will-cite --joblog parallel_out.log ::: "${SCRIPTS[@]}"; then
echo "^---- failure generated"
EXIT_CODE=1
fi
column -t parallel_out.log && rm parallel_out.log
fi
exit ${EXIT_CODE}