Skip to content

Commit 4198b66

Browse files
committed
feat(report): cargo report timings command skeleton
1 parent c77db63 commit 4198b66

File tree

5 files changed

+125
-116
lines changed

5 files changed

+125
-116
lines changed

src/bin/cargo/commands/report.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::command_prelude::*;
2-
use cargo::core::compiler::future_incompat::{OnDiskReports, REPORT_PREAMBLE};
2+
3+
use cargo::core::compiler::future_incompat::OnDiskReports;
4+
use cargo::core::compiler::future_incompat::REPORT_PREAMBLE;
35
use cargo::drop_println;
46

57
pub fn cli() -> Command {
@@ -23,11 +25,26 @@ pub fn cli() -> Command {
2325
)
2426
.arg_package("Package to display a report for"),
2527
)
28+
.subcommand(
29+
subcommand("timings")
30+
.about("Reports the build timings of previous builds (unstable)")
31+
.arg(flag("open", "Opens the timing report in a browser")),
32+
)
2633
}
2734

2835
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
2936
match args.subcommand() {
3037
Some(("future-incompatibilities", args)) => report_future_incompatibilities(gctx, args),
38+
Some(("timings", args)) => {
39+
gctx.cli_unstable().fail_if_stable_command(
40+
gctx,
41+
"report timings",
42+
15844,
43+
"build-analysis",
44+
gctx.cli_unstable().build_analysis,
45+
)?;
46+
report_timings(gctx, args)
47+
}
3148
Some((cmd, _)) => {
3249
unreachable!("unexpected command {}", cmd)
3350
}
@@ -49,3 +66,7 @@ fn report_future_incompatibilities(gctx: &GlobalContext, args: &ArgMatches) -> C
4966
drop(gctx.shell().print_ansi_stdout(report.as_bytes()));
5067
Ok(())
5168
}
69+
70+
fn report_timings(_gctx: &GlobalContext, _args: &ArgMatches) -> CliResult {
71+
Ok(())
72+
}

tests/testsuite/cargo_report/help/stdout.term.svg

Lines changed: 21 additions & 19 deletions
Loading

tests/testsuite/cargo_report_timings/help/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn case() {
88
.args(["report", "timings"])
99
.arg("--help")
1010
.assert()
11-
.failure()
12-
.stdout_eq(str![""])
13-
.stderr_eq(file!["stderr.term.svg"]);
11+
.success()
12+
.stdout_eq(file!["stdout.term.svg"])
13+
.stderr_eq(str![""]);
1414
}
Lines changed: 63 additions & 0 deletions
Loading

tests/testsuite/cargo_report_timings/mod.rs

