Skip to content

How to add coverage for a subproject

Jon Reid edited this page Feb 10, 2016 · 10 revisions

It takes some tweaking, but XcodeCoverage can report code coverage for subprojects.

Enable coverage

Enable coverage each subproject.

Important: You must use the same configuration across subprojects and the main target.

Define path in envcov.sh

Edit envcov.sh and define the path to the object folder of your subproject. If you're measuring the Debug configuration, make something like this:

MYLIB_OBJ=${OBJROOT}/MyLib.build/Debug-iphonesimulator/MyLib.build/Objects-normal/${CURRENT_ARCH}

Confirm that the path is correct. The name of the folder under Debug-iphonesimulator may need to be adjusted.

Add this path to cleancov

Edit cleancov to add the path to be zeroed.

LCOV --zerocounters -d "${MYLIB_OBJ}"

Add this path to getcov

Edit the gather_coverage() function in getcov. At the bottom, add something like

LCOV --capture -b "${MYLIB_OBJ}" -d "${MYLIB_OBJ}" -o MyLib.info

This directs lcov to capture coverage data for a specific library, writing it to the .info file.

Then we need to collect the data from all libraries and add it to the main file:

LCOV -o ${LCOV_INFO} -a ${LCOV_INFO} -a MyLib.info -a YetAnotherLib.info