Skip to content

Commit ae52db9

Browse files
committed
fixed #11663 (daca: fetch basic analysis flags from server) [skip ci]
1 parent 7393083 commit ae52db9

3 files changed

Lines changed: 95 additions & 20 deletions

File tree

tools/donate-cpu-server.py

Lines changed: 60 additions & 4 deletions
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.46"
29+
SERVER_VERSION = "1.4.0"
3030

3131
OLD_VERSION = '2.12.0'
3232

@@ -1281,9 +1281,65 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
12811281
if cmd.startswith('GET /'):
12821282
newThread = HttpClientThread(connection, cmd, resultPath, latestResults)
12831283
newThread.start()
1284-
elif cmd == 'GetCppcheckVersions\n':
1285-
reply = 'head ' + OLD_VERSION
1286-
print_ts('GetCppcheckVersions: ' + reply)
1284+
elif cmd == 'GetCppcheckData\n':
1285+
data = read_data(connection, cmd, pos_nl, max_data_size=8 * 1024, check_done=False, cmd_name='write_nodata')
1286+
if data is None:
1287+
continue
1288+
1289+
# TODO: move all fields here so are they properly documented in one place
1290+
# TODO: add server version?
1291+
reply_obj = {
1292+
'v': 1, # version of the response object
1293+
'err': None, # provide an error to show within the client
1294+
'note': None # provide a note to show within the client
1295+
}
1296+
1297+
# TODO
1298+
try:
1299+
from packaging.version import Version
1300+
Version(data)
1301+
except Exception as e:
1302+
reply_obj.err = 'invalid client version: {}'.format(e)
1303+
pass
1304+
1305+
if reply_obj.err is None:
1306+
# TODO: read/extend this from a configuration file
1307+
cppcheck_opts = [
1308+
'--enable=style,information',
1309+
'--inconclusive',
1310+
'--template=daca2',
1311+
# TODO: temporarily disabled timing information - use --showtime=top5_summary when next version is released
1312+
# '--showtime=top5',
1313+
'--check-library',
1314+
'--platform=unix64',
1315+
# suppressions
1316+
'--inline-suppr',
1317+
'--suppress=unmatchedSuppression',
1318+
# user provided defines
1319+
'-D__GNUC__',
1320+
# debug warnings and suppressions
1321+
'--debug-warnings',
1322+
'--suppress=autoNoType',
1323+
'--suppress=bailoutUninitVar',
1324+
'--suppress=symbolDatabaseWarning',
1325+
'--suppress=valueFlowBailout',
1326+
# TODO: remove missingInclude disabling when it no longer is implied by --enable=information
1327+
'--disable=missingInclude'
1328+
]
1329+
1330+
reply_data = {
1331+
'versions': ['head', OLD_VERSION], # the versions to check with
1332+
'build_opts': { # the build flags
1333+
'make': ['MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w'],
1334+
'mingw32-make': ['MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w'],
1335+
'msbuild.exe': ['/property:Configuration=Release;Platform=x64']
1336+
},
1337+
'cppcheck_opts': ' '.join(cppcheck_opts) # the check options
1338+
}
1339+
reply_obj.update(reply_data)
1340+
1341+
reply = json.dumps(reply_obj)
1342+
print_ts('GetCppcheckData: ' + reply)
12871343
connection.send(reply.encode('utf-8', 'ignore'))
12881344
connection.close()
12891345
elif cmd == 'get\n':

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 & 12 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.49"
19+
CLIENT_VERSION = "1.4.0"
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,12 +463,8 @@ def scan_package(cppcheck_path, source_path, libraries, capture_callstack=True):
440463

441464
dir_to_scan = source_path
442465

443-
# TODO: temporarily disabled timing information - use --showtime=top5_summary when next version is released
444-
# TODO: remove missingInclude disabling when it no longer is implied by --enable=information
445466
# Reference for GNU C: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
446-
options = libs + ' --showtime=none --check-library --inconclusive --enable=style,information --inline-suppr --disable=missingInclude --suppress=unmatchedSuppression --template=daca2'
447-
options += ' --debug-warnings --suppress=autoNoType --suppress=valueFlowBailout --suppress=bailoutUninitVar --suppress=symbolDatabaseWarning'
448-
options += ' -D__GNUC__ --platform=unix64'
467+
options = libs + cppcheck_opts
449468
options_rp = options + ' -rp={}'.format(dir_to_scan)
450469
if __make_cmd == 'msbuild.exe':
451470
cppcheck_cmd = os.path.join(cppcheck_path, 'bin', 'cppcheck.exe') + ' ' + options_rp

0 commit comments

Comments
 (0)