-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,42 @@ | ||
#!/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 convert_file { | ||
local xccovarchive_file="$1" | ||
local file_name="$2" | ||
local xccov_options="$3" | ||
echo " <file path=\"$file_name\">" | ||
xcrun xccov view $xccov_options --file "$file_name" "$xccovarchive_file" | \ | ||
sed -n ' | ||
s/^ *\([0-9][0-9]*\): 0.*$/ <lineToCover lineNumber="\1" covered="false"\/>/p; | ||
s/^ *\([0-9][0-9]*\): [1-9].*$/ <lineToCover lineNumber="\1" covered="true"\/>/p | ||
' | ||
echo ' </file>' | ||
} | ||
|
||
function xccov_to_generic { | ||
local xcresult="$1" | ||
|
||
echo '<coverage version="1">' | ||
xcrun xccov view --archive "$xcresult" | convert_xccov_to_xml | ||
for xccovarchive_file in "$@"; do | ||
if [[ ! -d $xccovarchive_file ]] | ||
then | ||
echo "Coverage FILE NOT FOUND AT PATH: $xccovarchive_file" 1>&2; | ||
exit 1 | ||
fi | ||
|
||
local xccov_options="" | ||
if [[ $xccovarchive_file == *".xcresult"* ]]; then | ||
xccov_options="--archive" | ||
fi | ||
xcrun xccov view $xccov_options --file-list "$xccovarchive_file" | while read -r file_name; do | ||
convert_file "$xccovarchive_file" "$file_name" "$xccov_options" | ||
done | ||
done | ||
echo '</coverage>' | ||
} | ||
|
||
function check_xcode_version() { | ||
local major=${1:-0} minor=${2:-0} | ||
return $(( (major >= 14) || (major == 13 && minor >= 3) )) | ||
function cleanup_tmp_files { | ||
rm -rf tmp.json | ||
rm -rf tmp.xccovarchive | ||
} | ||
|
||
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" | ||
xccov_to_generic "$@" | ||
cleanup_tmp_files |