Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/private/output_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def _output_files(ctx):
files_list = files_depset.to_list()

for path in ctx.attr.paths:
file = _find_short_path_in_files_list(files_list, path)
# Find the input path in the list of the files for the requested depset
# 1. Match by short file
# 2. Fall back to matching based on the reconstructed execution path, for cases like external repositories
# where short_path ends up containing the canonical repo name.
file = _find_short_path_in_files_list(files_list, path) or _find_execution_path_in_files_list(ctx, files_list, path)
if not file:
if ctx.attr.output_group:
msg = "%s file not found within the %s output group of %s" % (path, ctx.attr.output_group, ctx.attr.target)
Expand Down Expand Up @@ -86,3 +90,22 @@ def _find_short_path_in_files_list(files_list, short_path):
if file.short_path == short_path:
return file
return None

def _find_execution_path_in_files_list(ctx, files_list, path):
"""Helper function find a file in a DefaultInfo by reconstructing the execution path

Args:
files_list: a list of files
path: the execution path to search for
Returns:
The File if found else None
"""
for file in files_list:
# The `path` can be different depending on whether the file is generated (which will include bin_dir)
# or in the source (which will not)
if file.path in (
"/".join([ctx.bin_dir.path, ctx.attr.target.label.workspace_root, path]),
"/".join([ctx.attr.target.label.workspace_root, path]),
):
return file
Comment on lines +103 to +110

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match external source files, not just bin outputs

The new fallback reconstructs a path under ctx.bin_dir.path, then compares it to file.path. That only works for generated outputs in the bin tree. For external repos that expose source files via DefaultInfo (e.g., filegroup(srcs = glob(...)) in an http_archive), file.path is under external/<repo>/... with no bazel-out/.../bin prefix, so this fallback still never matches and output_files continues to fail for the common “external repo sources” case the change is targeting. You likely need an additional check against the workspace-root execution path (or other roots) so source files can be found too.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's indeed true (I've manually confirmed). Even though it looks like a less likely use case, I see no reason not to cover it as well, I fixed it on a second commit.

return None