Skip to content

Commit

Permalink
Use runfiles.merge_all() to reduce depset depth. This is recommende…
Browse files Browse the repository at this point in the history
…d at https://bazel.build/rules/lib/builtins/runfiles.html#merge for efficiency.

PiperOrigin-RevId: 712957429
Change-Id: I97779201ad561ead9bebc27d6c13cd58dc307dcc
  • Loading branch information
A Googler authored and copybara-github committed Jan 7, 2025
1 parent 78e3a91 commit 4d8487c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rules/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -298,21 +298,21 @@ def _dedupe_split_attr(attr):
return attr[arch]

def _get_runfiles(ctx, attrs):
runfiles = ctx.runfiles()
all_runfiles = []
for attr in attrs:
executable = attr[DefaultInfo].files_to_run.executable
if executable:
runfiles = runfiles.merge(ctx.runfiles([executable]))
runfiles = runfiles.merge(
all_runfiles.append(ctx.runfiles([executable]))
all_runfiles.append(
ctx.runfiles(
# Wrap DefaultInfo.files in depset to strip ordering.
transitive_files = depset(
transitive = [attr[DefaultInfo].files],
),
),
)
runfiles = runfiles.merge(attr[DefaultInfo].default_runfiles)
return runfiles
all_runfiles.append(attr[DefaultInfo].default_runfiles)
return ctx.runfiles().merge_all(all_runfiles)

def _sanitize_string(s, replacement = ""):
"""Sanitizes a string by replacing all non-word characters.
Expand Down

0 comments on commit 4d8487c

Please sign in to comment.