Skip to content

Commit 69b13be

Browse files
nglevinluispadron
authored andcommitted
Remove ctx.fragments.objc.uses_device_debug_entitlements and clean up the docs a bit to clarify the exact scope of what the relevant helper in entitlements_support.bzl does.
Cherry-pick: 7866ee3
1 parent b1b1343 commit 69b13be

File tree

4 files changed

+82
-12
lines changed

4 files changed

+82
-12
lines changed

apple/internal/entitlements_support.bzl

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,28 @@ def _new_entitlements_artifact(*, actions, extension, label_name):
8181
"entitlements/%s%s" % (label_name, extension),
8282
)
8383

84-
def _include_debug_entitlements(*, platform_prerequisites):
85-
"""Returns a value indicating whether debug entitlements should be used.
84+
def _force_debug_entitlements(*, platform_prerequisites):
85+
"""Returns a value indicating whether the `get-task-allow` debug entitlements should be forced.
8686
87-
Debug entitlements are used if the --device_debug_entitlements command-line
88-
option indicates that they should be included.
87+
Debug entitlements are not forced on macOS at this level, regardless of the
88+
apple.add_debugger_entitlement define.
8989
90-
Debug entitlements are also not used on macOS.
90+
Debug entitlements are forced if the apple.add_debugger_entitlement define indicates that they
91+
should be included, and if it is not present, they are not.
92+
93+
Note however that if `get-task-allow` is in the provisioning profile, `get-task-allow` will
94+
still be included in the evaluated entitlements file for code signing even if this function
95+
returns False, on account of plisttool's behavior.
96+
97+
Therefore, the ONLY practical effect of this function is to allow for debugging simulator
98+
targets that don't have provisioning profiles assigned if apple.add_debugger_entitlement is set
99+
to True.
91100
92101
Args:
93102
platform_prerequisites: Struct containing information on the platform being targeted.
94103
95104
Returns:
96-
True if the debug entitlements should be included, otherwise False.
105+
True if the `get-task-allow` debug entitlements should be forced, otherwise False.
97106
"""
98107
if platform_prerequisites.platform_type == apple_common.platform_type.macos:
99108
return False
@@ -104,9 +113,13 @@ def _include_debug_entitlements(*, platform_prerequisites):
104113
)
105114
if add_debugger_entitlement != None:
106115
return add_debugger_entitlement
107-
if not platform_prerequisites.objc_fragment.uses_device_debug_entitlements:
108-
return False
109-
return True
116+
117+
# TODO: b/473768498 - Consider if this should return True for the simulator with no provisioning
118+
# profile case that needs to be handled here, and if we can entirely drop the
119+
# apple.add_debugger_entitlement define support above in favor of that simplification. One means
120+
# would be to have an explicit "if not device -> return True else False" as the entire
121+
# implementation of this function.
122+
return False
110123

111124
def _include_app_clip_entitlements(*, product_type):
112125
"""Returns a value indicating whether app clip entitlements should be used.
@@ -268,7 +281,7 @@ def _process_entitlements(
268281
forced_plists = []
269282
if signing_info.entitlements:
270283
plists.append(signing_info.entitlements)
271-
if _include_debug_entitlements(platform_prerequisites = platform_prerequisites):
284+
if _force_debug_entitlements(platform_prerequisites = platform_prerequisites):
272285
get_task_allow = {"get-task-allow": True}
273286
forced_plists.append(struct(**get_task_allow))
274287
if _include_app_clip_entitlements(product_type = product_type):
@@ -351,7 +364,7 @@ def _process_entitlements(
351364
)
352365

353366
simulator_entitlements = None
354-
if _include_debug_entitlements(platform_prerequisites = platform_prerequisites):
367+
if _force_debug_entitlements(platform_prerequisites = platform_prerequisites):
355368
simulator_entitlements = actions.declare_file(
356369
"%s_entitlements.simulator.entitlements" % rule_label.name,
357370
)

test/ios_application_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function test_pkginfo_contents() {
233233
# Helper to test different values if a build adds the debugger entitlement.
234234
# First arg is "y|n" if provisioning profile should contain debugger entitlement
235235
# Second arg is "y|n" if debugger entitlement should be contained on signed app
236-
# Third arg is "y|n" if `_include_debug_entitlements` is `True` (mainly `--define=apple.add_debugger_entitlement=yes`)
236+
# Third arg is "y|n" if `_force_debug_entitlements` is `True` (mainly `--define=apple.add_debugger_entitlement=yes`)
237237
# Any other args are passed to `do_build`.
238238
function verify_debugger_entitlements_with_params() {
239239
readonly INCLUDE_DEBUGGER=$1; shift

test/starlark_tests/ios_application_tests.bzl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,49 @@ Found "com.bazel.app.example" which does not match previously defined "com.altba
12801280
tags = [name],
12811281
)
12821282

1283+
# Tests that get-task-allow is not added to the entitlements if no provisioning profile is
1284+
# assigned.
1285+
apple_verification_test(
1286+
name = "{}_no_get_task_allow_entitlements_by_default_simulator_test".format(name),
1287+
build_type = "simulator",
1288+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_minimal_no_provisioning_profile",
1289+
verifier_script = "verifier_scripts/entitlements_key_verifier.sh",
1290+
env = {
1291+
"CHECK_FOR_ABSENT_ENTITLEMENTS": ["True"],
1292+
"ENTITLEMENTS_KEY": ["get-task-allow"],
1293+
},
1294+
tags = [
1295+
name,
1296+
],
1297+
)
1298+
1299+
# Tests that get-task-allow is added to the entitlements if a provisioning profile is assigned
1300+
# that declares get-task-allow.
1301+
apple_verification_test(
1302+
name = "{}_get_task_allow_entitlements_by_default_with_provisioning_profile_device_test".format(name),
1303+
build_type = "device",
1304+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_minimal",
1305+
verifier_script = "verifier_scripts/entitlements_key_verifier.sh",
1306+
env = {
1307+
"ENTITLEMENTS_KEY": ["get-task-allow"],
1308+
},
1309+
tags = [
1310+
name,
1311+
],
1312+
)
1313+
apple_verification_test(
1314+
name = "{}_get_task_allow_entitlements_by_default_with_provisioning_profile_simulator_test".format(name),
1315+
build_type = "simulator",
1316+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_minimal",
1317+
verifier_script = "verifier_scripts/entitlements_key_verifier.sh",
1318+
env = {
1319+
"ENTITLEMENTS_KEY": ["get-task-allow"],
1320+
},
1321+
tags = [
1322+
name,
1323+
],
1324+
)
1325+
12831326
# Test that an app with a compiled binary resource coming from a resource attribute will fail to
12841327
# build and present a user-actionable error message.
12851328
analysis_failure_message_test(

test/starlark_tests/targets_under_test/ios/BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ ios_application(
140140
],
141141
)
142142

143+
ios_application(
144+
name = "app_minimal_no_provisioning_profile",
145+
bundle_id = "com.google.example",
146+
families = ["iphone"],
147+
infoplists = [
148+
"//test/starlark_tests/resources:Info.plist",
149+
],
150+
minimum_os_version = common.min_os_ios.baseline,
151+
tags = common.fixture_tags,
152+
deps = [
153+
"//test/starlark_tests/resources:objc_main_lib",
154+
],
155+
)
156+
143157
xcarchive(
144158
name = "app_minimal.xcarchive",
145159
bundle = ":app_minimal",

0 commit comments

Comments
 (0)