donate-cpu: fixed interrupted `main` branch compilation (#4643)

This commit is contained in:
Oliver Stöneberg 2022-12-18 19:50:22 +01:00 committed by GitHub
parent dc5c5de10e
commit d8451eda5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 9 deletions

View File

@ -184,7 +184,7 @@ while True:
current_cppcheck_dir = os.path.join(work_path, 'tree-'+ver) current_cppcheck_dir = os.path.join(work_path, 'tree-'+ver)
print('Fetching Cppcheck-{}..'.format(ver)) print('Fetching Cppcheck-{}..'.format(ver))
try: try:
hash_changes = lib.try_retry(lib.checkout_cppcheck_version, fargs=(repo_path, ver, current_cppcheck_dir), max_tries=3, sleep_duration=30.0, sleep_factor=1.0) has_changes = lib.try_retry(lib.checkout_cppcheck_version, fargs=(repo_path, ver, current_cppcheck_dir), max_tries=3, sleep_duration=30.0, sleep_factor=1.0)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
# Passthrough for user abort # Passthrough for user abort
raise e raise e
@ -192,7 +192,7 @@ while True:
print('Failed to update Cppcheck ({}), retry later'.format(e)) print('Failed to update Cppcheck ({}), retry later'.format(e))
sys.exit(1) sys.exit(1)
if ver == 'main': if ver == 'main':
if hash_changes and not lib.compile_cppcheck(current_cppcheck_dir): if (has_changes or not lib.has_binary(current_cppcheck_dir)) and not lib.compile_cppcheck(current_cppcheck_dir):
print('Failed to compile Cppcheck-{}, retry later'.format(ver)) print('Failed to compile Cppcheck-{}, retry later'.format(ver))
sys.exit(1) sys.exit(1)
else: else:

View File

@ -15,7 +15,7 @@ import shlex
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes) # changes)
CLIENT_VERSION = "1.3.40" CLIENT_VERSION = "1.3.41"
# Timeout for analysis with Cppcheck in seconds # Timeout for analysis with Cppcheck in seconds
CPPCHECK_TIMEOUT = 30 * 60 CPPCHECK_TIMEOUT = 30 * 60
@ -157,14 +157,29 @@ def get_cppcheck_info(cppcheck_path):
return '' return ''
def compile_version(cppcheck_path): def __get_cppcheck_binary(cppcheck_path):
if __make_cmd == "msbuild.exe": if __make_cmd == "msbuild.exe":
if os.path.isfile(os.path.join(cppcheck_path, 'bin', 'cppcheck.exe')): return os.path.join(cppcheck_path, 'bin', 'cppcheck.exe')
if __make_cmd == 'mingw32-make':
return os.path.join(cppcheck_path, 'cppcheck.exe')
return os.path.join(cppcheck_path, 'cppcheck')
def has_binary(cppcheck_path):
cppcheck_bin = __get_cppcheck_binary(cppcheck_path)
if __make_cmd == "msbuild.exe":
if os.path.isfile(cppcheck_bin):
return True return True
elif __make_cmd == 'mingw32-make': elif __make_cmd == 'mingw32-make':
if os.path.isfile(os.path.join(cppcheck_path, 'cppcheck.exe')): if os.path.isfile(cppcheck_bin):
return True return True
elif os.path.isfile(os.path.join(cppcheck_path, 'cppcheck')): elif os.path.isfile(cppcheck_bin):
return True
return False
def compile_version(cppcheck_path):
if has_binary(cppcheck_path):
return True return True
# Build # Build
ret = compile_cppcheck(cppcheck_path) ret = compile_cppcheck(cppcheck_path)
@ -175,13 +190,19 @@ def compile_version(cppcheck_path):
exclude_bin = 'cppcheck.exe' exclude_bin = 'cppcheck.exe'
else: else:
exclude_bin = 'cppcheck' exclude_bin = 'cppcheck'
# TODO: how to support multiple compiler on the same machine? this will clean msbuild.exe files in a mingw32-make build and vice versa # TODO: how to support multiple compilers on the same machine? this will clean msbuild.exe files in a mingw32-make build and vice versa
subprocess.call(['git', 'clean', '-f', '-d', '-x', '--exclude', exclude_bin], cwd=cppcheck_path) subprocess.call(['git', 'clean', '-f', '-d', '-x', '--exclude', exclude_bin], cwd=cppcheck_path)
return ret return ret
def compile_cppcheck(cppcheck_path): def compile_cppcheck(cppcheck_path):
print('Compiling {}'.format(os.path.basename(cppcheck_path))) print('Compiling {}'.format(os.path.basename(cppcheck_path)))
cppcheck_bin = __get_cppcheck_binary(cppcheck_path)
# remove file so interrupted "main" branch compilation is being resumed
if os.path.isfile(cppcheck_bin):
os.remove(cppcheck_bin)
try: try:
if __make_cmd == 'msbuild.exe': if __make_cmd == 'msbuild.exe':
subprocess.check_call(['python3', os.path.join('tools', 'matchcompiler.py'), '--write-dir', 'lib'], cwd=cppcheck_path) subprocess.check_call(['python3', os.path.join('tools', 'matchcompiler.py'), '--write-dir', 'lib'], cwd=cppcheck_path)
@ -211,7 +232,9 @@ def compile_cppcheck(cppcheck_path):
subprocess.check_call([os.path.join(cppcheck_path, 'cppcheck'), '--version'], cwd=cppcheck_path) subprocess.check_call([os.path.join(cppcheck_path, 'cppcheck'), '--version'], cwd=cppcheck_path)
except Exception as e: except Exception as e:
print('Running Cppcheck failed: {}'.format(e)) print('Running Cppcheck failed: {}'.format(e))
# TODO: remove binary # remove faulty binary
if os.path.isfile(cppcheck_bin):
os.remove(cppcheck_bin)
return False return False
return True return True