Skip to content

Commit b9b3bab

Browse files
nglevinluispadron
authored andcommitted
Update outputs.dsyms(...) to be able to handle the new dsymutil bundle outputs.
Add tests for macos_application and macos_command_line_application. Use build_setting_labels flags to reference dsym_variant_flag in test rules when possible. Cherry-pick: b27541a
1 parent 5a4f2ce commit b9b3bab

File tree

9 files changed

+121
-17
lines changed

9 files changed

+121
-17
lines changed

apple/internal/ios_rules.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@ def _ios_application_impl(ctx):
517517
rule_descriptor = rule_descriptor,
518518
)
519519

520-
dsyms = outputs.dsyms(processor_result = processor_result)
520+
dsyms = outputs.dsyms(
521+
platform_prerequisites = platform_prerequisites,
522+
processor_result = processor_result,
523+
)
521524

522525
return [
523526
# TODO(b/121155041): Should we do the same for ios_framework and ios_extension?

apple/internal/macos_rules.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ def _macos_application_impl(ctx):
436436
predeclared_outputs = predeclared_outputs,
437437
rule_descriptor = rule_descriptor,
438438
)
439-
dsyms = outputs.dsyms(processor_result = processor_result)
439+
dsyms = outputs.dsyms(
440+
platform_prerequisites = platform_prerequisites,
441+
processor_result = processor_result,
442+
)
440443

