#!/usr/bin/bash

#
# Massages the coverage XML of a waf build+test execution to make the results
# look better in Jenkins. This is because some data is referred to the build
# directory and some to original source, so in Jenkins coverage plugin we
# will have two separate entries for a directory which is not so practical.
# See also ELTDEV-141
#
# For Python removes also INTROOT/lib/python3.xx/site-packages/ references
# as well as build/...../src/ ones which should make the names converge and
# hopefully reports too

if [ $# -ne 2 ]; then
	echo "Illegal number of parameters: needs input and output file"
	exit -1
fi

sed -e 's/filename=\"\.\.\//filename=\"/g' -e 's/\ name=\"\.\.\./\ name=\"/g' \
    -e 's/filename=\"INTROOT\/lib\/python3\...\/site-packages\//filename=\"/g' \
    -e 's/ name=\"INTROOT\.lib\.python3\...\.site-packages\./ name=\"/g' \
    -e 's/ name=\"build\.[[:alnum:]._]*\.src\./ name=\"/g' \
    -e 's/filename=\"build\/[[:alnum:]_/]*\/src\//filename=\"/g' \
    $1 > $2
