Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f2231d5

Browse files
Rollup merge of #143228 - nnethercote:macro-stats-build-scripts, r=Kobzol
Handle build scripts better in `-Zmacro-stats` output. Currently all build scripts are listed as `build_script_build` in the stats header. This commit uses `CARGO_PKG_NAME` to improve that. I tried it on Bevy, it works well, giving output like this on the build script: ``` MACRO EXPANSION STATS: serde build script ``` and this on the crate itself: ``` MACRO EXPANSION STATS: serde ``` r? `@Kobzol`
2 parents 172fc60 + c3c995a commit f2231d5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

‎compiler/rustc_interface/src/passes.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ fn configure_and_expand(
298298
fn print_macro_stats(ecx: &ExtCtxt<'_>) {
299299
use std::fmt::Write;
300300

301+
let crate_name = ecx.ecfg.crate_name.as_str();
302+
let crate_name = if crate_name == "build_script_build" {
303+
// This is a build script. Get the package name from the environment.
304+
let pkg_name =
305+
std::env::var("CARGO_PKG_NAME").unwrap_or_else(|_| "<unknown crate>".to_string());
306+
format!("{pkg_name} build script")
307+
} else {
308+
crate_name.to_string()
309+
};
310+
301311
// No instability because we immediately sort the produced vector.
302312
#[allow(rustc::potential_query_instability)]
303313
let mut macro_stats: Vec<_> = ecx
@@ -327,7 +337,7 @@ fn print_macro_stats(ecx: &ExtCtxt<'_>) {
327337
// non-interleaving, though.
328338
let mut s = String::new();
329339
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
330-
_ = writeln!(s, "{prefix} MACRO EXPANSION STATS: {}", ecx.ecfg.crate_name);
340+
_ = writeln!(s, "{prefix} MACRO EXPANSION STATS: {}", crate_name);
331341
_ = writeln!(
332342
s,
333343
"{prefix} {:<name_w$}{:>uses_w$}{:>lines_w$}{:>avg_lines_w$}{:>bytes_w$}{:>avg_bytes_w$}",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /