Donate CPU: Concentrate on the diff

This commit is contained in:
Daniel Marjamäki 2018-08-26 16:23:42 +02:00
parent b2f0bd315d
commit 6ec6f70f2d
1 changed files with 36 additions and 42 deletions

View File

@ -31,21 +31,25 @@ def checkRequirements():
def getCppcheck(cppcheckPath): def getCppcheck(cppcheckPath):
print('Get Cppcheck..') print('Get Cppcheck..')
if os.path.exists(cppcheckPath): for i in range(5):
os.chdir(cppcheckPath) if os.path.exists(cppcheckPath):
subprocess.call(['git', 'checkout', '-f']) os.chdir(cppcheckPath)
subprocess.call(['git', 'pull']) subprocess.call(['git', 'checkout', '-f'])
else: subprocess.call(['git', 'pull'])
subprocess.call(['git', 'clone', 'http://github.com/danmar/cppcheck.git', cppcheckPath]) else:
if not os.path.exists(cppcheckPath): subprocess.call(['git', 'clone', 'http://github.com/danmar/cppcheck.git', cppcheckPath])
return False if not os.path.exists(cppcheckPath):
time.sleep(2) print('Failed to clone, will try again in 10 minutes..')
return True time.sleep(600)
continue
time.sleep(2)
return True
return False
def compile_version(workPath, version): def compile_version(workPath, version):
if os.path.isfile(workPath + '/' + version + '/cppcheck'): if os.path.isfile(workPath + '/' + version + '/cppcheck'):
return return True
os.chdir(workPath + '/cppcheck') os.chdir(workPath + '/cppcheck')
subprocess.call(['git', 'checkout', version]) subprocess.call(['git', 'checkout', version])
subprocess.call(['make', 'clean']) subprocess.call(['make', 'clean'])
@ -56,6 +60,11 @@ def compile_version(workPath, version):
subprocess.call(['cp', '-R', workPath + '/cppcheck/cfg', destPath]) subprocess.call(['cp', '-R', workPath + '/cppcheck/cfg', destPath])
subprocess.call(['cp', 'cppcheck', destPath]) subprocess.call(['cp', 'cppcheck', destPath])
subprocess.call(['git', 'checkout', 'master']) subprocess.call(['git', 'checkout', 'master'])
try:
subprocess.call([workPath + '/' + version + '/cppcheck', '--version'])
except OSError:
return False
return True
def compile(cppcheckPath): def compile(cppcheckPath):
@ -116,20 +125,17 @@ def unpackPackage(workPath, tgz):
def scanPackage(workPath, cppcheck): def scanPackage(workPath, cppcheck):
print('Analyze..') print('Analyze..')
os.chdir(workPath) os.chdir(workPath)
cmd = 'nice ' + cppcheck + ' -D__GCC__ --enable=style --library=posix --platform=unix64 --template=daca2 -rp=temp temp' cmd = 'nice ' + cppcheck + ' -D__GCC__ --enable=style --library=posix --platform=unix64 --template={file}:{line}:{message}[{id}] -rp=temp temp'
print(cmd) print(cmd)
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
comm = p.communicate() comm = p.communicate()
errout = comm[1].decode('utf-8') errout = comm[1].decode('utf-8')
count = 0 count = 0
for line in errout.split('\n'): for line in errout.split('\n'):
if re.match(r'.*:[0-9]+:[0-9]+: [a-z]+: .*\]$', line): if re.match(r'.*:[0-9]+:.*\]$', line):
count += 1 count += 1
if count == 0: print('Number of issues: ' + str(count))
errout = None return count, errout
else:
print('Number of issues: ' + str(count))
return errout
def diffResults(workPath, ver1, results1, ver2, results2): def diffResults(workPath, ver1, results1, ver2, results2):
@ -155,9 +161,6 @@ def diffResults(workPath, ver1, results1, ver2, results2):
while i2 < len(r2): while i2 < len(r2):
ret += ver2 + ' ' + r2[i2] + '\n' ret += ver2 + ' ' + r2[i2] + '\n'
i2 += 1 i2 += 1
if len(ret)==0:
return None
print(ret)
return ret return ret
@ -193,34 +196,25 @@ if not os.path.exists(workpath):
cppcheckPath = workpath + '/cppcheck' cppcheckPath = workpath + '/cppcheck'
while True: while True:
if not getCppcheck(cppcheckPath): if not getCppcheck(cppcheckPath):
time.sleep(5) print('Failed to clone Cppcheck, retry later')
if not getCppcheck(cppcheckPath): sys.exit(1)
print('Failed to clone Cppcheck, retry later') if compile_version(workpath, '1.84') == False:
sys.exit(1) print('Failed to compile Cppcheck-1.84, retry later')
compile_version(workpath, '1.84') sys.exit(1)
if compile(cppcheckPath) == False: if compile(cppcheckPath) == False:
print('Failed to compile Cppcheck, retry later') print('Failed to compile Cppcheck, retry later')
sys.exit(1) sys.exit(1)
package = getPackage() package = getPackage()
tgz = downloadPackage(workpath, package) tgz = downloadPackage(workpath, package)
unpackPackage(workpath, tgz) unpackPackage(workpath, tgz)
allResults = '' output = 'cppcheck:head 1.84\ncount:'
resultsToDiff = [] resultsToDiff = []
for cppcheck in ['cppcheck/cppcheck', '1.84/cppcheck']: for cppcheck in ['cppcheck/cppcheck', '1.84/cppcheck']:
cmd = workpath + '/' + cppcheck c,errout = scanPackage(workpath, cppcheck)
if not os.path.isfile(cmd): output += ' ' + str(c)
continue resultsToDiff.append(errout)
res = scanPackage(workpath, cmd) output += '\ndiff:\n' + diffResults(workpath, 'head', resultsToDiff[0], '1.84', resultsToDiff[1])
if res: uploadResults(package, output)
resultsToDiff.append(res)
allResults += 'cppcheck:' + cppcheck + '\n' + res
if len(resultsToDiff) == 0:
print('No results to upload')
continue
if len(resultsToDiff) == 2:
diff = diffResults(workpath, 'head', resultsToDiff[0], '1.84', resultsToDiff[1])
if diff:
allResults += 'diff:\n' + diff
uploadResults(package, allResults)
print('Results have been uploaded') print('Results have been uploaded')
print('Sleep 5 seconds..')
time.sleep(5) time.sleep(5)