-
Notifications
You must be signed in to change notification settings - Fork 35
/
xccov-to-sonarqube-generic.sh
50 lines (42 loc) · 1.5 KB
/
xccov-to-sonarqube-generic.sh
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
#!/usr/bin/env bash
set -euo pipefail
function convert_xccov_to_xml {
sed -n \
-e '/:$/s/&/\&/g;s/^\(.*\):$/ <file path="\1">/p' \
-e 's/^ *\([0-9][0-9]*\): 0.*$/ <lineToCover lineNumber="\1" covered="false"\/>/p' \
-e 's/^ *\([0-9][0-9]*\): [1-9].*$/ <lineToCover lineNumber="\1" covered="true"\/>/p' \
-e 's/^$/ <\/file>/p'
}
function trim_pwd {
local pwd_dir=`pwd`
sed "s|$pwd_dir|.|"
}
function xccov_to_generic {
local xcresult="$1"
echo '<coverage version="1">'
xcrun xccov view --archive "$xcresult" | convert_xccov_to_xml | trim_pwd
echo '</coverage>'
}
function check_xcode_version() {
local major=${1:-0} minor=${2:-0}
return $(( (major >= 14) || (major == 13 && minor >= 3) ))
}
if ! xcode_version="$(xcodebuild -version | sed -n '1s/^Xcode \([0-9.]*\)$/\1/p')"; then
echo 'Failed to get Xcode version' 1>&2
exit 1
elif check_xcode_version ${xcode_version//./ }; then
echo "Xcode version '$xcode_version' not supported, version 13.3 or above is required" 1>&2;
exit 1
fi
xcresult="$1"
if [[ $# -ne 1 ]]; then
echo "Invalid number of arguments. Expecting 1 path matching '*.xcresult'"
exit 1
elif [[ ! -d $xcresult ]]; then
echo "Path not found: $xcresult" 1>&2;
exit 1
elif [[ $xcresult != *".xcresult"* ]]; then
echo "Expecting input to match '*.xcresult', got: $xcresult" 1>&2;
exit 1
fi
xccov_to_generic "$xcresult"