Skip to content

Commit 7e2fbcf

Browse files
committed
fixed #11663 (daca: fetch basic analysis flags from server) [skip ci]
1 parent 91070ca commit 7e2fbcf

3 files changed

Lines changed: 94 additions & 16 deletions

File tree

tools/donate-cpu-server.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
2727
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
2828
# changes)
29-
SERVER_VERSION = "1.3.42"
29+
SERVER_VERSION = "1.3.43"
3030

3131
OLD_VERSION = '2.11'
3232

@@ -1235,10 +1235,68 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
12351235
newThread = HttpClientThread(connection, cmd, resultPath, latestResults)
12361236
newThread.start()
12371237
elif cmd == 'GetCppcheckVersions\n':
1238+
# TODO: deprecate
12381239
reply = 'head ' + OLD_VERSION
12391240
print_ts('GetCppcheckVersions: ' + reply)
12401241
connection.send(reply.encode('utf-8', 'ignore'))
12411242
connection.close()
1243+
elif cmd == 'GetCppcheckData\n':
1244+
data = read_data(connection, cmd, pos_nl, max_data_size=8 * 1024, check_done=False, cmd_name='write_nodata')
1245+
if data is None:
1246+
continue
1247+
1248+
reply_obj = {
1249+
'v': 1, # version of the response object
1250+
'err': None, # provide an error to show within the client
1251+
'note': None # provide a note to show within the client
1252+
}
1253+
1254+
# TODO
1255+
try:
1256+
from packaging.version import Version
1257+
Version(data)
1258+
except Exception as e:
1259+
reply_obj.err = 'invalid client version: {}'.format(e)
1260+
pass
1261+
1262+
if reply_obj.err is None:
1263+
cppcheck_opts = [
1264+
'--enable=style,information',
1265+
'--inconclusive',
1266+
'--template=daca2',
1267+
'--showtime=top5',
1268+
'--check-library',
1269+
'--platform=unix64',
1270+
# suppressions
1271+
'--inline-suppr',
1272+
'--suppress=unmatchedSuppression',
1273+
# user provided defines
1274+
'-D__GNUC__',
1275+
# debug warnings and suppressions
1276+
'--debug-warnings',
1277+
'--suppress=autoNoType',
1278+
'--suppress=bailoutUninitVar',
1279+
'--suppress=symbolDatabaseWarning',
1280+
'--suppress=valueFlowBailout',
1281+
# TODO: remove missingInclude disabling when it no longer is implied by --enable=information
1282+
'--disable=missingInclude'
1283+
]
1284+
1285+
reply_data = {
1286+
'versions': ['head', OLD_VERSION], # the versions to check with
1287+
'build_opts': { # the build flags
1288+
'make': ['MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w'],
1289+
'mingw32-make': ['MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w'],
1290+
'msbuild.exe': ['/property:Configuration=Release;Platform=x64']
1291+
},
1292+
'cppcheck_opts': ' '.join(cppcheck_opts) # the check options
1293+
}
1294+
reply_obj.update(reply_data)
1295+
1296+
reply = json.dumps(reply_obj)
1297+
print_ts('GetCppcheckData: ' + reply)
1298+
connection.send(reply.encode('utf-8', 'ignore'))
1299+
connection.close()
12421300
elif cmd == 'get\n':
12431301
while True:
12441302
pkg = packages[packageIndex]

tools/donate-cpu.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
print('Stopping. Thank you!')
175175
sys.exit(0)
176176
try:
177-
cppcheck_versions = lib.try_retry(lib.get_cppcheck_versions, max_tries=3, sleep_duration=30.0, sleep_factor=1.0)
177+
cppcheck_versions, build_opts, cppcheck_opts = lib.try_retry(lib.get_cppcheck_options, max_tries=3, sleep_duration=30.0, sleep_factor=1.0)
178178
except Exception as e:
179179
print('Failed to get cppcheck versions from server ({}), retry later'.format(e))
180180
sys.exit(1)
@@ -192,11 +192,11 @@
192192
print('Failed to update Cppcheck ({}), retry later'.format(e))
193193
sys.exit(1)
194194
if ver == 'main':
195-
if (has_changes or not lib.has_binary(current_cppcheck_dir)) 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, build_opts):
196196
print('Failed to compile Cppcheck-{}, retry later'.format(ver))
197197
sys.exit(1)
198198
else:
199-
if not lib.compile_version(current_cppcheck_dir):
199+
if not lib.compile_version(current_cppcheck_dir, build_opts):
200200
print('Failed to compile Cppcheck-{}, retry later'.format(ver))
201201
sys.exit(1)
202202
if package_urls:
@@ -254,7 +254,7 @@ def get_client_version_head():
254254
return None
255255

256256
client_version_head = get_client_version_head()
257-
c, errout, info, t, cppcheck_options, timing_info = lib.scan_package(tree_path, source_path, libraries, capture_callstack)
257+
c, errout, info, t, cppcheck_options, timing_info = lib.scan_package(tree_path, source_path, libraries, cppcheck_opts, capture_callstack)
258258
if c < 0:
259259
if c == -101 and 'error: could not find or open any of the paths given.' in errout:
260260
# No sourcefile found (for example only headers present)

