Skip to content

Commit fbd55e5

Browse files
committed
Add suppress-code-coverage flag for builds
Signed-off-by: sebastian.shanus <sebastian.shanus@robinhood.com>
1 parent e1bcd9e commit fbd55e5

12 files changed

Lines changed: 139 additions & 1 deletion

File tree

test/internal/pbxproj_partials/write_pbxproj_prefix_tests.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def _write_pbxproj_prefix_test_impl(ctx):
4848
colorize = ctx.attr.colorize,
4949
config = ctx.attr.config,
5050
default_xcode_configuration = ctx.attr.default_xcode_configuration,
51+
suppress_coverage_build = ctx.attr.suppress_coverage_build,
5152
execution_root_file = ctx.attr.execution_root_file,
5253
generator_name = "a_generator_name",
5354
import_index_build_indexstores = (
@@ -153,6 +154,7 @@ write_pbxproj_prefix_test = unittest.make(
153154
"post_build_script": attr.string(),
154155
"pre_build_script": attr.string(),
155156
"project_options": attr.string_dict(mandatory = True),
157+
"suppress_coverage_build": attr.bool(mandatory = True),
156158
"resolved_repositories_file": attr.string(mandatory = True),
157159
"separate_index_build_output_base": attr.bool(mandatory = True),
158160
"target_ids_list": attr.string(mandatory = True),
@@ -182,6 +184,7 @@ def write_pbxproj_prefix_test_suite(name):
182184
colorize = False,
183185
config,
184186
default_xcode_configuration,
187+
suppress_coverage_build = False,
185188
execution_root_file,
186189
import_index_build_indexstores,
187190
index_import,
@@ -208,6 +211,7 @@ def write_pbxproj_prefix_test_suite(name):
208211
colorize = colorize,
209212
config = config,
210213
default_xcode_configuration = default_xcode_configuration,
214+
suppress_coverage_build = suppress_coverage_build,
211215
execution_root_file = execution_root_file,
212216
import_index_build_indexstores = import_index_build_indexstores,
213217
index_import = index_import,
@@ -277,6 +281,8 @@ def write_pbxproj_prefix_test_suite(name):
277281
"some/path/to/index_import",
278282
# separateIndexBuildOutputBase
279283
"0",
284+
# suppressCoverageBuild
285+
"0",
280286
# resolvedRepositoriesFile
281287
"some/path/to/resolved_repositories_file",
282288
# minimumXcodeVersion
@@ -349,6 +355,8 @@ def write_pbxproj_prefix_test_suite(name):
349355
"some/path/to/index_import",
350356
# separateIndexBuildOutputBase
351357
"1",
358+
# suppressCoverageBuild
359+
"0",
352360
# resolvedRepositoriesFile
353361
"some/path/to/resolved_repositories_file",
354362
# minimumXcodeVersion

tools/generators/pbxproj_prefix/src/Generator/Arguments.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Path to a file that contains the absolute path to the Bazel execution root.
4242
)
4343
var separateIndexBuildOutputBase: Bool
4444

45+
@Argument(
46+
help: "Whether to suppress coverage builds even when CLANG_COVERAGE_MAPPING is set.",
47+
transform: { $0 == "1" }
48+
)
49+
var suppressCoverageBuild: Bool
50+
4551
@Argument(
4652
help: """
4753
Path to a file that contains a string for the `RESOLVED_REPOSITORIES` build \

tools/generators/pbxproj_prefix/src/Generator/Environment.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extension Generator {
3131

3232
let pbxProjectBuildSettings: (
3333
_ config: String,
34+
_ suppressCoverageBuild: Bool,
3435
_ importIndexBuildIndexstores: Bool,
3536
_ legacyIndexImport: String,
3637
_ indexImport: String,

tools/generators/pbxproj_prefix/src/Generator/Generator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct Generator {
4949
let pbxProjectPrefixPartial = environment.pbxProjectPrefixPartial(
5050
/*buildSettings:*/ environment.pbxProjectBuildSettings(
5151
/*config:*/ arguments.config,
52+
/*suppressCoverageBuild:*/ arguments.suppressCoverageBuild,
5253
/*importIndexBuildIndexstores:*/ arguments
5354
.importIndexBuildIndexstores,
5455
/*legacyIndexImport:*/ arguments.legacyIndexImport,

tools/generators/pbxproj_prefix/src/Generator/PBXProjectBuildSettings.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extension Generator {
2121
/// - workspace: The absolute path to the Bazel workspace.
2222
static func pbxProjectBuildSettings(
2323
config: String,
24+
suppressCoverageBuild: Bool,
2425
importIndexBuildIndexstores: Bool,
2526
legacyIndexImport: String,
2627
indexImport: String,
@@ -175,6 +176,14 @@ extension Generator {
175176
value: #""$(PROJECT_DIR)/../..""#
176177
),
177178
]
179+
if suppressCoverageBuild {
180+
buildSettings.append(
181+
.init(
182+
key: "BAZEL_SUPPRESS_COVERAGE_BUILD",
183+
value: "YES"
184+
)
185+
)
186+
}
178187
if separateIndexBuildOutputBase {
179188
buildSettings.append(contentsOf: [
180189
.init(

tools/generators/pbxproj_prefix/test/PBXProjectBuildSettingsTests.swift

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class PBXProjectBuildSettingsTests: XCTestCase {
8484

8585
let buildSettings = Generator.pbxProjectBuildSettings(
8686
config: config,
87+
suppressCoverageBuild: false,
8788
importIndexBuildIndexstores: importIndexBuildIndexstores,
8889
legacyIndexImport: legacyIndexImport,
8990
indexImport: indexImport,
@@ -100,6 +101,94 @@ class PBXProjectBuildSettingsTests: XCTestCase {
100101
XCTAssertNoDifference(buildSettings, expectedBuildSettings)
101102
}
102103

104+
func testSuppressCoverageBuild() {
105+
let config = "rxcp_custom_config"
106+
let importIndexBuildIndexstores = false
107+
let legacyIndexImport = "external/legacy-index-import"
108+
let indexImport = "external/index-import"
109+
let indexingProjectDir = "/some/indexing/project dir"
110+
let projectDir = "/some/project dir"
111+
let resolvedRepositories = #""" "/tmp/workspace""#
112+
let workspace = "/Users/TimApple/Star Board"
113+
114+
let expectedBuildSettings = #"""
115+
{
116+
ALWAYS_SEARCH_USER_PATHS = NO;
117+
ASSETCATALOG_COMPILER_GENERATE_ASSET_SYMBOLS = NO;
118+
BAZEL_CONFIG = rxcp_custom_config;
119+
BAZEL_SUPPRESS_COVERAGE_BUILD = YES;
120+
BAZEL_EXTERNAL = "$(BAZEL_OUTPUT_BASE)/external";
121+
BAZEL_INTEGRATION_DIR = "$(INTERNAL_DIR)/bazel";
122+
BAZEL_LLDB_INIT = "$(HOME)/.lldbinit-rules_xcodeproj";
123+
BAZEL_OUT = "$(PROJECT_DIR)/bazel-out";
124+
BAZEL_OUTPUT_BASE = "$(_BAZEL_OUTPUT_BASE:standardizepath)";
125+
BAZEL_WORKSPACE_ROOT = "$(SRCROOT)";
126+
BUILD_DIR = "$(SYMROOT)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
127+
BUILD_MARKER_FILE = "$(OBJROOT)/build_marker";
128+
BUILD_WORKSPACE_DIRECTORY = "$(SRCROOT)";
129+
CC = "$(BAZEL_INTEGRATION_DIR)/clang.sh";
130+
CLANG_ENABLE_OBJC_ARC = YES;
131+
CLANG_MODULES_AUTOLINK = NO;
132+
CODE_SIGNING_ALLOWED = NO;
133+
CODE_SIGN_STYLE = Manual;
134+
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(BAZEL_PACKAGE_BIN_DIR)";
135+
COPY_PHASE_STRIP = NO;
136+
CXX = "$(BAZEL_INTEGRATION_DIR)/clang.sh";
137+
DEBUG_INFORMATION_FORMAT = dwarf;
138+
DSTROOT = "$(PROJECT_TEMP_DIR)";
139+
ENABLE_DEBUG_DYLIB = NO;
140+
ENABLE_DEFAULT_SEARCH_PATHS = NO;
141+
ENABLE_STRICT_OBJC_MSGSEND = YES;
142+
ENABLE_USER_SCRIPT_SANDBOXING = NO;
143+
GCC_OPTIMIZATION_LEVEL = 0;
144+
IMPORT_INDEX_BUILD_INDEXSTORES = NO;
145+
INDEX_DATA_STORE_DIR = "$(INDEX_DATA_STORE_DIR)";
146+
INDEX_FORCE_SCRIPT_EXECUTION = YES;
147+
INDEX_IMPORT = "$(BAZEL_EXTERNAL)/index-import";
148+
INSTALL_PATH = "$(BAZEL_PACKAGE_BIN_DIR)/$(TARGET_NAME)/bin";
149+
INTERNAL_DIR = "$(PROJECT_FILE_PATH)/rules_xcodeproj";
150+
LD = "$(BAZEL_INTEGRATION_DIR)/ld";
151+
LDPLUSPLUS = "$(BAZEL_INTEGRATION_DIR)/ld";
152+
LD_DYLIB_INSTALL_NAME = "";
153+
LD_OBJC_ABI_VERSION = "";
154+
LD_RUNPATH_SEARCH_PATHS = "";
155+
LEGACY_INDEX_IMPORT = "$(BAZEL_EXTERNAL)/legacy-index-import";
156+
LIBTOOL = "$(BAZEL_INTEGRATION_DIR)/libtool";
157+
ONLY_ACTIVE_ARCH = YES;
158+
PROJECT_DIR = "/some/project dir";
159+
RESOLVED_REPOSITORIES = "\"\" \"/tmp/workspace\"";
160+
RULES_XCODEPROJ_BUILD_MODE = bazel;
161+
SRCROOT = "/Users/TimApple/Star Board";
162+
SUPPORTS_MACCATALYST = NO;
163+
SWIFT_EXEC = "$(BAZEL_INTEGRATION_DIR)/swiftc";
164+
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
165+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
166+
SWIFT_USE_INTEGRATED_DRIVER = NO;
167+
SWIFT_VERSION = 5.0;
168+
TAPI_EXEC = /usr/bin/true;
169+
TARGET_TEMP_DIR = "$(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)";
170+
USE_HEADERMAP = NO;
171+
VALIDATE_WORKSPACE = NO;
172+
_BAZEL_OUTPUT_BASE = "$(PROJECT_DIR)/../..";
173+
}
174+
"""#
175+
176+
let buildSettings = Generator.pbxProjectBuildSettings(
177+
config: config,
178+
suppressCoverageBuild: true,
179+
importIndexBuildIndexstores: importIndexBuildIndexstores,
180+
legacyIndexImport: legacyIndexImport,
181+
indexImport: indexImport,
182+
indexingProjectDir: indexingProjectDir,
183+
separateIndexBuildOutputBase: false,
184+
projectDir: projectDir,
185+
resolvedRepositories: resolvedRepositories,
186+
workspace: workspace,
187+
createBuildSettingsAttribute: CreateBuildSettingsAttribute()
188+
)
189+
XCTAssertNoDifference(buildSettings, expectedBuildSettings)
190+
}
191+
103192
func testSeparateIndexOutputBase() {
104193
// Arrange
105194

@@ -181,6 +270,7 @@ class PBXProjectBuildSettingsTests: XCTestCase {
181270

182271
let buildSettings = Generator.pbxProjectBuildSettings(
183272
config: config,
273+
suppressCoverageBuild: false,
184274
importIndexBuildIndexstores: importIndexBuildIndexstores,
185275
legacyIndexImport: legacyIndexImport,
186276
indexImport: indexImport,

xcodeproj/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ string_flag(
4545
visibility = ["//visibility:public"],
4646
)
4747

48+
bool_flag(
49+
name = "suppress_coverage_build",
50+
build_setting_default = False,
51+
visibility = ["//visibility:public"],
52+
)
53+
4854
bool_flag(
4955
name = "separate_index_build_output_base",
5056
build_setting_default = False,

xcodeproj/internal/pbxproj_partials.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ def _write_pbxproj_prefix(
659659
colorize,
660660
config,
661661
default_xcode_configuration,
662+
suppress_coverage_build,
662663
execution_root_file,
663664
generator_name,
664665
import_index_build_indexstores,
@@ -685,6 +686,8 @@ def _write_pbxproj_prefix(
685686
config: The name of the `.bazelrc` config.
686687
default_xcode_configuration: The name of the the Xcode configuration to
687688
use when building, if not overridden by custom schemes.
689+
suppress_coverage_build: Whether or not to disable coverage builds even
690+
when `CLANG_COVERAGE_MAPPING` is set.
688691
execution_root_file: A `File` containing the absolute path to the Bazel
689692
execution root.
690693
generator_name: The name of the `xcodeproj` generator target.
@@ -749,6 +752,9 @@ def _write_pbxproj_prefix(
749752
# separateIndexBuildOutputBase
750753
args.add(TRUE_ARG if separate_index_build_output_base else FALSE_ARG)
751754

755+
# suppressCoverageBuild
756+
args.add(TRUE_ARG if suppress_coverage_build else FALSE_ARG)
757+
752758
# resolvedRepositoriesFile
753759
args.add(resolved_repositories_file)
754760

xcodeproj/internal/templates/generate_bazel_dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ if [ "$ACTION" == "indexbuild" ]; then
121121
apply_sanitizers=0
122122
elif [ "${ENABLE_PREVIEWS:-}" == "YES" ]; then
123123
readonly config="${BAZEL_CONFIG}_swiftuipreviews"
124-
elif [ "${CLANG_COVERAGE_MAPPING:-}" == YES ]; then
124+
elif [ "${CLANG_COVERAGE_MAPPING:-}" == YES ] && [ "${BAZEL_SUPPRESS_COVERAGE_BUILD:-}" != YES ]; then
125125
# Code coverage build
126126
#
127127
# CLANG_COVERAGE_MAPPING is set to YES when the active scheme's test action has code coverage enabled. It is configured

xcodeproj/internal/templates/generator.BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ xcodeproj(
3131
runner_label = "%runner_label%",
3232
scheme_autogeneration_mode = "%scheme_autogeneration_mode%",
3333
scheme_autogeneration_config = %scheme_autogeneration_config%,
34+
suppress_coverage_build = %suppress_coverage_build%,
3435
separate_index_build_output_base = %separate_index_build_output_base%,
3536
storekit_configurations_map = %storekit_configurations_map%,
3637
tags = %tags%,

0 commit comments

Comments
 (0)