Skip to content

Commit

Permalink
Preserve ArtifactInfo when using selective_debugging.
Browse files Browse the repository at this point in the history
Summary:
When focused debugging is enabled we "scrub" the binary and filter the `ArtifactTSet` to only include
a subset of target's debug artifacts. When we are done filtering we don't rebuild our tset, we make a single node that has all the children of all
the targets in the apple_binary.

This causes downstream failures to `debug_artifacts_validators` because the TSet not only looks different, but, the corresponding `.label`
to the artifacts has changed, which requires users to maintain multiple "allowlists" based on the build config.

Instead, preserve the entire `ArtifactInfo` for debug info we want to keep. This makes the `label` corresponding to debug artifacts stay the same
whether we are in focused debugging or not.

Reviewed By: chatura-atapattu

Differential Revision: D65238543

fbshipit-source-id: 60d9a6bb450e200369eab5bbcc017e3e90bd5b2d
  • Loading branch information
Dustin Shahidehpour authored and facebook-github-bot committed Oct 31, 2024
1 parent a42ba51 commit 36ebb2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 6 additions & 2 deletions prelude/apple/apple_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,20 @@ def _maybe_scrub_binary(ctx, binary_dep: Dependency) -> AppleBundleBinaryOutput:
filtered_external_debug_info = make_artifact_tset(
actions = ctx.actions,
label = ctx.label,
artifacts = flatten(filtered_debug_info.map.values()),
infos = filtered_debug_info.infos,
)

binary = _scrub_binary(ctx, binary, binary_dep.get(LinkExecutionPreferenceInfo), filtered_debug_info.swift_modules_labels)
dsym_artifact = _get_scrubbed_binary_dsym(ctx, binary, debug_info_tset)

filtered_map = {}
for info in filtered_debug_info.infos:
filtered_map.setdefault(info.label, []).extend(info.artifacts)

debuggable_info = AppleDebuggableInfo(
dsyms = [dsym_artifact],
debug_info_tset = filtered_external_debug_info,
filtered_map = filtered_debug_info.map,
filtered_map = filtered_map,
selective_metadata = [
AppleSelectiveDebuggableMetadata(
dsym = dsym_artifact,
Expand Down
17 changes: 9 additions & 8 deletions prelude/apple/user/apple_selective_debugging.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

load(
"@prelude//:artifact_tset.bzl",
"ArtifactInfo",
"ArtifactInfoTag",
)
load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolsInfo")
Expand Down Expand Up @@ -42,7 +43,7 @@ AppleSelectiveDebuggingInfo = provider(
)

AppleSelectiveDebuggingFilteredDebugInfo = record(
map = field(dict[Label, list[Artifact]]),
infos = field(list[ArtifactInfo]),
swift_modules_labels = field(list[Label]),
metadata = field(Artifact),
)
Expand Down Expand Up @@ -181,7 +182,7 @@ def _apple_selective_debugging_impl(ctx: AnalysisContext) -> list[Provider]:
return output

def filter_debug_info(inner_ctx: AnalysisContext, debug_info: TransitiveSetIterator) -> AppleSelectiveDebuggingFilteredDebugInfo:
map = {}
artifact_infos = []
linked_targets = set()
is_any_selected_target_linked = False
is_using_spec = (json_type == _SelectiveDebuggingJsonType("spec"))
Expand Down Expand Up @@ -217,11 +218,7 @@ def _apple_selective_debugging_impl(ctx: AnalysisContext) -> list[Provider]:
if is_label_included or (selected_targets_contain_swift and is_swift_related):
# There might be a few ArtifactInfo corresponding to the same Label,
# so to avoid overwriting, we need to preserve all artifacts.
if info.label in map:
map[info.label] += info.artifacts
else:
map[info.label] = list(info.artifacts)

artifact_infos.append(info)
selected_targets_contain_swift = selected_targets_contain_swift or ArtifactInfoTag("swiftmodule") in info.tags

if json_type == _SelectiveDebuggingJsonType("spec"):
Expand Down Expand Up @@ -258,7 +255,11 @@ def _apple_selective_debugging_impl(ctx: AnalysisContext) -> list[Provider]:
else:
fail("Unexpected type: {}".format(json_type))

return AppleSelectiveDebuggingFilteredDebugInfo(map = map, swift_modules_labels = [], metadata = metadata_output)
return AppleSelectiveDebuggingFilteredDebugInfo(
infos = artifact_infos,
swift_modules_labels = [],
metadata = metadata_output,
)

def preference_for_links(links: list[Label], deps_preferences: list[LinkExecutionPreferenceInfo]) -> LinkExecutionPreference:
# If any dependent links were run locally, prefer that the current link is also performed locally,
Expand Down

0 comments on commit 36ebb2f

Please sign in to comment.