From a080ee42d91457ed78c7f7b148e1fefa640decae Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 29 Jun 2020 20:44:36 -0400 Subject: [PATCH] Don't hard-code `rustdoc` subcommand - Change `subcommand()` to take BuildKind and return Option - Remove `is_build_kind_supported` --- .../src/bin/rustc-perf-collector/execute.rs | 45 ++++++------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/collector/src/bin/rustc-perf-collector/execute.rs b/collector/src/bin/rustc-perf-collector/execute.rs index e6f4200af..e83b7f7a4 100644 --- a/collector/src/bin/rustc-perf-collector/execute.rs +++ b/collector/src/bin/rustc-perf-collector/execute.rs @@ -146,7 +146,7 @@ impl Profiler { // What cargo subcommand do we need to run for this profiler? If not // `rustc`, must be a subcommand that itself invokes `rustc`. - fn subcommand(&self) -> &'static str { + fn subcommand(&self, build_kind: BuildKind) -> Option<&'static str> { match self { Profiler::PerfStat | Profiler::PerfStatSelfProfile @@ -158,27 +158,14 @@ impl Profiler { | Profiler::Callgrind | Profiler::DHAT | Profiler::Massif - | Profiler::Eprintln => "rustc", - Profiler::LlvmLines => "llvm-lines", - } - } - - fn is_build_kind_allowed(&self, build_kind: BuildKind) -> bool { - match self { - Profiler::PerfStat - | Profiler::PerfStatSelfProfile - | Profiler::SelfProfile - | Profiler::TimePasses - | Profiler::PerfRecord - | Profiler::OProfile - | Profiler::Cachegrind - | Profiler::Callgrind - | Profiler::DHAT - | Profiler::Massif - | Profiler::Eprintln => true, + | Profiler::Eprintln => if build_kind == BuildKind::Doc { + Some("rustdoc") + } else { + Some("rustc") + }, Profiler::LlvmLines => match build_kind { - BuildKind::Debug | BuildKind::Opt => true, - BuildKind::Check | BuildKind::Doc => false, + BuildKind::Debug | BuildKind::Opt => Some("rustc"), + BuildKind::Check | BuildKind::Doc => None, } } } @@ -268,12 +255,6 @@ impl<'a> CargoProcess<'a> { // machinery works). let subcommand = if let Some((ref mut processor, run_kind, ..)) = self.processor_etc { let profiler = processor.profiler(); - if !profiler.is_build_kind_allowed(self.build_kind) { - return Err(anyhow::anyhow!( - "this profiler doesn't support {:?} builds", - self.build_kind - )); - } if !profiler.is_run_kind_allowed(run_kind) { return Err(anyhow::anyhow!( "this profiler doesn't support {:?} runs", @@ -281,10 +262,12 @@ impl<'a> CargoProcess<'a> { )); } - if self.build_kind == BuildKind::Doc { - "rustdoc" - } else { - profiler.subcommand() + match profiler.subcommand(self.build_kind) { + None => return Err(anyhow::anyhow!( + "this profiler doesn't support {:?} builds", + self.build_kind + )), + Some(sub) => sub, } } else { "rustc"