@@ -321,18 +321,25 @@ fn bench(
321
321
}
322
322
323
323
fn check_measureme_installed ( ) -> Result < ( ) , String > {
324
- let mut binaries = vec ! [ ] ;
325
-
326
- for name in [ "summarize" , "crox" , "flamegraph" ] {
327
- if let Err ( _) = Command :: new ( name) . output ( ) {
328
- binaries. push ( name) ;
329
- }
330
- }
331
- if binaries. is_empty ( ) {
324
+ let not_installed = std:: array:: IntoIter :: new ( [ "summarize" , "crox" , "flamegraph" ] )
325
+ . filter ( |n| !is_installed ( n) )
326
+ . collect :: < Vec < _ > > ( ) ;
327
+ if not_installed. is_empty ( ) {
332
328
Ok ( ( ) )
333
329
} else {
334
- Err ( format ! ( "To run this command you need {0} on your PATH. To install run `cargo install --git https://github.com/rust-lang/measureme --branch stable {0}`\n " , binaries. join( " " ) ) )
330
+ Err ( format ! ( "To run this command you need {0} on your PATH. To install run `cargo install --git https://github.com/rust-lang/measureme --branch stable {0}`\n " , not_installed. join( " " ) ) )
331
+ }
332
+ }
333
+
334
+ fn check_installed ( name : & str ) -> anyhow:: Result < ( ) > {
335
+ if !is_installed ( name) {
336
+ anyhow:: bail!( "`{}` is not installed but must be" , name) ;
335
337
}
338
+ Ok ( ( ) )
339
+ }
340
+
341
+ fn is_installed ( name : & str ) -> bool {
342
+ Command :: new ( name) . output ( ) . is_ok ( )
336
343
}
337
344
338
345
fn get_benchmarks (
@@ -490,14 +497,19 @@ fn get_local_toolchain(
490
497
. with_context ( || format ! ( "failed to canonicalize cargo executable '{}'" , cargo) ) ?
491
498
} else {
492
499
// Use the nightly cargo from `rustup`.
493
- let s = String :: from_utf8 (
494
- Command :: new ( "rustup" )
495
- . args ( & [ "which" , "cargo" , "--toolchain=nightly" ] )
496
- . output ( )
497
- . context ( "failed to run `rustup which cargo`" ) ?
498
- . stdout ,
499
- )
500
- . context ( "failed to convert `rustup which cargo` output to utf8" ) ?;
500
+ let output = Command :: new ( "rustup" )
501
+ . args ( & [ "which" , "cargo" , "--toolchain=nightly" ] )
502
+ . output ( )
503
+ . context ( "failed to run `rustup which cargo`" ) ?;
504
+ if !output. status . success ( ) {
505
+ anyhow:: bail!(
506
+ "`rustup which cargo` exited with status {}\n stderr={}" ,
507
+ output. status,
508
+ String :: from_utf8_lossy( & output. stderr)
509
+ )
510
+ }
511
+ let s = String :: from_utf8 ( output. stdout )
512
+ . context ( "failed to convert `rustup which cargo` output to utf8" ) ?;
501
513
502
514
let cargo = PathBuf :: from ( s. trim ( ) ) ;
503
515
debug ! ( "found cargo: {:?}" , & cargo) ;
@@ -576,6 +588,9 @@ fn generate_cachegrind_diffs(
576
588
577
589
/// Demangles symbols in a file using rustfilt and writes result to path.
578
590
fn rustfilt ( cgout : & Path , path : & Path ) -> anyhow:: Result < ( ) > {
591
+ if !is_installed ( "rustfilt" ) {
592
+ anyhow:: bail!( "`rustfilt` not installed." ) ;
593
+ }
579
594
let output = Command :: new ( "rustfilt" )
580
595
. arg ( "-i" )
581
596
. arg ( cgout)
@@ -594,6 +609,9 @@ fn rustfilt(cgout: &Path, path: &Path) -> anyhow::Result<()> {
594
609
595
610
/// Compares two Cachegrind output files using cg_diff and writes result to path.
596
611
fn cg_diff ( cgout1 : & Path , cgout2 : & Path , path : & Path ) -> anyhow:: Result < ( ) > {
612
+ if !is_installed ( "cg_diff" ) {
613
+ anyhow:: bail!( "`cg_diff` not installed." ) ;
614
+ }
597
615
let output = Command :: new ( "cg_diff" )
598
616
. arg ( "--mod-filename=s#/rustc/[^/]*/##" )
599
617
. arg ( "--mod-funcname=s/[.]llvm[.].*//" )
@@ -1042,6 +1060,10 @@ fn main_result() -> anyhow::Result<i32> {
1042
1060
let out_dir = PathBuf :: from ( sub_m. value_of_os ( "OUT_DIR" ) . unwrap_or ( default_out_dir) ) ;
1043
1061
let scenario_kinds = scenario_kinds_from_arg ( sub_m. value_of ( "RUNS" ) ) ?;
1044
1062
let rustdoc = sub_m. value_of ( "RUSTDOC" ) ;
1063
+ check_installed ( "valgrind" ) ?;
1064
+ check_installed ( "cg_annotate" ) ?;
1065
+ check_installed ( "rustup-toolchain-install-master" ) ?;
1066
+ check_installed ( "rustfilt" ) ?;
1045
1067
1046
1068
let id1 = rustc1. strip_prefix ( '+' ) . unwrap_or ( "before" ) ;
1047
1069
let id2 = rustc2. strip_prefix ( '+' ) . unwrap_or ( "after" ) ;
0 commit comments