Remap relative bin-dir prefix for file!() and log macros#4017
Open
tamasvajk wants to merge 2 commits into
Open
Remap relative bin-dir prefix for file!() and log macros#4017tamasvajk wants to merge 2 commits into
file!() and log macros#4017tamasvajk wants to merge 2 commits into
Conversation
f0549c1 to
d784ae6
Compare
When transform_sources() symlinks sources into bazel-out/<config>/bin/,
file!(), Location::caller(), and tracing/log macros embed the literal
relative path rustc received on the command line. The existing ${pwd}
remap only matches absolute paths in debug info.
Add a second --remap-path-prefix for the relative bazel-out/<config>/bin/
prefix (without ${pwd}) so these compile-time paths are also clean.
Add analysis tests verifying the flag is present for generated sources
and absent for plain sources, plus a runtime test confirming file!()
returns a clean path.
d784ae6 to
022e197
Compare
Use add_all with the crate root File and a map_each callback instead of a hardcoded ctx.bin_dir.path string. This lets Bazel's path mapping rewrite the config portion of the bin-dir prefix (e.g. k8-fastbuild -> cfg), so the remap flag matches the actual source file path at execution time.
1ca326c to
905bedc
Compare
Contributor
Author
|
@UebelAndre Could you please take a look at this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion to #4016. While #4016 fixes
--remap-path-prefixfor absolute paths in debug info (backtraces, panic locations), this PR adds a remap for the relativebazel-out/<config>/bin/prefix so thatfile!(),Location::caller(), and tracing/log macros also produce clean workspace-relative paths when sources are symlinked bytransform_sources().Problem
When a target mixes generated and non-generated sources,
transform_sources()symlinks all source files intobazel-out/<config>/bin/.... The existing--remap-path-prefix=${pwd}=.only affects absolute paths embedded in debug info. However,file!(),Location::caller(), and log macros embed the literal relative path that rustc received on the command line. These are not matched by the${pwd}remap, so they produce paths like:instead of:
Fix
When
crate_info.root.is_sourceis False (symlinked sources), add a second remap that strips the relative bin-dir prefix:This complements the existing absolute-path remaps and ensures compile-time paths are also clean.
Tests
file!()and a test asserts the returned path does not containbazel-out.