Skip to content

Commit 1f30678

Browse files
author
Tamas Vajk
committed
Fix rustfmt silently skipping symlinked sources
When transform_sources() symlinks hand-written .rs files into bazel-out (which happens when any compile_data entry is generated), the symlinked files are no longer is_source=True. This causes _find_rustfmtable_srcs to filter them all out, silently skipping formatting for the entire crate. Fix by recovering original source files from the aspect context's rule attributes when available. Also use crate_info.srcs directly in rustfmt_test to include all sources.
1 parent f31db8b commit 1f30678

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

rust/private/rustfmt.bzl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ def _find_rustfmtable_srcs(crate_info, aspect_ctx = None):
4747
if tag.replace("-", "_").lower() in ignore_tags:
4848
return []
4949

50-
# Filter out any generated files
50+
# Filter out generated files, but recover hand-written sources that were
51+
# symlinked into bazel-out by transform_sources() (which happens when any
52+
# compile_data entry is generated). Return the original source File objects
53+
# so that exec_path and short_path remain correct for manifests and runfiles.
54+
if aspect_ctx and hasattr(aspect_ctx.rule.attr, "srcs"):
55+
original_srcs = []
56+
for target in aspect_ctx.rule.attr.srcs:
57+
for f in target.files.to_list():
58+
if f.is_source:
59+
original_srcs.append(f)
60+
if original_srcs:
61+
return original_srcs
62+
5163
srcs = [src for src in crate_info.srcs.to_list() if src.is_source]
5264

5365
return srcs
@@ -219,7 +231,7 @@ def _rustfmt_test_impl(ctx):
219231
)
220232

221233
crate_infos = [_get_rustfmt_ready_crate_info(target) for target in ctx.attr.targets]
222-
srcs = [depset(_find_rustfmtable_srcs(crate_info)) for crate_info in crate_infos if crate_info]
234+
srcs = [crate_info.srcs for crate_info in crate_infos if crate_info]
223235

224236
# Some targets may be included in tests but tagged as "no-format". In this
225237
# case, there will be no manifest.

0 commit comments

Comments
 (0)