rust: doctest: add source map script
Gary Guo
reviewerPATCH v2 1/1 rust: doctest: add source map script
Quite often when updating abstractions there will be some documentation that needs updating, but the build process is not very developer friendly as it just gives out something like "rust/doctests_kernel_generated.rs:12345:42" and it is a hassle to find where the documentation actually is.
Add a script as rustc wrapper, which translates the error message by appending a "(generated from original_file:original_line:col)" message to the original source info emitted by rustc.
This is the result of an example diagnostics:
error: test
--> rust/doctests_kernel_generated.rs:4490:1 (generated from rust/kernel/build_assert.rs:96:1)
|
4490 | compile_error!("test");
| ^^^^^^^^^^^^^^^^^^^^^^---
Changes in v2:
- Fixed SPDX header.
- Detect tty with stderr instead of stdout.
- Match doctest anchors more loosely without hardcoding i32.
- Link to v1: https://patch.msgid.link/[email protected]
--- rust/Makefile | 6 ++++ scripts/rustdoc_test_map_source.py | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+)
rust/Makefile +6 -0
@@ -406,6 +406,12 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $< $(objtree)/scripts/rustdoc_test_gen FORCE +$(call if_changed,rustdoc_test_kernel) +# When building rustdoc tests, instead of using the actual RUSTC_OR_CLIPPY, use a wrapper to build +# so we can convert line number in diagnostics. +ACTUAL_RUSTC := $(RUSTC_OR_CLIPPY) +%/doctests_kernel_generated.o: private RUSTC_OR_CLIPPY = \ + PYTHONDONTWRITEBYTECODE=1 ACTUAL_RUSTC=$(ACTUAL_RUSTC) $(PYTHON3) $(srctree)/scripts/rustdoc_test_map_source.py + # We cannot use `-Zpanic-abort-tests` because some tests are dynamic, # so for the moment we skip `-Cpanic=abort`. quiet_cmd_rustc_test = $(RUSTC_OR_CLIPPY_QUIET) T $<
scripts/rustdoc_test_map_source.py new file +73 -0
73 lines not on this page · raw message
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260903-rustdoc-sourcemap-160f904fe78f
Best regards,
Signature · 1 line
Gary Guo <[email protected]>