@@ -22,11 +22,14 @@ load(
2222 "@bazel_skylib//lib:paths.bzl" ,
2323 "paths" ,
2424)
25+ load (
26+ "@bazel_skylib//lib:shell.bzl" ,
27+ "shell" ,
28+ )
2529load (
2630 "@build_bazel_apple_support//lib:apple_support.bzl" ,
2731 "apple_support" ,
2832)
29- load ("@build_bazel_apple_support//lib:lipo.bzl" , "lipo" )
3033load (
3134 "//apple:providers.bzl" ,
3235 "AppleBundleVersionInfo" ,
5457 "defines" ,
5558)
5659
60+ visibility ("//apple/..." )
61+
5762def _declare_linkmap (
5863 * ,
5964 actions ,
@@ -107,13 +112,12 @@ def _collect_linkmaps(
107112
108113 return outputs
109114
110- def _generate_dsym_binaries (
115+ def _copy_dsyms_into_declared_bundle (
111116 * ,
112117 actions ,
113118 debug_output_filename ,
114119 dsym_bundle_name ,
115- found_binaries_by_arch ,
116- platform_prerequisites ):
120+ found_binaries_by_arch ):
117121 """Declares the dSYM binary file and copies it into the preferred .dSYM bundle location.
118122
119123 Args:
@@ -124,22 +128,25 @@ def _generate_dsym_binaries(
124128 dsym_bundle_name: The full name of the dSYM bundle, including its extension.
125129 found_binaries_by_arch: A mapping of architectures to Files representing dsym binary outputs
126130 for each architecture.
127- platform_prerequisites: Struct containing information on the platform being targeted.
128131
129132 Returns:
130133 A list of Files representing the copied dSYM binary which is located in the preferred .dSYM
131134 bundle locations.
132135 """
133- output_binary = actions .declare_file (
134- "%s/Contents/Resources/DWARF/%s" % (
135- dsym_bundle_name ,
136+ output_binaries = []
137+
138+ for arch , dsym_binary in found_binaries_by_arch .items ():
139+ output_relpath = "Contents/Resources/DWARF/%s_%s" % (
136140 debug_output_filename ,
137- ) ,
138- )
141+ arch ,
142+ )
139143
140- # Copy the binary over if there's only a single arch.
141- if len (found_binaries_by_arch ) == 1 :
142- dsym_binary = found_binaries_by_arch .values ()[0 ]
144+ output_binary = actions .declare_file (
145+ "%s/%s" % (
146+ dsym_bundle_name ,
147+ output_relpath ,
148+ ),
149+ )
143150
144151 # cp instead of symlink here because a dSYM with a symlink to the DWARF data will not be
145152 # recognized by spotlight which is key for lldb on mac to find a dSYM for a binary.
159166cp $flags "{src}" "{dst}"
160167""" .format (src = dsym_binary .path , dst = output_binary .path ),
161168 )
162- else :
163- lipo .create (
164- actions = actions ,
165- apple_fragment = platform_prerequisites .apple_fragment ,
166- inputs = found_binaries_by_arch .values (),
167- output = output_binary ,
168- xcode_config = platform_prerequisites .xcode_version_config ,
169- )
170169
171- return [output_binary ]
170+ output_binaries .append (output_binary )
171+
172+ return output_binaries
173+
174+ def _lipo_command_for_dsyms (
175+ * ,
176+ debug_output_filename ,
177+ found_binaries_by_arch ):
178+ """Returns a shell command to invoke lipo against all provided dSYMs for a given bundle.
179+
180+ Args:
181+ debug_output_filename: The base file name to use for this debug output, which will be followed
182+ by the architecture with an underscore to make the dSYM binary file name or with the bundle
183+ extension following it for the dSYM bundle file name.
184+ found_binaries_by_arch: A mapping of architectures to Files representing dsym binary outputs
185+ for each architecture.
186+
187+ Returns:
188+ A String representing the shell command to invoke lipo, referencing an OUTPUT_DIR shell
189+ variable that is expected to represent the dSYM bundle root.
190+ """
191+ found_binary_paths = []
192+
193+ for dsym_binary in found_binaries_by_arch .values ():
194+ found_binary_paths .append (dsym_binary .path )
195+
196+ lipo_command = (
197+ "/usr/bin/lipo " +
198+ "-create {found_binary_inputs} " +
199+ "-output \" ${{OUTPUT_DIR}}/Contents/Resources/DWARF/{debug_output_filename}\" "
200+ ).format (
201+ found_binary_inputs = " " .join ([shell .quote (path ) for path in found_binary_paths ]),
202+ debug_output_filename = debug_output_filename ,
203+ )
204+
205+ return lipo_command
172206
173207def _generate_dsym_info_plist (
174208 actions ,
175209 dsym_bundle_name ,
176210 dsym_info_plist_template ,
211+ mac_exec_group ,
177212 output_discriminator ,
178213 platform_prerequisites ,
179214 plisttool ,
@@ -185,6 +220,7 @@ def _generate_dsym_info_plist(
185220 actions: The actions provider from `ctx.actions`.
186221 dsym_bundle_name: The full name of the dSYM bundle, including its extension.
187222 dsym_info_plist_template: File referencing a plist template for dSYM bundles.
223+ mac_exec_group: The exec_group associated with plisttool.
188224 output_discriminator: A string to differentiate between different target intermediate files
189225 or `None`.
190226 platform_prerequisites: Struct containing information on the platform being targeted.
@@ -237,6 +273,7 @@ def _generate_dsym_info_plist(
237273 actions = actions ,
238274 control_file = control_file ,
239275 inputs = plisttool_input_files ,
276+ mac_exec_group = mac_exec_group ,
240277 mnemonic = "CompileDSYMInfoPlist" ,
241278 outputs = [dsym_plist ],
242279 platform_prerequisites = platform_prerequisites ,
@@ -251,7 +288,7 @@ def _bundle_dsym_files(
251288 debug_output_filename ,
252289 dsym_binaries = {},
253290 dsym_info_plist_template ,
254- dsym_output_filename ,
291+ mac_exec_group ,
255292 label_name ,
256293 output_discriminator ,
257294 platform_prerequisites ,
@@ -276,7 +313,7 @@ def _bundle_dsym_files(
276313 dsym_binaries: A mapping of architectures to Files representing dSYM binary outputs for each
277314 architecture.
278315 dsym_info_plist_template: File referencing a plist template for dSYM bundles.
279- dsym_output_filename : The dSYM binary file name .
316+ mac_exec_group : The exec_group associated with plisttool .
280317 label_name: The name of the target.
281318 output_discriminator: A string to differentiate between different target intermediate files
282319 or `None`.
@@ -305,28 +342,24 @@ def _bundle_dsym_files(
305342 found_binaries_by_arch .update (dsym_binaries )
306343
307344 if found_binaries_by_arch :
308- generated_dsym_binaries = _generate_dsym_binaries (
345+ output_files = _copy_dsyms_into_declared_bundle (
309346 actions = actions ,
310- debug_output_filename = dsym_output_filename ,
347+ debug_output_filename = debug_output_filename ,
311348 dsym_bundle_name = dsym_bundle_name ,
312349 found_binaries_by_arch = found_binaries_by_arch ,
313- platform_prerequisites = platform_prerequisites ,
314350 )
315- output_files .extend (generated_dsym_binaries )
316- dsyms_command = (" && " .join ([
317- "cp \" {dsym_path}\" \" ${{OUTPUT_DIR}}/Contents/Resources/DWARF/{dsym_bundle_name}\" " .format (
318- dsym_path = dsym_binary .path ,
319- dsym_bundle_name = dsym_output_filename ,
320- )
321- for dsym_binary in generated_dsym_binaries
322- ]))
351+ lipo_command = _lipo_command_for_dsyms (
352+ debug_output_filename = debug_output_filename ,
353+ found_binaries_by_arch = found_binaries_by_arch ,
354+ )
323355
324356 # If we found any binaries, create the Info.plist for the bundle as well.
325357 dsym_plist = _generate_dsym_info_plist (
326358 actions = actions ,
327359 dsym_bundle_name = dsym_bundle_name ,
328360 dsym_info_plist_template = dsym_info_plist_template ,
329361 output_discriminator = output_discriminator ,
362+ mac_exec_group = mac_exec_group ,
330363 platform_prerequisites = platform_prerequisites ,
331364 plisttool = plisttool ,
332365 rule_label = rule_label ,
@@ -344,9 +377,10 @@ def _bundle_dsym_files(
344377 apple_support .run_shell (
345378 actions = actions ,
346379 apple_fragment = platform_prerequisites .apple_fragment ,
347- inputs = generated_dsym_binaries + [dsym_plist ] + found_binaries_by_arch .values (),
380+ inputs = [dsym_plist ] + found_binaries_by_arch .values (),
348381 outputs = [dsym_bundle_dir ],
349- command = ("mkdir -p \" ${OUTPUT_DIR}/Contents/Resources/DWARF\" && " + dsyms_command + " && " + plist_command ),
382+ command = ("mkdir -p \" ${OUTPUT_DIR}/Contents/Resources/DWARF\" && " + lipo_command +
383+ " && " + plist_command ),
350384 env = {
351385 "OUTPUT_DIR" : dsym_bundle_dir .path ,
352386 },
@@ -365,9 +399,9 @@ def _debug_symbols_partial_impl(
365399 debug_discriminator = None ,
366400 dsym_binaries = {},
367401 dsym_info_plist_template ,
368- executable_name = None ,
369402 label_name ,
370403 linkmaps = {},
404+ mac_exec_group ,
371405 output_discriminator = None ,
372406 platform_prerequisites ,
373407 plisttool ,
@@ -408,16 +442,13 @@ def _debug_symbols_partial_impl(
408442
409443 if platform_prerequisites .cpp_fragment :
410444 if platform_prerequisites .cpp_fragment .apple_generate_dsym :
411- dsym_output_filename = executable_name or bundle_name
412- if debug_discriminator :
413- dsym_output_filename += "_" + debug_discriminator
414445 dsym_files , dsym_bundle_dir = _bundle_dsym_files (
415446 actions = actions ,
416447 bundle_extension = bundle_extension ,
417448 debug_output_filename = debug_output_filename ,
418449 dsym_binaries = dsym_binaries ,
419450 dsym_info_plist_template = dsym_info_plist_template ,
420- dsym_output_filename = dsym_output_filename ,
451+ mac_exec_group = mac_exec_group ,
421452 label_name = label_name ,
422453 output_discriminator = output_discriminator ,
423454 platform_prerequisites = platform_prerequisites ,
@@ -495,9 +526,9 @@ def debug_symbols_partial(
495526 debug_discriminator = None ,
496527 dsym_binaries = {},
497528 dsym_info_plist_template ,
498- executable_name = None ,
499529 label_name ,
500530 linkmaps = {},
531+ mac_exec_group ,
501532 output_discriminator = None ,
502533 platform_prerequisites ,
503534 plisttool ,
@@ -523,9 +554,9 @@ def debug_symbols_partial(
523554 dsym_binaries: A mapping of architectures to Files representing dsym binary outputs for each
524555 architecture.
525556 dsym_info_plist_template: File referencing a plist template for dSYM bundles.
526- executable_name: The name of the output DWARF executable.
527557 label_name: The name of the target.
528558 linkmaps: A mapping of architectures to Files representing linkmaps for each architecture.
559+ mac_exec_group: The exec_group associated with plisttool.
529560 output_discriminator: A string to differentiate between different target intermediate files
530561 or `None`.
531562 platform_prerequisites: Struct containing information on the platform being targeted.
@@ -545,9 +576,9 @@ def debug_symbols_partial(
545576 debug_discriminator = debug_discriminator ,
546577 dsym_binaries = dsym_binaries ,
547578 dsym_info_plist_template = dsym_info_plist_template ,
548- executable_name = executable_name or bundle_name ,
549579 label_name = label_name ,
550580 linkmaps = linkmaps ,
581+ mac_exec_group = mac_exec_group ,
551582 output_discriminator = output_discriminator ,
552583 platform_prerequisites = platform_prerequisites ,
553584 plisttool = plisttool ,
0 commit comments