Lines changed: 16 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ fn gated_stable_channel() {
1818
.build();
1919

2020
p.cargo("report timings")
21-
.with_status(1)
21+
.with_status(101)
2222
.with_stderr_data(str![[r#"
23-
[ERROR] unrecognized subcommand 'timings'
24-
25-
Usage: cargo report [OPTIONS] <COMMAND>
26-
27-
For more information, try '--help'.
23+
[ERROR] the `cargo report timings` command is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
24+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
25+
See https://github.com/rust-lang/cargo/issues/15844 for more information about the `cargo report timings` command.
2826
2927
"#]])
3028
.run();
@@ -39,13 +37,10 @@ fn gated_unstable_options() {
3937

4038
p.cargo("report timings")
4139
.masquerade_as_nightly_cargo(&["build-analysis"])
42-
.with_status(1)
40+
.with_status(101)
4341
.with_stderr_data(str![[r#"
44-
[ERROR] unrecognized subcommand 'timings'
45-
46-
Usage: cargo report [OPTIONS] <COMMAND>
47-
48-
For more information, try '--help'.
42+
[ERROR] the `cargo report timings` command is unstable, pass `-Z build-analysis` to enable it
43+
See https://github.com/rust-lang/cargo/issues/15844 for more information about the `cargo report timings` command.
4944
5045
"#]])
5146
.run();
@@ -55,15 +50,7 @@ For more information, try '--help'.
5550
fn no_log() {
5651
cargo_process("report timings -Zbuild-analysis")
5752
.masquerade_as_nightly_cargo(&["build-analysis"])
58-
.with_status(1)
59-
.with_stderr_data(str![[r#"
60-
[ERROR] unrecognized subcommand 'timings'
61-
62-
Usage: cargo report [OPTIONS] <COMMAND>
63-
64-
For more information, try '--help'.
65-
66-
"#]])
53+
.with_stderr_data(str![""])
6754
.run();
6855
}
6956

@@ -91,15 +78,7 @@ fn no_log_for_the_current_workspace() {
9178

9279
bar.cargo("report timings -Zbuild-analysis")
9380
.masquerade_as_nightly_cargo(&["build-analysis"])
94-
.with_status(1)
95-
.with_stderr_data(str![[r#"
96-
[ERROR] unrecognized subcommand 'timings'
97-
98-
Usage: cargo report [OPTIONS] <COMMAND>
99-
100-
For more information, try '--help'.
101-
102-
"#]])
81+
.with_stderr_data(str![""])
10382
.run();
10483
}
10584

@@ -120,15 +99,7 @@ fn invalid_log() {
12099

121100
p.cargo("report timings -Zbuild-analysis")
122101
.masquerade_as_nightly_cargo(&["build-analysis"])
123-
.with_status(1)
124-
.with_stderr_data(str![[r#"
125-
[ERROR] unrecognized subcommand 'timings'
126-
127-
Usage: cargo report [OPTIONS] <COMMAND>
128-
129-
For more information, try '--help'.
130-
131-
"#]])
102+
.with_stderr_data(str![""])
132103
.run();
133104
}
134105

@@ -150,15 +121,7 @@ fn empty_log() {
150121
// If the make-up log file was picked, the command would have failed.
151122
p.cargo("report timings -Zbuild-analysis")
152123
.masquerade_as_nightly_cargo(&["build-analysis"])
153-
.with_status(1)
154-
.with_stderr_data(str![[r#"
155-
[ERROR] unrecognized subcommand 'timings'
156-
157-
Usage: cargo report [OPTIONS] <COMMAND>
158-
159-
For more information, try '--help'.
160-
161-
"#]])
124+
.with_stderr_data(str![""])
162125
.run();
163126
}
164127

@@ -189,15 +152,7 @@ fn prefer_latest() {
189152
// if it had picked the corrupted first log file, it would have failed.
190153
p.cargo("report timings -Zbuild-analysis")
191154
.masquerade_as_nightly_cargo(&["build-analysis"])
192-
.with_status(1)
193-
.with_stderr_data(str![[r#"
194-
[ERROR] unrecognized subcommand 'timings'
195-
196-
Usage: cargo report [OPTIONS] <COMMAND>
197-
198-
For more information, try '--help'.
199-
200-
"#]])
155+
.with_stderr_data(str![""])
201156
.run();
202157

203158
assert_eq!(p.glob("**/cargo-timing-*.html").count(), 0);
@@ -236,15 +191,7 @@ fn prefer_workspace() {
236191
// Back to foo, if it had picked the corrupted log file, it would have failed.
237192
foo.cargo("report timings -Zbuild-analysis")
238193
.masquerade_as_nightly_cargo(&["build-analysis"])
239-
.with_status(1)
240-
.with_stderr_data(str![[r#"
241-
[ERROR] unrecognized subcommand 'timings'
242-
243-
Usage: cargo report [OPTIONS] <COMMAND>
244-
245-
For more information, try '--help'.
246-
247-
"#]])
194+
.with_stderr_data(str![""])
248195
.run();
249196

250197
assert_eq!(foo.glob("**/cargo-timing-*.html").count(), 0);
@@ -267,15 +214,7 @@ fn outside_workspace() {
267214
// * save the report in a temp directory
268215
cargo_process("report timings -Zbuild-analysis")
269216
.masquerade_as_nightly_cargo(&["build-analysis"])
270-
.with_status(1)
271-
.with_stderr_data(str![[r#"
272-
[ERROR] unrecognized subcommand 'timings'
273-
274-
Usage: cargo report [OPTIONS] <COMMAND>
275-
276-
For more information, try '--help'.
277-
278-
"#]])
217+
.with_stderr_data(str![""])
279218
.run();
280219

281220
// Have no timing HTML under target directory
@@ -296,15 +235,7 @@ fn with_section_timings() {
296235

297236
p.cargo("report timings -Zbuild-analysis")
298237
.masquerade_as_nightly_cargo(&["build-analysis"])
299-
.with_status(1)
300-
.with_stderr_data(str![[r#"
301-
[ERROR] unrecognized subcommand 'timings'
302-
303-
Usage: cargo report [OPTIONS] <COMMAND>
304-
305-
For more information, try '--help'.
306-
307-
"#]])
238+
.with_stderr_data(str![""])
308239
.run();
309240

310241
assert_eq!(p.glob("**/cargo-timing-*.html").count(), 0);
@@ -335,15 +266,7 @@ fn with_multiple_targets() {
335266

336267
p.cargo("report timings -Zbuild-analysis")
337268
.masquerade_as_nightly_cargo(&["build-analysis"])
338-
.with_status(1)
339-
.with_stderr_data(str![[r#"
340-
[ERROR] unrecognized subcommand 'timings'
341-
342-
Usage: cargo report [OPTIONS] <COMMAND>
343-
344-
For more information, try '--help'.
345-
346-
"#]])
269+
.with_stderr_data(str![""])
347270
.run();
348271

349272
assert_eq!(p.glob("**/cargo-timing-*.html").count(), 0);

0 commit comments

Comments
 (0)