441444
run_support.register_macos_executable(
442445
actions = actions,
@@ -2092,7 +2095,10 @@ def _macos_command_line_application_impl(ctx):
20922095
if clang_rt_dylibs.should_package_clang_runtime(features = features):
20932096
runfiles = clang_rt_dylibs.get_from_toolchain(ctx)
20942097

2095-
dsyms = outputs.dsyms(processor_result = processor_result)
2098+
dsyms = outputs.dsyms(
2099+
platform_prerequisites = platform_prerequisites,
2100+
processor_result = processor_result,
2101+
)
20962102

20972103
return [
20982104
new_applebinaryinfo(

apple/internal/outputs.bzl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,26 @@ def _executable(*, actions, label_name):
109109
"""Returns a file reference for the executable that would be invoked with `bazel run`."""
110110
return actions.declare_file(label_name)
111111

112-
def _dsyms(*, processor_result):
112+
def _dsyms(*, platform_prerequisites, processor_result):
113113
"""Returns a depset of all of the dsyms from the result."""
114-
dsyms = []
115-
for provider in processor_result.providers:
116-
if getattr(provider, "dsyms", None):
117-
dsyms.append(provider.dsyms)
118-
return depset(transitive = dsyms)
114+
direct_dsyms = []
115+
transitive_dsyms = []
116+
dsym_variant_flag = platform_prerequisites.build_settings.dsym_variant_flag
117+
if dsym_variant_flag == "bundle":
118+
for provider in processor_result.providers:
119+
# Sourcing fields from the public AppleDsymBundleInfo provider.
120+
if getattr(provider, "direct_dsyms", None):
121+
direct_dsyms.extend(provider.direct_dsyms)
122+
if getattr(provider, "transitive_dsyms", None):
123+
transitive_dsyms.append(provider.transitive_dsyms)
124+
elif dsym_variant_flag == "flat":
125+
for provider in processor_result.providers:
126+
# Sourcing fields from the AppleDebugInfo provider, only visible to the rules.
127+
if getattr(provider, "dsyms", None):
128+
transitive_dsyms.append(provider.dsyms)
129+
else:
130+
fail("Internal Error: Unsupported dsym_variant_flag: {}".format(dsym_variant_flag))
131+
return depset(direct_dsyms, transitive = transitive_dsyms)
119132

120133
def _infoplist(*, actions, label_name, output_discriminator):
121134
"""Returns a file reference for this target's Info.plist file."""

apple/internal/testing/apple_test_bundle_support.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,10 @@ def _apple_test_bundle_impl(*, ctx, product_type):
572572
rule_descriptor = rule_descriptor,
573573
)
574574

575-
dsyms = outputs.dsyms(processor_result = processor_result)
575+
dsyms = outputs.dsyms(
576+
platform_prerequisites = platform_prerequisites,
577+
processor_result = processor_result,
578+
)
576579

577580
# The processor outputs has all the extra outputs like dSYM files that we want to propagate, but
578581
# it also includes the archive artifact. This collects all the files that should be output from

apple/internal/visionos_rules.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,10 @@ Resolved Xcode is version {xcode_version}.
453453
rule_descriptor = rule_descriptor,
454454
)
455455

456-
dsyms = outputs.dsyms(processor_result = processor_result)
456+
dsyms = outputs.dsyms(
457+
platform_prerequisites = platform_prerequisites,
458+
processor_result = processor_result,
459+
)
457460

458461
return [
459462
DefaultInfo(

apple/internal/xcframework_rules.bzl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,16 +842,20 @@ def _apple_xcframework_impl(ctx):
842842
# Save a reference to those archives as file-friendly inputs to the bundler action.
843843
framework_archive_files.append(depset([provider.archive]))
844844

845-
# Save the dSYMs.
846-
if getattr(provider, "dsyms", None):
847-
framework_output_files.append(depset(transitive = [provider.dsyms]))
848-
framework_output_groups.append({"dsyms": provider.dsyms})
849-
850845
# Save the linkmaps.
851846
if getattr(provider, "linkmaps", None):
852847
framework_output_files.append(depset(transitive = [provider.linkmaps]))
853848
framework_output_groups.append({"linkmaps": provider.linkmaps})
854849

850+
dsyms = outputs.dsyms(
851+
platform_prerequisites = platform_prerequisites,
852+
processor_result = processor_result,
853+
)
854+
if dsyms:
855+
# Save the dSYMs.
856+
framework_output_files.append(depset(transitive = [dsyms]))
857+
framework_output_groups.append({"dsyms": dsyms})
858+
855859
# Save additional library details for the XCFramework's root info plist.
856860
available_libraries.append(_available_library_dictionary(
857861
architectures = link_output.architectures,

test/starlark_tests/macos_application_tests.bzl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ load(
2020
)
2121
load(
2222
"//test/starlark_tests/rules:analysis_output_group_info_files_test.bzl",
23+
"analysis_output_group_info_dsymutil_bundle_files_test",
2324
"analysis_output_group_info_files_test",
2425
)
2526
load(
2627
"//test/starlark_tests/rules:analysis_runfiles_test.bzl",
2728
"analysis_runfiles_dsym_test",
29+
"analysis_runfiles_dsymutil_bundle_test",
2830
)
2931
load(
3032
"//test/starlark_tests/rules:analysis_target_actions_test.bzl",
3133
"analysis_target_actions_test",
3234
)
3335
load(
3436
"//test/starlark_tests/rules:apple_dsym_bundle_info_test.bzl",
37+
"apple_dsym_bundle_info_dsymutil_bundle_test",
3538
"apple_dsym_bundle_info_test",
3639
)
3740
load(
@@ -275,6 +278,15 @@ def macos_application_test_suite(name):
275278
],
276279
tags = [name],
277280
)
281+
analysis_output_group_info_dsymutil_bundle_files_test(
282+
name = "{}_dsyms_output_group_dsymutil_bundle_files_test".format(name),
283+
target_under_test = "//test/starlark_tests/targets_under_test/macos:app",
284+
output_group_name = "dsyms",
285+
expected_outputs = [
286+
"app.app.dSYM",
287+
],
288+
tags = [name],
289+
)
278290
apple_dsym_bundle_info_test(
279291
name = "{}_dsym_bundle_info_files_test".format(name),
280292
target_under_test = "//test/starlark_tests/targets_under_test/macos:app",
@@ -286,6 +298,17 @@ def macos_application_test_suite(name):
286298
],
287299
tags = [name],
288300
)
301+
apple_dsym_bundle_info_dsymutil_bundle_test(
302+
name = "{}_dsym_bundle_info_dsymutil_bundle_files_test".format(name),
303+
target_under_test = "//test/starlark_tests/targets_under_test/macos:app",
304+
expected_direct_dsyms = [
305+
"app.app.dSYM",
306+
],
307+
expected_transitive_dsyms = [
308+
"app.app.dSYM",
309+
],
310+
tags = [name],
311+
)
289312

290313
analysis_runfiles_dsym_test(
291314
name = "{}_runfiles_dsym_test".format(name),
@@ -297,6 +320,15 @@ def macos_application_test_suite(name):
297320
tags = [name],
298321
)
299322

323+
analysis_runfiles_dsymutil_bundle_test(
324+
name = "{}_runfiles_dsymutil_bundle_test".format(name),
325+
target_under_test = "//test/starlark_tests/targets_under_test/macos:app",
326+
expected_runfiles = [
327+
"third_party/bazel_rules/rules_apple/test/starlark_tests/targets_under_test/macos/darwin_arm64/app.app.dSYM",
328+
],
329+
tags = [name],
330+
)
331+
300332
infoplist_contents_test(
301333
name = "{}_plist_test".format(name),
302334
target_under_test = "//test/starlark_tests/targets_under_test/macos:app",

test/starlark_tests/macos_command_line_application_tests.bzl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
load(
1818
"//test/starlark_tests/rules:analysis_output_group_info_files_test.bzl",
19+
"analysis_output_group_info_dsymutil_bundle_files_test",
1920
"analysis_output_group_info_files_test",
2021
)
2122
load(
2223
"//test/starlark_tests/rules:analysis_runfiles_test.bzl",
2324
"analysis_runfiles_dsym_test",
25+
"analysis_runfiles_dsymutil_bundle_test",
2426
)
2527
load(
2628
"//test/starlark_tests/rules:apple_dsym_bundle_info_test.bzl",
29+
"apple_dsym_bundle_info_dsymutil_bundle_test",
2730
"apple_dsym_bundle_info_test",
2831
)
2932
load(
@@ -162,13 +165,29 @@ def macos_command_line_application_test_suite(name):
162165
],
163166
tags = [name],
164167
)
168+
analysis_output_group_info_dsymutil_bundle_files_test(
169+
name = "{}_dsyms_output_group_dsymutil_bundle_test".format(name),
170+
target_under_test = "//test/starlark_tests/targets_under_test/macos:cmd_app_basic",
171+
output_group_name = "dsyms",
172+
expected_outputs = [
173+
"cmd_app_basic.dSYM",
174+
],
175+
tags = [name],
176+
)
165177
apple_dsym_bundle_info_test(
166178
name = "{}_dsym_bundle_info_files_test".format(name),
167179
target_under_test = "//test/starlark_tests/targets_under_test/macos:cmd_app_basic",
168180
expected_direct_dsyms = ["dSYMs/cmd_app_basic.dSYM"],
169181
expected_transitive_dsyms = ["dSYMs/cmd_app_basic.dSYM"],
170182
tags = [name],
171183
)
184+
apple_dsym_bundle_info_dsymutil_bundle_test(
185+
name = "{}_dsym_bundle_info_dsymutil_bundle_test".format(name),
186+
target_under_test = "//test/starlark_tests/targets_under_test/macos:cmd_app_basic",
187+
expected_direct_dsyms = ["cmd_app_basic.dSYM"],
188+
expected_transitive_dsyms = ["cmd_app_basic.dSYM"],
189+
tags = [name],
190+
)
172191

173192
infoplist_contents_test(
174193
name = "{}_infoplist_test".format(name),
@@ -203,6 +222,15 @@ def macos_command_line_application_test_suite(name):
203222
tags = [name],
204223
)
205224

225+
analysis_runfiles_dsymutil_bundle_test(
226+
name = "{}_runfiles_dsymutil_bundle_test".format(name),
227+
target_under_test = "//test/starlark_tests/targets_under_test/macos:cmd_app_basic",
228+
expected_runfiles = [
229+
"third_party/bazel_rules/rules_apple/test/starlark_tests/targets_under_test/macos/darwin_arm64/cmd_app_basic.dSYM",
230+
],
231+
tags = [name],
232+
)
233+
206234
binary_contents_test(
207235
name = "{}_version_plist_test".format(name),
208236
build_type = "device",

test/starlark_tests/rules/analysis_runfiles_test.bzl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ load(
1919
"analysistest",
2020
"unittest",
2121
)
22+
load(
23+
"//apple/build_settings:build_settings.bzl",
24+
"build_settings_labels",
25+
)
2226

2327
def _analysis_runfiles_test_impl(ctx):
2428
"Test that runfiles of the given target under test is properly set."
@@ -62,7 +66,15 @@ def make_analysis_runfiles_test_rule(
6266
# A generic analysis_runfiles_test with no custom settings.
6367
analysis_runfiles_test = make_analysis_runfiles_test_rule()
6468

65-
# An analysis_runfiles_test that generates dsyms.
69+
# An analysis_runfiles_test that generates "flat file" dSYMs.
6670
analysis_runfiles_dsym_test = make_analysis_runfiles_test_rule(config_settings = {
71+
build_settings_labels.dsym_variant_flag: "flat",
72+
"//command_line_option:apple_generate_dsym": "true",
73+
"//command_line_option:macos_cpus": "arm64",
74+
})
75+
76+
# An analysis_runfiles_test that generates dSYMs bundles using dsymutil.
77+
analysis_runfiles_dsymutil_bundle_test = make_analysis_runfiles_test_rule(config_settings = {
78+
build_settings_labels.dsym_variant_flag: "bundle",
6779
"//command_line_option:apple_generate_dsym": "true",
6880
})

0 commit comments

Comments
 (0)