From 4d7585a7111eb3515fc7772d9b33af1183ed3b65 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 9 Jan 2026 11:23:52 -0500 Subject: [PATCH 1/2] Add `--id` flag to `cargo report timings` and `cargo report rebuilds` This adds the `--id` argument to the CLI definitions but does not yet implement the functionality. The argument is currently accepted but ignored; the commands still use the most recent session by default. This commit also adds tests that verify the current behavior (using the most recent session) in preparation for the next commit which implements the `--id` functionality. --- src/bin/cargo/commands/report.rs | 6 ++- tests/testsuite/cargo_report_rebuilds/mod.rs | 44 +++++++++++++++++ .../cargo_report_timings/help/stdout.term.svg | 32 +++++++------ tests/testsuite/cargo_report_timings/mod.rs | 47 +++++++++++++++++++ 4 files changed, 112 insertions(+), 17 deletions(-) diff --git a/src/bin/cargo/commands/report.rs b/src/bin/cargo/commands/report.rs index e31edb19133..499a208c905 100644 --- a/src/bin/cargo/commands/report.rs +++ b/src/bin/cargo/commands/report.rs @@ -31,7 +31,8 @@ pub fn cli() -> Command { subcommand("timings") .about("Reports the build timings of previous sessions (unstable)") .arg_manifest_path() - .arg(flag("open", "Opens the timing report in a browser")), + .arg(flag("open", "Opens the timing report in a browser")) + .arg(opt("id", "Session ID to report on").value_name("ID")), ) .subcommand( subcommand("sessions") @@ -47,7 +48,8 @@ pub fn cli() -> Command { .subcommand( subcommand("rebuilds") .about("Reports rebuild reasons from previous sessions (unstable)") - .arg_manifest_path(), + .arg_manifest_path() + .arg(opt("id", "Session ID to report on").value_name("ID")), ) } diff --git a/tests/testsuite/cargo_report_rebuilds/mod.rs b/tests/testsuite/cargo_report_rebuilds/mod.rs index 8aada08d77f..2c2c2e0c866 100644 --- a/tests/testsuite/cargo_report_rebuilds/mod.rs +++ b/tests/testsuite/cargo_report_rebuilds/mod.rs @@ -563,3 +563,47 @@ Root rebuilds: "#]]) .run(); } + +#[cargo_test] +fn uses_latest_session_by_default() { + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.0.0")) + .file("src/lib.rs", "") + .build(); + + // First session: fresh build (1 new unit) + p.cargo("check -Zbuild-analysis") + .env("CARGO_BUILD_ANALYSIS_ENABLED", "true") + .masquerade_as_nightly_cargo(&["build-analysis"]) + .run(); + + let _ = paths::log_file(0); + + p.change_file("src/lib.rs", "// touched"); + + // Second session: rebuild (1 unit rebuilt) + p.cargo("check -Zbuild-analysis") + .env("CARGO_BUILD_ANALYSIS_ENABLED", "true") + .masquerade_as_nightly_cargo(&["build-analysis"]) + .run(); + + let _ = paths::log_file(1); + + // Without --id, should use the most recent (second) session which has a rebuild + p.cargo("report rebuilds -Zbuild-analysis") + .masquerade_as_nightly_cargo(&["build-analysis"]) + .with_stderr_data(str![[r#" +Session: [..] +Status: 1 unit rebuilt, 0 cached, 0 new + +Rebuild impact: + root rebuilds: 1 unit + cascading: 0 units + +Root rebuilds: + 0. foo@0.0.0 (check): file modified: src/lib.rs + impact: no cascading rebuilds + +"#]]) + .run(); +} diff --git a/tests/testsuite/cargo_report_timings/help/stdout.term.svg b/tests/testsuite/cargo_report_timings/help/stdout.term.svg index 0fd20351a5d..00b692de7cd 100644 --- a/tests/testsuite/cargo_report_timings/help/stdout.term.svg +++ b/tests/testsuite/cargo_report_timings/help/stdout.term.svg @@ -1,4 +1,4 @@ - +