Skip to content

Commit

Permalink
Don't hard-code rustdoc subcommand
Browse files Browse the repository at this point in the history
- Change `subcommand()` to take BuildKind and return Option
- Remove `is_build_kind_supported`
  • Loading branch information
jyn514 committed Jun 30, 2020
1 parent a72221f commit a080ee4
Showing 1 changed file with 14 additions and 31 deletions.
45 changes: 14 additions & 31 deletions collector/src/bin/rustc-perf-collector/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -268,23 +255,19 @@ 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",
run_kind
));
}

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"
Expand Down

0 comments on commit a080ee4

Please sign in to comment.