Skip to content

Commit 0e44914

Browse files
Add fallback to summarize-0.7 if running raw summarize fails
This is intended to ease the transition over rust-lang/rust#67397.
1 parent c4cd85d commit 0e44914

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

collector/src/bin/rustc-fake.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::env;
2+
use std::path::Path;
23
use std::process::Command;
34
use std::time::{Duration, Instant};
45

@@ -82,26 +83,9 @@ fn main() {
8283
}
8384
}
8485
let prefix = prefix.expect(&format!("found prefix {:?}", prof_out_dir));
85-
// FIXME: it'd be great to have a less generic name for this;
86-
// we should think about renaming the binary in measureme to measureme, such
87-
// that the command is `measureme summarize ...`.
88-
let mut cmd = Command::new("summarize");
89-
cmd.current_dir(&prof_out_dir);
90-
cmd.arg("summarize").arg("--json");
91-
cmd.arg(&prefix);
92-
let status = cmd.status().expect(&format!(
93-
"summarize spawned successfully in {:?}",
94-
prof_out_dir
95-
));
96-
assert!(
97-
status.success(),
98-
"summarize failed in {:?}; prefix is {:?}",
99-
prof_out_dir,
100-
prefix
101-
);
102-
let json =
103-
std::fs::read_to_string(prof_out_dir.join(&format!("{}.json", prefix)))
104-
.expect("able to read JSON output");
86+
let json = run_summarize("summarize", &prof_out_dir, &prefix)
87+
.or_else(|_| run_summarize("summarize-0.7", &prof_out_dir, &prefix))
88+
.expect("able to run summarize or summarize-0.7");
10589
println!("!self-profile-output:{}", json);
10690
}
10791
}
@@ -282,6 +266,21 @@ fn print_time(dur: Duration) {
282266
);
283267
}
284268

269+
fn run_summarize(name: &str, prof_out_dir: &Path, prefix: &str) -> std::io::Result<String> {
270+
let mut cmd = Command::new(name);
271+
cmd.current_dir(&prof_out_dir);
272+
cmd.arg("summarize").arg("--json");
273+
cmd.arg(&prefix);
274+
let status = cmd.status()?;
275+
if !status.success() {
276+
return Err(std::io::Error::new(
277+
std::io::ErrorKind::Other,
278+
"Failed to run successfully",
279+
));
280+
}
281+
std::fs::read_to_string(prof_out_dir.join(&format!("{}.json", prefix)))
282+
}
283+
285284
#[cfg(windows)]
286285
fn raise_priority() {}
287286

0 commit comments

Comments
 (0)