@@ -71,20 +71,28 @@ def _codesignopts_from_rule_ctx(ctx):
7171 for opt in ctx .attr .codesignopts
7272 ]
7373
74- def _preferred_codesigning_identity (platform_prerequisites ):
75- """Returns the preferred codesigning identity from platform prerequisites"""
76- if not platform_prerequisites .platform .is_device :
74+ def _preferred_codesigning_identity (
75+ * ,
76+ build_settings ,
77+ objc_fragment ,
78+ requires_adhoc_signing ):
79+ """Returns the preferred codesigning identity from platform prerequisites.
80+
81+ Args:
82+ build_settings: The build settings from apple_xplat_toolchain_info or platform_prerequisites.
83+ objc_fragment: The objc fragment interface from ctx.fragments.objc.
84+ requires_adhoc_signing: Whether this signing operation requires adhoc signing with the adhoc
85+ pseudo identity. i.e. if this is a simulator build.
86+ """
87+ if requires_adhoc_signing :
7788 return _ADHOC_PSEUDO_IDENTITY
78- build_settings = platform_prerequisites .build_settings
7989 if build_settings :
80- objc_fragment = platform_prerequisites .objc_fragment
8190 if objc_fragment :
8291 # TODO(b/252873771): Remove this fallback when the native Bazel flag
8392 # ios_signing_cert_name is removed.
8493 return (build_settings .signing_certificate_name or
8594 objc_fragment .signing_certificate_name )
86- else :
87- return build_settings .signing_certificate_name
95+ return build_settings .signing_certificate_name
8896 return None
8997
9098def _codesign_args_for_path (
@@ -131,7 +139,11 @@ def _codesign_args_for_path(
131139
132140 # First, try to use the identity passed on the command line, if any. If it's a simulator build,
133141 # use an ad hoc identity.
134- identity = _preferred_codesigning_identity (platform_prerequisites )
142+ identity = _preferred_codesigning_identity (
143+ build_settings = platform_prerequisites .build_settings ,
144+ objc_fragment = platform_prerequisites .objc_fragment ,
145+ requires_adhoc_signing = not platform_prerequisites .platform .is_device ,
146+ )
135147 if not identity :
136148 if provisioning_profile :
137149 cmd_codesigning .extend ([
@@ -294,10 +306,12 @@ def _should_sign_simulator_bundles(
294306 """Check if a main bundle should be codesigned.
295307
296308 Args:
309+ config_vars: The config_vars from `ctx.var`.
310+ features: List of features enabled by the user. Typically from `ctx.features`.
311+ rule_descriptor: A rule descriptor for platform and product types from the rule context.
297312
298313 Returns:
299314 True/False for if the bundle should be signed.
300-
301315 """
302316 if "apple.codesign_simulator_bundles" in config_vars :
303317 # buildifier: disable=print
@@ -348,16 +362,16 @@ def _codesigning_args(
348362 """Returns a set of codesigning arguments to be passed to the codesigning tool.
349363
350364 Args:
351- entitlements: The entitlements file to sign with. Can be None.
352- features: List of features enabled by the user. Typically from `ctx.features`.
353- full_archive_path: The full path to the codesigning target.
354- is_framework: If the target is a framework. False by default.
355- platform_prerequisites: Struct containing information on the platform being targeted.
356- provisioning_profile: File for the provisioning profile.
357- rule_descriptor: A rule descriptor for platform and product types from the rule context.
365+ entitlements: The entitlements file to sign with. Can be None.
366+ features: List of features enabled by the user. Typically from `ctx.features`.
367+ full_archive_path: The full path to the codesigning target.
368+ is_framework: If the target is a framework. False by default.
369+ platform_prerequisites: Struct containing information on the platform being targeted.
370+ provisioning_profile: File for the provisioning profile.
371+ rule_descriptor: A rule descriptor for platform and product types from the rule context.
358372
359373 Returns:
360- A list containing the arguments to pass to the codesigning tool.
374+ A list containing the arguments to pass to the codesigning tool.
361375 """
362376 should_sign_bundles = _should_sign_bundles (
363377 provisioning_profile = provisioning_profile ,
@@ -479,30 +493,39 @@ def _codesigning_command(
479493 )
480494
481495def _generate_codesigning_dossier_action (
496+ * ,
482497 actions ,
483- label_name ,
498+ apple_fragment ,
499+ codesign_identity ,
484500 dossier_codesigningtool ,
485501 embedded_dossiers ,
486502 entitlements ,
487503 output_discriminator ,
488504 output_dossier ,
489- platform_prerequisites ,
490- provisioning_profile ):
505+ label_name ,
506+ provisioning_profile ,
507+ target_signs_with_entitlements ,
508+ xcode_config ):
491509 """Generates a codesigning dossier based on parameters.
492510
493511 Args:
494512 actions: The actions provider from `ctx.actions`.
495- label_name: Name of the target being built.
513+ apple_fragment: The apple fragment from `ctx.fragments.apple` to use for the action.
514+ codesign_identity: The identity for the dossier to sign with.
496515 dossier_codesigningtool: The files_to_run for the code signing tool.
497516 embedded_dossiers: An optional List of Structs generated from
498517 `embedded_codesigning_dossier` that should also be included in this
499518 dossier.
500519 entitlements: Optional file representing the entitlements to sign with.
501520 output_discriminator: A string to differentiate between different target intermediate files
502521 or `None`.
503- output_dossier: The `File` representing the output dossier file - the zipped dossier will be placed here.
504- platform_prerequisites: Struct containing information on the platform being targeted.
522+ output_dossier: The `File` representing the output dossier file - the zipped dossier will be
523+ placed here.
524+ label_name: Name of the target being built.
505525 provisioning_profile: The provisioning profile file. May be `None`.
526+ target_signs_with_entitlements: Whether the target platform needs signing with entitlements,
527+ which is true for non-simulator builds.
528+ xcode_config: The `apple_common.XcodeVersionConfig` provider from the context.
506529 """
507530 input_files = [x .dossier_file for x in embedded_dossiers ]
508531
@@ -511,16 +534,15 @@ def _generate_codesigning_dossier_action(
511534
512535 dossier_arguments = ["--output" , output_dossier .path , "--zip" ]
513536
514- # Try to use the identity passed on the command line, if any. If it's a simulator build, use an
515- # ad hoc identity.
516- codesign_identity = _preferred_codesigning_identity (platform_prerequisites )
537+ # Try to use the identity passed through, if any. Use the ad-hoc pseudo-identity if no identity
538+ # or provisioning profile is passed through.
517539 if not codesign_identity and not provisioning_profile :
518540 codesign_identity = _ADHOC_PSEUDO_IDENTITY
519541 if codesign_identity :
520542 dossier_arguments .extend (["--codesign_identity" , codesign_identity ])
521543 else :
522544 dossier_arguments .append ("--infer_identity" )
523- if entitlements and platform_prerequisites . platform . is_device :
545+ if entitlements and target_signs_with_entitlements :
524546 # Entitlements are embedded as segments of the linked simulator binary. They should not be
525547 # used for signing simulator binaries.
526548 input_files .append (entitlements )
@@ -559,14 +581,14 @@ def _generate_codesigning_dossier_action(
559581
560582 apple_support .run (
561583 actions = actions ,
562- apple_fragment = platform_prerequisites . apple_fragment ,
584+ apple_fragment = apple_fragment ,
563585 arguments = args ,
564586 executable = dossier_codesigningtool ,
565587 inputs = input_files ,
566588 mnemonic = mnemonic ,
567589 outputs = [output_dossier ],
568590 progress_message = progress_message ,
569- xcode_config = platform_prerequisites . xcode_version_config ,
591+ xcode_config = xcode_config ,
570592 )
571593
572594def _post_process_and_sign_archive_action (
@@ -826,6 +848,7 @@ codesigning_support = struct(
826848 embedded_codesigning_dossier = _embedded_codesigning_dossier ,
827849 generate_codesigning_dossier_action = _generate_codesigning_dossier_action ,
828850 post_process_and_sign_archive_action = _post_process_and_sign_archive_action ,
851+ preferred_codesigning_identity = _preferred_codesigning_identity ,
829852 should_sign_bundles = _should_sign_bundles ,
830853 sign_binary_action = _sign_binary_action ,
831854)
0 commit comments