Skip to content

Commit d8451ed

Browse files
authored
donate-cpu: fixed interrupted main branch compilation (cppcheck-opensource#4643)
1 parent dc5c5de commit d8451ed

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

tools/donate-cpu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@
184184
current_cppcheck_dir = os.path.join(work_path, 'tree-'+ver)
185185
print('Fetching Cppcheck-{}..'.format(ver))
186186
try:
187-
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)
187+
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)
188188
except KeyboardInterrupt as e:
189189
# Passthrough for user abort
190190
raise e
191191
except Exception as e:
192192
print('Failed to update Cppcheck ({}), retry later'.format(e))
193193
sys.exit(1)
194194
if ver == 'main':
195-
if hash_changes and not lib.compile_cppcheck(current_cppcheck_dir):
195+
if (has_changes or not lib.has_binary(current_cppcheck_dir)) and not lib.compile_cppcheck(current_cppcheck_dir):
196196
print('Failed to compile Cppcheck-{}, retry later'.format(ver))
197197
sys.exit(1)
198198
else:

tools/donate_cpu_lib.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
1616
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
1717
# changes)
18-
CLIENT_VERSION = "1.3.40"
18+
CLIENT_VERSION = "1.3.41"
1919

2020
# Timeout for analysis with Cppcheck in seconds
2121
CPPCHECK_TIMEOUT = 30 * 60
@@ -157,14 +157,29 @@ def get_cppcheck_info(cppcheck_path):
157157
return ''
158158

159159

160-
def compile_version(cppcheck_path):
160+
def __get_cppcheck_binary(cppcheck_path):
161161
if __make_cmd == "msbuild.exe":
162-
if os.path.isfile(os.path.join(cppcheck_path, 'bin', 'cppcheck.exe')):
162+
return os.path.join(cppcheck_path, 'bin', 'cppcheck.exe')
163+
if __make_cmd == 'mingw32-make':
164+
return os.path.join(cppcheck_path, 'cppcheck.exe')
165+
return os.path.join(cppcheck_path, 'cppcheck')
166+
167+
168+
def has_binary(cppcheck_path):
169+
cppcheck_bin = __get_cppcheck_binary(cppcheck_path)
170+
if __make_cmd == "msbuild.exe":
171+
if os.path.isfile(cppcheck_bin):
163172
return True
164173
elif __make_cmd == 'mingw32-make':
165-
if os.path.isfile(os.path.join(cppcheck_path, 'cppcheck.exe')):
174+
if os.path.isfile(cppcheck_bin):
166175
return True
167-
elif os.path.isfile(os.path.join(cppcheck_path, 'cppcheck')):
176+
elif os.path.isfile(cppcheck_bin):
177+
return True
178+
return False
179+
180+
181+
def compile_version(cppcheck_path):
182+
if has_binary(cppcheck_path):
168183
return True
169184
# Build
170185
ret = compile_cppcheck(cppcheck_path)
@@ -175,13 +190,19 @@ def compile_version(cppcheck_path):
175190
exclude_bin = 'cppcheck.exe'
176191
else:
177192
exclude_bin = 'cppcheck'
178-
# TODO: how to support multiple compiler on the same machine? this will clean msbuild.exe files in a mingw32-make build and vice versa
193+
# TODO: how to support multiple compilers on the same machine? this will clean msbuild.exe files in a mingw32-make build and vice versa
179194
subprocess.call(['git', 'clean', '-f', '-d', '-x', '--exclude', exclude_bin], cwd=cppcheck_path)
180195
return ret
181196

182197

183198
def compile_cppcheck(cppcheck_path):
184199
print('Compiling {}'.format(os.path.basename(cppcheck_path)))
200+
201+
cppcheck_bin = __get_cppcheck_binary(cppcheck_path)
202+
# remove file so interrupted "main" branch compilation is being resumed
203+
if os.path.isfile(cppcheck_bin):
204+
os.remove(cppcheck_bin)
205+
185206
try:
186207
if __make_cmd == 'msbuild.exe':
187208
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):
211232
subprocess.check_call([os.path.join(cppcheck_path, 'cppcheck'), '--version'], cwd=cppcheck_path)
212233
except Exception as e:
213234
print('Running Cppcheck failed: {}'.format(e))
214-
# TODO: remove binary
235+
# remove faulty binary
236+
if os.path.isfile(cppcheck_bin):
237+
os.remove(cppcheck_bin)
215238
return False
216239

217240
return True

0 commit comments

Comments
 (0)