add postprocessing script to deduplicate cobertura reports
This commit is contained in:
parent
427e07ec8a
commit
daa1eba969
|
@ -59,7 +59,7 @@ coverage:
|
|||
LLVM_PROFILE_FILE: "arti-%p-%m.profraw"
|
||||
script:
|
||||
- apt-get update && apt-get install -y python3-pip python3-setuptools
|
||||
- pip3 install beautifulsoup4
|
||||
- pip3 install beautifulsoup4 lxml
|
||||
- rustup toolchain add nightly
|
||||
- rustup default nightly
|
||||
- rustup component add llvm-tools-preview
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# Use BeautifulSoup to deduplicate functions in a grov XML (cobertura)
|
||||
# output file.
|
||||
|
||||
import sys
|
||||
|
||||
try:
|
||||
from bs4 import BeautifulSoup
|
||||
import lxml
|
||||
except ImportError:
|
||||
print("Sorry, BeautifulSoup 4 or lxml is not installed.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print(f"Usage: {sys.argv[0]} <cobertura_file>")
|
||||
print(" Post-process a grcov cobertura.xml file")
|
||||
sys.exit(1)
|
||||
|
||||
# Parse the coverage file
|
||||
with open(sys.argv[1]) as f:
|
||||
document = BeautifulSoup(f, "lxml")
|
||||
|
||||
# Iterate over source files
|
||||
for file in document.coverage.packages.findAll("package"):
|
||||
already_seen = set()
|
||||
# Iterate over function
|
||||
for func in file.classes.findChild("class").methods.findAll("method"):
|
||||
name = func["name"]
|
||||
if name in already_seen:
|
||||
# Remove duplicate function
|
||||
func.extract()
|
||||
else:
|
||||
already_seen.add(name)
|
||||
|
||||
with open(sys.argv[1], 'w') as out:
|
||||
out.write(document.prettify())
|
|
@ -137,7 +137,11 @@ grcov "$COVERAGE_BASEDIR/coverage_meta" \
|
|||
--ignore="crates/arti-bench/*" \
|
||||
--ignore="*/github.com-1ecc6299db9ec823/*"
|
||||
|
||||
if [ "$format" != html ]; then
|
||||
if [ "$format" == cobertura ]; then
|
||||
python3 "$COVERAGE_BASEDIR/maint/postprocess_coverage_cobertura.py" "$COVERAGE_BASEDIR/$output"
|
||||
echo "Full report: $COVERAGE_BASEDIR/$output"
|
||||
exit
|
||||
elif [ "$format" != html ]; then
|
||||
# no html post processing when outputing non html result
|
||||
echo "Full report: $COVERAGE_BASEDIR/$output"
|
||||
exit
|
||||
|
@ -149,7 +153,7 @@ if [ "$(which python3 2>/dev/null)" = "" ]; then
|
|||
echo "python3 not installed; not post-processing the index file."
|
||||
else
|
||||
echo "Postprocessing..."
|
||||
python3 "$COVERAGE_BASEDIR/maint/postprocess_coverage.py" "$COVERAGE_BASEDIR/coverage_meta/commands" "$COVERAGE_BASEDIR/$output/index.html" "$COVERAGE_BASEDIR/$output/index.html"
|
||||
python3 "$COVERAGE_BASEDIR/maint/postprocess_coverage_html.py" "$COVERAGE_BASEDIR/coverage_meta/commands" "$COVERAGE_BASEDIR/$output/index.html" "$COVERAGE_BASEDIR/$output/index.html"
|
||||
fi
|
||||
|
||||
echo "Full report: $COVERAGE_BASEDIR/$output/index.html"
|
||||
|
|
Loading…
Reference in New Issue