Skip to content

Commit cee04f4

Browse files
authored
donate-cpu: fixed make build / cleanups (#4398)
1 parent d12f4fd commit cee04f4

2 files changed

Lines changed: 34 additions & 23 deletions

File tree

tools/donate-cpu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@
230230

231231
def get_client_version_head():
232232
cmd = 'python3' + ' ' + os.path.join(tree_path, 'tools', 'donate-cpu.py') + ' ' + '--version'
233-
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
233+
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, universal_newlines=True)
234234
try:
235235
comm = p.communicate()
236-
return comm[0].decode(encoding='utf-8', errors='ignore').strip()
236+
return comm[0]
237237
except:
238238
return None
239239

tools/donate_cpu_lib.py

Lines changed: 32 additions & 21 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.31"
18+
CLIENT_VERSION = "1.3.32"
1919

2020
# Timeout for analysis with Cppcheck in seconds
2121
CPPCHECK_TIMEOUT = 30 * 60
@@ -34,10 +34,10 @@ def detect_make():
3434

3535
for m in make_cmds:
3636
try:
37-
print('{} --version'.format(m))
38-
subprocess.call([m, '--version'])
37+
#print('{} --version'.format(m))
38+
subprocess.call([m, '--version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
3939
except OSError as e:
40-
print("'{}' not found ({})".format(m, e))
40+
#print("'{}' not found ({})".format(m, e))
4141
continue
4242

4343
print("using '{}'".format(m))
@@ -62,8 +62,8 @@ def check_requirements():
6262

6363
for app in apps:
6464
try:
65-
print('{} --version'.format(app))
66-
subprocess.call([app, '--version'])
65+
#print('{} --version'.format(app))
66+
subprocess.call([app, '--version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
6767
except OSError:
6868
print("Error: '{}' is required".format(app))
6969
result = False
@@ -141,7 +141,7 @@ def checkout_cppcheck_version(repo_path, version, cppcheck_path):
141141

142142
def get_cppcheck_info(cppcheck_path):
143143
try:
144-
return subprocess.check_output(['git', 'show', "--pretty=%h (%ci)", 'HEAD', '--no-patch', '--no-notes'], cwd=cppcheck_path).decode('utf-8').strip()
144+
return subprocess.check_output(['git', 'show', "--pretty=%h (%ci)", 'HEAD', '--no-patch', '--no-notes'], universal_newlines=True, cwd=cppcheck_path).strip()
145145
except:
146146
return ''
147147

@@ -173,23 +173,36 @@ def compile_cppcheck(cppcheck_path, jobs):
173173
print('Compiling {}'.format(os.path.basename(cppcheck_path)))
174174
try:
175175
if __make_cmd == 'msbuild.exe':
176-
# TODO: run matchcompiler
177-
# TODO: always uses all available threads
178-
subprocess.check_call([__make_cmd, jobs.replace('j', 'm:', 1), '-t:cli', os.path.join(cppcheck_path, 'cppcheck.sln'), '/property:Configuration=Release;Platform=x64'], cwd=cppcheck_path)
179-
subprocess.check_call([os.path.join(cppcheck_path, 'bin', 'cppcheck.exe'), '--version'], cwd=os.path.join(cppcheck_path, 'bin'))
176+
subprocess.check_call(['python3', os.path.join('tools', 'matchcompiler.py'), '--write-dir', 'lib'], cwd=cppcheck_path)
177+
build_env = os.environ
178+
# append to cl.exe options - need to omit dash or slash since a dash is being prepended
179+
build_env["_CL_"] = jobs.replace('j', 'MP', 1)
180+
# TODO: processes still exhaust all threads of the system
181+
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)
180182
else:
181-
rdynamic = ''
183+
build_cmd = [__make_cmd, jobs, 'MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w']
182184
build_env = os.environ
183185
if __make_cmd == 'mingw32-make':
184186
# TODO: MinGW will always link even if no changes are present
185187
# assume Python is in PATH for now
186188
build_env['PYTHON_INTERPRETER'] = 'python3'
187189
# TODO: MinGW is not detected by Makefile - so work around it for now
188-
rdynamic = 'RDYNAMIC=-lshlwapi'
189-
subprocess.check_call([__make_cmd, jobs, 'MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w', rdynamic], cwd=cppcheck_path, env=build_env)
190+
build_cmd.append('RDYNAMIC=-lshlwapi')
191+
subprocess.check_call(build_cmd, cwd=cppcheck_path, env=build_env)
192+
except Exception as e:
193+
print('Compilation failed: {}'.format(e))
194+
return False
195+
196+
try:
197+
if __make_cmd == 'msbuild.exe':
198+
subprocess.check_call([os.path.join(cppcheck_path, 'bin', 'cppcheck.exe'), '--version'], cwd=os.path.join(cppcheck_path, 'bin'))
199+
else:
190200
subprocess.check_call([os.path.join(cppcheck_path, 'cppcheck'), '--version'], cwd=cppcheck_path)
191-
except:
201+
except Exception as e:
202+
print('Running Cppcheck failed: {}'.format(e))
203+
# TODO: remove binary
192204
return False
205+
193206
return True
194207

195208

@@ -348,9 +361,9 @@ def __run_command(cmd, print_cmd=True):
348361
start_time = time.time()
349362
comm = None
350363
if sys.platform == 'win32':
351-
p = subprocess.Popen(shlex.split(cmd, comments=False, posix=False), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
364+
p = subprocess.Popen(shlex.split(cmd, comments=False, posix=False), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
352365
else:
353-
p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid)
366+
p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, preexec_fn=os.setsid)
354367
try:
355368
comm = p.communicate(timeout=CPPCHECK_TIMEOUT)
356369
return_code = p.returncode
@@ -374,8 +387,7 @@ def __run_command(cmd, print_cmd=True):
374387
os.killpg(os.getpgid(p.pid), signal.SIGTERM) # Send the signal to all the process groups
375388
comm = p.communicate()
376389
stop_time = time.time()
377-
stdout = comm[0].decode(encoding='utf-8', errors='ignore')
378-
stderr = comm[1].decode(encoding='utf-8', errors='ignore')
390+
stdout, stderr = comm
379391
elapsed_time = stop_time - start_time
380392
return return_code, stdout, stderr, elapsed_time
381393

@@ -569,7 +581,7 @@ def __send_all(connection, data):
569581

570582
def upload_results(package, results, server_address):
571583
if not __make_cmd == 'make':
572-
print('Error: Information upload not performed - only make build binaries are currently fully supported')
584+
print('Error: Result upload not performed - only make build binaries are currently fully supported')
573585
return False
574586

575587
print('Uploading results.. ' + str(len(results)) + ' bytes')
@@ -693,7 +705,6 @@ def has_include(filedata):
693705

694706
def get_compiler_version():
695707
if __make_cmd == 'msbuild.exe':
696-
# TODO: shorted version string
697708
_, _, stderr, _ = __run_command('cl.exe', False)
698709
return stderr.split('\n')[0]
699710

0 commit comments

Comments
 (0)