From b6dbf1dca18d49481691590a6e9c43ad2fc5ce8a Mon Sep 17 00:00:00 2001 From: Emanuel Schmoczer Date: Thu, 12 Sep 2019 16:06:26 +0200 Subject: [PATCH 1/3] make xccov-to-sonarqube-generic.sh work with Xcode 11 (#63) --- .../xccov-to-sonarqube-generic.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh b/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh index 7b4f258a..882a06b1 100644 --- a/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh +++ b/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh @@ -5,7 +5,12 @@ function convert_file { local xccovarchive_file="$1" local file_name="$2" echo " " - xcrun xccov view --file "$file_name" "$xccovarchive_file" | \ + local line_coverage_cmd="xcrun xccov view" + if [[ $@ == *".xcresult"* ]]; then + line_coverage_cmd="$line_coverage_cmd --archive" + fi + line_coverage_cmd="$line_coverage_cmd --file \"$file_name\" \"$xccovarchive_file\"" + eval $line_coverage_cmd | \ sed -n ' s/^ *\([0-9][0-9]*\): 0.*$/ /p; s/^ *\([0-9][0-9]*\): [1-9].*$/ /p @@ -16,7 +21,12 @@ function convert_file { function xccov_to_generic { echo '' for xccovarchive_file in "$@"; do - xcrun xccov view --file-list "$xccovarchive_file" | while read -r file_name; do + local file_list_cmd="xcrun xccov view" + if [[ $@ == *".xcresult"* ]]; then + file_list_cmd="$file_list_cmd --archive" + fi + file_list_cmd="$file_list_cmd --file-list \"$xccovarchive_file\"" + eval $file_list_cmd | while read -r file_name; do convert_file "$xccovarchive_file" "$file_name" done done From 7534c2966ec7f1ceef6218a0eba0b41c10288397 Mon Sep 17 00:00:00 2001 From: Emanuel Schmoczer Date: Thu, 12 Sep 2019 16:08:50 +0200 Subject: [PATCH 2/3] Update README for Xcode 11 --- swift-coverage/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swift-coverage/README.md b/swift-coverage/README.md index 06de8682..2cc04a0a 100644 --- a/swift-coverage/README.md +++ b/swift-coverage/README.md @@ -23,7 +23,8 @@ XCode version | Command --- | --- XCode 8+ - 9.2 | `xcrun llvm-cov show -instr-profile=Build/ProfileData//Coverage.profdata Build/Products/Debug/swift-coverage-example.app/Contents/MacOS/swift-coverage-example > Coverage.report` XCode 9.3 - 9.4.1 | `bash xccov-to-sonarqube-generic.sh Build/Logs/Test/*.xccovarchive/ > sonarqube-generic-coverage.xml` -XCode 10+ | `bash xccov-to-sonarqube-generic.sh Build/Logs/Test/*.xcresult/*_Test/*.xccovarchive/ > sonarqube-generic-coverage.xml` +XCode 10 | `bash xccov-to-sonarqube-generic.sh Build/Logs/Test/*.xcresult/*_Test/*.xccovarchive/ > sonarqube-generic-coverage.xml` +XCode 11 | `bash xccov-to-sonarqube-generic.sh Build/Logs/Test/*.xcresult/ > sonarqube-generic-coverage.xml` 1.c Import code coverage report From 064d0be3292703ab86b41fac957e122899d38e0b Mon Sep 17 00:00:00 2001 From: Emanuel Schmoczer Date: Fri, 11 Oct 2019 15:50:10 +0200 Subject: [PATCH 3/3] Simplify script. This closes #63 --- .../xccov-to-sonarqube-generic.sh | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh b/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh index 882a06b1..bb2edbc6 100644 --- a/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh +++ b/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh @@ -4,13 +4,9 @@ set -euo pipefail function convert_file { local xccovarchive_file="$1" local file_name="$2" + local xccov_options="$3" echo " " - local line_coverage_cmd="xcrun xccov view" - if [[ $@ == *".xcresult"* ]]; then - line_coverage_cmd="$line_coverage_cmd --archive" - fi - line_coverage_cmd="$line_coverage_cmd --file \"$file_name\" \"$xccovarchive_file\"" - eval $line_coverage_cmd | \ + xcrun xccov view $xccov_options --file "$file_name" "$xccovarchive_file" | \ sed -n ' s/^ *\([0-9][0-9]*\): 0.*$/ /p; s/^ *\([0-9][0-9]*\): [1-9].*$/ /p @@ -21,13 +17,12 @@ function convert_file { function xccov_to_generic { echo '' for xccovarchive_file in "$@"; do - local file_list_cmd="xcrun xccov view" - if [[ $@ == *".xcresult"* ]]; then - file_list_cmd="$file_list_cmd --archive" + local xccov_options="" + if [[ $xccovarchive_file == *".xcresult"* ]]; then + xccov_options="--archive" fi - file_list_cmd="$file_list_cmd --file-list \"$xccovarchive_file\"" - eval $file_list_cmd | while read -r file_name; do - convert_file "$xccovarchive_file" "$file_name" + 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 ''