Skip to content

Commit 1459684

Browse files
committed
Enable code coverage in Xcode
Signed-off-by: Aaron Sky <aaronsky@skyaaron.com>
1 parent 7b59344 commit 1459684

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

xcodeproj/internal/templates/generate_bazel_dependencies.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ if [ "$ACTION" == "indexbuild" ]; then
121121
apply_sanitizers=0
122122
elif [ "${ENABLE_PREVIEWS:-}" == "YES" ]; then
123123
readonly config="${BAZEL_CONFIG}_swiftuipreviews"
124+
elif [ "${ENABLE_CODE_COVERAGE:-}" == "YES" ]; then
125+
readonly config="${BAZEL_CONFIG}_coverage"
124126
else
125127
readonly config="_${BAZEL_CONFIG}_build"
126128
fi

xcodeproj/internal/templates/xcodeproj.bazelrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,33 @@ common:rules_xcodeproj_indexbuild --config=rules_xcodeproj
8383
# Disable BES for Index Builds, as it runs a lot, and isn't user invoked
8484
common:rules_xcodeproj_indexbuild --bes_backend= --bes_results_url=
8585

86+
### `--config=rules_xcodeproj_coverage`
87+
#
88+
# Used when doing building for code coverage.
89+
90+
common:rules_xcodeproj_coverage --config=rules_xcodeproj
91+
92+
# Enable features that allow for building for instrumentation.
93+
#
94+
# Of particular note are the (swift./)coverage_prefix_map_canonical_non_hermetic
95+
# features, which remap the execroot during the build as the absolute, canonical path
96+
# to the source root.
97+
#
98+
# This approach breaks remote caching when building for testing and codeCoverageEnabled
99+
# is set to YES, but does not affect other builds (for running, or for testing without
100+
# coverage).
101+
common:rules_xcodeproj_coverage --features=coverage
102+
common:rules_xcodeproj_coverage --features=llvm_coverage_map_format
103+
common:rules_xcodeproj_coverage --features=coverage_prefix_map_canonical_non_hermetic
104+
common:rules_xcodeproj_coverage --features=swift.coverage
105+
common:rules_xcodeproj_coverage --features=swift.coverage_prefix_map_canonical_non_hermetic
106+
107+
# Disable features that interfere with (swift./)coverage_prefix_map_canonical_non_hermetic
108+
common:rules_xcodeproj_coverage --features=-coverage_prefix_map
109+
common:rules_xcodeproj_coverage --features=-file_prefix_map
110+
common:rules_xcodeproj_coverage --features=-swift.coverage_prefix_map
111+
common:rules_xcodeproj_coverage --features=-swift.file_prefix_map
112+
86113
### `--config=rules_xcodeproj_swiftuipreviews`
87114
#
88115
# Used when doing a Xcode Previews build.

0 commit comments

Comments
 (0)