-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathci-coveralls-merge.py
executable file
·68 lines (59 loc) · 2.04 KB
/
ci-coveralls-merge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# Hacked up merger for testing
from __future__ import print_function
import hashlib
import json
import os
import os.path
import sys
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
print("Merging coveralls json coverage")
# Special-cased gap-coveralls.json, because we rely
# on GAP to set the correct service_name, pull-request number
# etc
print("file: gap-coveralls.json", end="")
if os.path.isfile('gap-coveralls.json'):
with open('gap-coveralls.json', 'r') as f:
merged = json.load(f)
print(" done.")
else:
print()
print("WARNING: could not find gap-coveralls.json, quitting")
sys.exit(0)
if not 'source_files' in merged:
print("warning: source_files not in JSON dictionary read from gap-coveralls.json")
merged['source_files'] = []
print("merging c-coveralls.json")
with open('c-coveralls.json', 'r') as f:
input = json.load(f)
sf = merged['source_files']
for file in input['files']:
name = file["file"]
print("processing ", name)
# TODO: normalize filename, remove leading "./"?
source_digest = md5(name)
max_line_number = max([line["line_number"] for line in file["lines"]])
coverage = [None] * max_line_number
result = { "name" : name, "source_digest" : source_digest, "coverage" : coverage }
print(" MD5 hash = ", source_digest)
for line in file["lines"]:
if line["gcovr/noncode"]:
continue
coverage[line["line_number"]-1] = line["count"]
sf.append(result)
if len(merged['source_files']) > 0:
print("Merged:")
for k in merged.keys():
if (k != 'source_files'):
print("%s: %s" % (k, merged[k]))
print("Writing merged profiles to merged-coveralls.json")
with open('merged-coveralls.json', 'w+') as dump:
json.dump(merged, dump)
else:
print("No coverage found.")
print("Done. Bye.")