tools/donate_cpu_lib.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
1717
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
1818
# changes)
19-
CLIENT_VERSION = "1.3.48"
19+
CLIENT_VERSION = "1.3.49"
2020

2121
# Timeout for analysis with Cppcheck in seconds
2222
CPPCHECK_TIMEOUT = 30 * 60
@@ -179,11 +179,11 @@ def has_binary(cppcheck_path):
179179
return False
180180

181181

182-
def compile_version(cppcheck_path):
182+
def compile_version(cppcheck_path, build_opts):
183183
if has_binary(cppcheck_path):
184184
return True
185185
# Build
186-
ret = compile_cppcheck(cppcheck_path)
186+
ret = compile_cppcheck(cppcheck_path, build_opts)
187187
# Clean intermediate build files
188188
if __make_cmd == "msbuild.exe":
189189
exclude_bin = 'bin'
@@ -196,7 +196,7 @@ def compile_version(cppcheck_path):
196196
return ret
197197

198198

199-
def compile_cppcheck(cppcheck_path):
199+
def compile_cppcheck(cppcheck_path, build_opts):
200200
print('Compiling {}'.format(os.path.basename(cppcheck_path)))
201201

202202
cppcheck_bin = __get_cppcheck_binary(cppcheck_path)
@@ -211,9 +211,10 @@ def compile_cppcheck(cppcheck_path):
211211
# append to cl.exe options - need to omit dash or slash since a dash is being prepended
212212
build_env["_CL_"] = __jobs.replace('j', 'MP', 1)
213213
# TODO: processes still exhaust all threads of the system
214-
subprocess.check_call([__make_cmd, '-t:cli', os.path.join(cppcheck_path, 'cppcheck.sln'), '/property:Configuration=Release;Platform=x64'], cwd=cppcheck_path, env=build_env)
214+
build_cmd = [__make_cmd, '-t:cli', os.path.join(cppcheck_path, 'cppcheck.sln'), build_opts[__make_cmd]]
215+
subprocess.check_call(build_cmd, cwd=cppcheck_path, env=build_env)
215216
else:
216-
build_cmd = [__make_cmd, __jobs, 'MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w']
217+
build_cmd = [__make_cmd, __jobs, 'MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w', build_opts[__make_cmd]]
217218
build_env = os.environ
218219
if __make_cmd == 'mingw32-make':
219220
# TODO: MinGW will always link even if no changes are present
@@ -241,6 +242,7 @@ def compile_cppcheck(cppcheck_path):
241242
return True
242243

243244

245+
# TODO: deprecate
244246
def get_cppcheck_versions():
245247
print('Connecting to server to get Cppcheck versions..')
246248
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
@@ -253,6 +255,27 @@ def get_cppcheck_versions():
253255
return versions.decode('utf-8').split()
254256

255257

258+
def get_cppcheck_options():
259+
print('Connecting to server to get Cppcheck options..')
260+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
261+
sock.connect(__server_address)
262+
sock.send(b'GetCppcheckData\n') # TODO: send version
263+
options = sock.recv(1024) # TODO: increase
264+
# TODO: sock.recv() sometimes hangs and returns b'' afterwards
265+
if not options:
266+
raise Exception('received empty response')
267+
import json
268+
options_obj = json.loads(options.decode('utf-8'))
269+
if not options_obj.v or options_obj.v != 1:
270+
raise Exception("received invalid version '{}'".format(options_obj.v))
271+
# v1
272+
if options_obj.err is not None:
273+
raise Exception('server provided error: {}'.format(options_obj.err))
274+
if options_obj.note is not None:
275+
print('server provided notice: {}'.format(options_obj.note))
276+
return options_obj.versions, options_obj.build_opts, options_obj.cppcheck_opts
277+
278+
256279
def get_packages_count():
257280
def __get_packages_count():
258281
print('Connecting to server to get count of packages..')
@@ -431,7 +454,7 @@ def __run_command(cmd, print_cmd=True):
431454
return return_code, stdout, stderr, elapsed_time
432455

433456

434-
def scan_package(cppcheck_path, source_path, libraries, capture_callstack=True):
457+
def scan_package(cppcheck_path, source_path, libraries, cppcheck_opts, capture_callstack=True):
435458
print('Analyze..')
436459
libs = ''
437460
for library in libraries:
@@ -440,11 +463,8 @@ def scan_package(cppcheck_path, source_path, libraries, capture_callstack=True):
440463

441464
dir_to_scan = source_path
442465

443-
# TODO: remove missingInclude disabling when it no longer is implied by --enable=information
444466
# Reference for GNU C: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
445-
options = libs + ' --showtime=top5 --check-library --inconclusive --enable=style,information --inline-suppr --disable=missingInclude --suppress=unmatchedSuppression --template=daca2'
446-
options += ' --debug-warnings --suppress=autoNoType --suppress=valueFlowBailout --suppress=bailoutUninitVar --suppress=symbolDatabaseWarning'
447-
options += ' -D__GNUC__ --platform=unix64'
467+
options = libs + cppcheck_opts
448468
options_rp = options + ' -rp={}'.format(dir_to_scan)
449469
if __make_cmd == 'msbuild.exe':
450470
cppcheck_cmd = os.path.join(cppcheck_path, 'bin', 'cppcheck.exe') + ' ' + options_rp

0 commit comments

Comments
 (0)