From aaaaa3d7cfade1c60a80d1de1e2dc84db356aa24 Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 12:49:34 -0500 Subject: [PATCH 01/11] First stab at adding ignore paths through the xcode project --- getcov | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/getcov b/getcov index 8bdacf5..74bee58 100755 --- a/getcov +++ b/getcov @@ -9,6 +9,8 @@ usage() { main() { scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "${scripts}/envcov.sh" + + XCODECOV_IGNORED_PATHS=$(echo ${XCODECOV_IGNORE} | tr ",") LCOV_INFO=Coverage.info output_dir="${BUILT_PRODUCTS_DIR}" @@ -77,6 +79,7 @@ report_values() { echo "SRCROOT : ${SRCROOT}" echo "OBJ_DIR : ${OBJ_DIR}" echo "LCOV_PATH : ${LCOV_PATH}" + echo "IGNORED : ${XCODECOV_IGNORED_PATHS}" } remove_old_report() { @@ -112,7 +115,13 @@ exclude_data() { LCOV --remove "${LCOV_INFO}" "Developer/SDKs/*" -d "${OBJ_DIR}" -o "${LCOV_INFO}" LCOV --remove "${LCOV_INFO}" "main.m" -d "${OBJ_DIR}" -o "${LCOV_INFO}" - # Remove other patterns here... + + #Remove anything Xcode has specified should be ignored. + for IGNORE_THIS in XCODECOV_IGNORED_PATHS { + LCOV --remove "${LCOV_INFO}" "${IGNORE_THIS}" -d "${OBJ_DIR}" -o "${LCOV_INFO}" + } + + # Remove other patterns manually below this line } generate_cobertura_xml() { From af4284b9de4aff8faa12d4f1be18b4b8b1bbb5fd Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 13:23:02 -0500 Subject: [PATCH 02/11] fix some silly bash things --- getcov | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/getcov b/getcov index 74bee58..f7c5f3e 100755 --- a/getcov +++ b/getcov @@ -10,7 +10,7 @@ main() { scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "${scripts}/envcov.sh" - XCODECOV_IGNORED_PATHS=$(echo ${XCODECOV_IGNORE} | tr ",") + XCODECOV_IGNORED_PATHS=$(echo "${XCODECOV_IGNORE}" | tr ",") LCOV_INFO=Coverage.info output_dir="${BUILT_PRODUCTS_DIR}" @@ -117,9 +117,9 @@ exclude_data() { LCOV --remove "${LCOV_INFO}" "main.m" -d "${OBJ_DIR}" -o "${LCOV_INFO}" #Remove anything Xcode has specified should be ignored. - for IGNORE_THIS in XCODECOV_IGNORED_PATHS { + for IGNORE_THIS in ${XCODECOV_IGNORED_PATHS}; do LCOV --remove "${LCOV_INFO}" "${IGNORE_THIS}" -d "${OBJ_DIR}" -o "${LCOV_INFO}" - } + done # Remove other patterns manually below this line } From 2ebd2d8b56cc4d4779eff324fdecdfa12cada938 Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 13:28:15 -0500 Subject: [PATCH 03/11] Grep the new variable --- exportenv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exportenv.sh b/exportenv.sh index 30f7745..d751363 100755 --- a/exportenv.sh +++ b/exportenv.sh @@ -2,4 +2,4 @@ # Copyright 2015 Jonathan M. Reid. See LICENSE.txt scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)' > "${scripts}/env.sh" +export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)|(XCODECOV_IGNORE)' > "${scripts}/env.sh" From 97fffdeca3464ecd59c7afd132c78f20e48e1559 Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 13:32:05 -0500 Subject: [PATCH 04/11] Hey maybe i should transpose TO something --- getcov | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getcov b/getcov index f7c5f3e..2ca0396 100755 --- a/getcov +++ b/getcov @@ -10,7 +10,7 @@ main() { scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "${scripts}/envcov.sh" - XCODECOV_IGNORED_PATHS=$(echo "${XCODECOV_IGNORE}" | tr ",") + XCODECOV_IGNORED_PATHS=$(echo "${XCODECOV_IGNORE}" | tr "," "\n") LCOV_INFO=Coverage.info output_dir="${BUILT_PRODUCTS_DIR}" From 88302506d61441beb107f3d98289b5c2f83bf004 Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 13:47:22 -0500 Subject: [PATCH 05/11] Add eval so wildcards expand --- getcov | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/getcov b/getcov index 2ca0396..54f75fe 100755 --- a/getcov +++ b/getcov @@ -118,7 +118,9 @@ exclude_data() { #Remove anything Xcode has specified should be ignored. for IGNORE_THIS in ${XCODECOV_IGNORED_PATHS}; do - LCOV --remove "${LCOV_INFO}" "${IGNORE_THIS}" -d "${OBJ_DIR}" -o "${LCOV_INFO}" + #use eval to expand any of the variables and then pass them to the shell - this allows + #use of wildcards in the variables. + eval LCOV --remove "${LCOV_INFO}" "${IGNORE_THIS}" -d "${OBJ_DIR}" -o "${LCOV_INFO}" done # Remove other patterns manually below this line From 9af0ee8b6a8ee8ed939cb7e7f9a4bec642a23747 Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 13:57:07 -0500 Subject: [PATCH 06/11] Let's try this with a file instead of a comma separated list. --- exportenv.sh | 2 +- getcov | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exportenv.sh b/exportenv.sh index d751363..30f7745 100755 --- a/exportenv.sh +++ b/exportenv.sh @@ -2,4 +2,4 @@ # Copyright 2015 Jonathan M. Reid. See LICENSE.txt scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)|(XCODECOV_IGNORE)' > "${scripts}/env.sh" +export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)' > "${scripts}/env.sh" diff --git a/getcov b/getcov index 54f75fe..fe2a167 100755 --- a/getcov +++ b/getcov @@ -10,7 +10,7 @@ main() { scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "${scripts}/envcov.sh" - XCODECOV_IGNORED_PATHS=$(echo "${XCODECOV_IGNORE}" | tr "," "\n") + readarray XCODECOV_IGNORED_PATHS < "${SRCROOT}/.xcodecoverageignore" LCOV_INFO=Coverage.info output_dir="${BUILT_PRODUCTS_DIR}" From 5b4f3b00254a6de6b7d49a78fd6414f95a5eece5 Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 14:10:44 -0500 Subject: [PATCH 07/11] So apparently readarray isn't a thing on macs --- getcov | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/getcov b/getcov index fe2a167..82213a1 100755 --- a/getcov +++ b/getcov @@ -9,8 +9,6 @@ usage() { main() { scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "${scripts}/envcov.sh" - - readarray XCODECOV_IGNORED_PATHS < "${SRCROOT}/.xcodecoverageignore" LCOV_INFO=Coverage.info output_dir="${BUILT_PRODUCTS_DIR}" @@ -116,14 +114,12 @@ exclude_data() { LCOV --remove "${LCOV_INFO}" "Developer/SDKs/*" -d "${OBJ_DIR}" -o "${LCOV_INFO}" LCOV --remove "${LCOV_INFO}" "main.m" -d "${OBJ_DIR}" -o "${LCOV_INFO}" - #Remove anything Xcode has specified should be ignored. - for IGNORE_THIS in ${XCODECOV_IGNORED_PATHS}; do - #use eval to expand any of the variables and then pass them to the shell - this allows + #Remove anything the .xcodecoverageignore file has specified should be ignored. + cat "${SRCROOT}/.xcodecoverageignore" | while read IGNORE_THIS; do + #use eval to expand any of the variables and then pass them to the shell - this allows #use of wildcards in the variables. eval LCOV --remove "${LCOV_INFO}" "${IGNORE_THIS}" -d "${OBJ_DIR}" -o "${LCOV_INFO}" done - - # Remove other patterns manually below this line } generate_cobertura_xml() { From 70978071f29721e440e73adf49b970be1e4a53eb Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 14:14:02 -0500 Subject: [PATCH 08/11] try to make the ignore file not need a newline at the end. --- getcov | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getcov b/getcov index 82213a1..1ca5a5a 100755 --- a/getcov +++ b/getcov @@ -115,7 +115,7 @@ exclude_data() { LCOV --remove "${LCOV_INFO}" "main.m" -d "${OBJ_DIR}" -o "${LCOV_INFO}" #Remove anything the .xcodecoverageignore file has specified should be ignored. - cat "${SRCROOT}/.xcodecoverageignore" | while read IGNORE_THIS; do + (cat "${SRCROOT}/.xcodecoverageignore"; echo) | while read IGNORE_THIS; do #use eval to expand any of the variables and then pass them to the shell - this allows #use of wildcards in the variables. eval LCOV --remove "${LCOV_INFO}" "${IGNORE_THIS}" -d "${OBJ_DIR}" -o "${LCOV_INFO}" From 6f92efdfa050970b49945d22de1d1a4f6af3751a Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 14:47:55 -0500 Subject: [PATCH 09/11] Update README to include instructions on use of new exclusion strategy --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 918b6b0..1dff3d5 100644 --- a/README.md +++ b/README.md @@ -81,10 +81,22 @@ If you make changes to your production code, you should clear out all build arti * Set script to `source XcodeCoverage/run_code_coverage_post.sh` for standard installation. For CocoaPods installation, use `source Pods/XcodeCoverage/run_code_coverage_post.sh` -Modification -============ +Excluding Files From Coverage +============================= -If you are using the standard installation, you can modify `exclude_data()` in `getcov` to specify which files to exclude, such as third-party libraries. +If there are files or folders which you want to have the coverage generator ignore (for instance, third-party libraries not installed via CocoaPods or machine-generated files), add an `.xcodecoverageignore` file to your `SRCROOT`. + +Each line should be a different file or group of files which should be excluded for code coverage purposes. You can use `SRCROOT` relative paths as well as the `*` character to indicate everything below a certain directory should be excluded. + +Example contents of an `.xcodecoverageignore` file: + +``` +${SRCROOT}/TestedProject/Machine Files/* +${SRCROOT}/TestedProject/Third-Party/SingleFile.m +${SRCROOT}/TestedProject/Categories/UIImage+IgnoreMe.{h,m} +``` + +Note: If you were using a version of XcodeCoverage prior to 1.3, you will need to move the list of files and folders you wish to ignore to the `.xcodecoverageignore` file. The current setup will prevent your customized list from being overwritten when there is an update to this project. Credits From 34a161548489892f6b0fcbf128e794bcb02fcca3 Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 14:48:11 -0500 Subject: [PATCH 10/11] Update changelog and/or give myself a pat on the back. --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 1518fa5..3e8c393 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +Version 1.3.0 +------------- +_12 August 2015_ + +* Update to look for an `.xcodecoverageignore` file in `SRCROOT` instead of needing to manually update the `getcov` script to specify which files to ignore - a specification which would get overwritten if you were using CocoaPods and ran `pod update`. _Thanks to: Ellen Shapiro_ + Version 1.2.2 ------------- _22 Mar 2015_ From 42ec5aa49bcf606719a60b39de234e97b219f07a Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Wed, 12 Aug 2015 15:05:27 -0500 Subject: [PATCH 11/11] tabs -> spaces --- getcov | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getcov b/getcov index 1ca5a5a..dedcc36 100755 --- a/getcov +++ b/getcov @@ -117,8 +117,8 @@ exclude_data() { #Remove anything the .xcodecoverageignore file has specified should be ignored. (cat "${SRCROOT}/.xcodecoverageignore"; echo) | while read IGNORE_THIS; do #use eval to expand any of the variables and then pass them to the shell - this allows - #use of wildcards in the variables. - eval LCOV --remove "${LCOV_INFO}" "${IGNORE_THIS}" -d "${OBJ_DIR}" -o "${LCOV_INFO}" + #use of wildcards in the variables. + eval LCOV --remove "${LCOV_INFO}" "${IGNORE_THIS}" -d "${OBJ_DIR}" -o "${LCOV_INFO}" done }