From 19bb97ffadf0ff18f9f986e7e31ae778895d7ae2 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Fri, 22 Sep 2023 12:49:58 +0200 Subject: [PATCH 1/6] Clippy locally --- collector/src/bin/collector.rs | 9 +++++++ collector/src/bin/rustc-fake.rs | 3 +++ collector/src/compile/benchmark/profile.rs | 4 ++- collector/src/compile/execute/bencher.rs | 1 + collector/src/compile/execute/mod.rs | 22 ++++++++++++++- collector/src/toolchain.rs | 31 ++++++++++++++++++++-- database/src/lib.rs | 4 +++ site/src/request_handlers/dashboard.rs | 3 +++ 8 files changed, 73 insertions(+), 4 deletions(-) diff --git a/collector/src/bin/collector.rs b/collector/src/bin/collector.rs index 21c1c4ebf..3959c279f 100644 --- a/collector/src/bin/collector.rs +++ b/collector/src/bin/collector.rs @@ -375,6 +375,10 @@ struct CompileTimeOptions { /// The path to the local rustdoc to measure #[arg(long)] rustdoc: Option, + + /// The path to the local clippy to measure + #[arg(long)] + clippy: Option } #[derive(Debug, clap::Args)] @@ -663,6 +667,7 @@ fn main_result() -> anyhow::Result { None, None, None, + None, id, target_triple.clone(), )?; @@ -721,6 +726,7 @@ fn main_result() -> anyhow::Result { None, None, None, + None, id, target_triple.clone(), )?; @@ -757,6 +763,7 @@ fn main_result() -> anyhow::Result { &profiles, &local.rustc, opts.rustdoc.as_deref(), + opts.clippy.as_deref(), local.cargo.as_deref(), local.id.as_deref(), "", @@ -949,6 +956,7 @@ fn main_result() -> anyhow::Result { profiles, rustc, opts.rustdoc.as_deref(), + opts.clippy.as_deref(), local.cargo.as_deref(), local.id.as_deref(), suffix, @@ -1063,6 +1071,7 @@ fn get_local_toolchain_for_runtime_benchmarks( &[Profile::Opt], &local.rustc, None, + None, local.cargo.as_deref(), local.id.as_deref(), "", diff --git a/collector/src/bin/rustc-fake.rs b/collector/src/bin/rustc-fake.rs index 6cfcacdce..1697e5ef4 100644 --- a/collector/src/bin/rustc-fake.rs +++ b/collector/src/bin/rustc-fake.rs @@ -35,8 +35,11 @@ fn main() { let mut args = args_os.collect::>(); let rustc = env::var_os("RUSTC_REAL").unwrap(); let actually_rustdoc = name.ends_with("rustdoc-fake"); + let actually_clippy = name.ends_with("clippy-fake"); let tool = if actually_rustdoc { env::var_os("RUSTDOC_REAL").unwrap() + } else if actually_clippy { + env::var_os("CLIPPY_REAL").unwrap() } else { rustc }; diff --git a/collector/src/compile/benchmark/profile.rs b/collector/src/compile/benchmark/profile.rs index 01a58253d..cb7e89bdc 100644 --- a/collector/src/compile/benchmark/profile.rs +++ b/collector/src/compile/benchmark/profile.rs @@ -12,13 +12,15 @@ pub enum Profile { Debug, Doc, Opt, + Clippy, } impl Profile { pub fn all() -> Vec { - vec![Profile::Check, Profile::Debug, Profile::Doc, Profile::Opt] + vec![Profile::Check, Profile::Debug, Profile::Doc, Profile::Opt, Profile::Clippy] } + // This also leaves Clippy out pub fn all_non_doc() -> Vec { vec![Profile::Check, Profile::Debug, Profile::Opt] } diff --git a/collector/src/compile/execute/bencher.rs b/collector/src/compile/execute/bencher.rs index 3a90d9a62..eeb6f3469 100644 --- a/collector/src/compile/execute/bencher.rs +++ b/collector/src/compile/execute/bencher.rs @@ -87,6 +87,7 @@ impl<'a> BenchProcessor<'a> { Profile::Debug => database::Profile::Debug, Profile::Doc => database::Profile::Doc, Profile::Opt => database::Profile::Opt, + Profile::Clippy => database::Profile::Clippy, }; if let Some(files) = stats.2 { diff --git a/collector/src/compile/execute/mod.rs b/collector/src/compile/execute/mod.rs index 6af9bb2d4..4b66a3b26 100644 --- a/collector/src/compile/execute/mod.rs +++ b/collector/src/compile/execute/mod.rs @@ -72,7 +72,7 @@ impl PerfTool { } ProfileTool(LlvmLines) => match profile { Profile::Debug | Profile::Opt => Some("llvm-lines"), - Profile::Check | Profile::Doc => None, + Profile::Check | Profile::Doc | Profile::Clippy => None, }, } } @@ -168,6 +168,10 @@ impl<'a> CargoProcess<'a> { if let Some(r) = &self.toolchain.components.rustdoc { cmd.env("RUSTDOC", &*FAKE_RUSTDOC).env("RUSTDOC_REAL", r); + }; + + if let Some(c) = &self.toolchain.components.clippy { + cmd.env("CLIPPY", &*FAKE_CLIPPY).env("CLIPPY_REAL", c); } cmd } @@ -236,6 +240,7 @@ impl<'a> CargoProcess<'a> { } Profile::Debug => {} Profile::Doc => {} + Profile::Clippy => {} Profile::Opt => { cmd.arg("--release"); } @@ -354,6 +359,21 @@ lazy_static::lazy_static! { } fake_rustdoc }; + static ref FAKE_CLIPPY: PathBuf = { + let mut fake_clippy = env::current_exe().unwrap(); + fake_clippy.pop(); + fake_clippy.push("clippy-fake"); + // link from rustc-fake to rustdoc-fake + if !fake_clippy.exists() { + #[cfg(unix)] + use std::os::unix::fs::symlink; + #[cfg(windows)] + use std::os::windows::fs::symlink_file as symlink; + + symlink(&*FAKE_RUSTC, &fake_clippy).expect("failed to make symbolic link"); + } + fake_clippy + }; } /// Used to indicate if we need to retry a run. diff --git a/collector/src/toolchain.rs b/collector/src/toolchain.rs index 2cebec280..1942fafda 100644 --- a/collector/src/toolchain.rs +++ b/collector/src/toolchain.rs @@ -123,6 +123,7 @@ impl SysrootDownload { let components = ToolchainComponents::from_binaries_and_libdir( sysroot_bin("rustc")?, Some(sysroot_bin("rustdoc")?), + Some(sysroot_bin("clippy")?), sysroot_bin("cargo")?, &self.directory.join(&self.rust_sha).join("lib"), )?; @@ -241,6 +242,7 @@ impl Toolchain { pub struct ToolchainComponents { pub rustc: PathBuf, pub rustdoc: Option, + pub clippy: Option, pub cargo: PathBuf, pub lib_rustc: Option, pub lib_std: Option, @@ -252,12 +254,14 @@ impl ToolchainComponents { fn from_binaries_and_libdir( rustc: PathBuf, rustdoc: Option, + clippy: Option, cargo: PathBuf, libdir: &Path, ) -> anyhow::Result { let mut component = ToolchainComponents { rustc, rustdoc, + clippy, cargo, ..Default::default() }; @@ -298,6 +302,7 @@ pub fn get_local_toolchain( profiles: &[Profile], rustc: &str, rustdoc: Option<&Path>, + clippy: Option<&Path>, cargo: Option<&Path>, id: Option<&str>, id_suffix: &str, @@ -400,6 +405,26 @@ pub fn get_local_toolchain( None }; + let clippy = + if let Some(clippy) = &clippy { + Some(clippy.canonicalize().with_context(|| { + format!("failed to canonicalize clippy executable {:?}", clippy) + })?) + } else if profiles.contains(&Profile::Clippy) { + // We need a `clippy`. Look for one next to `rustc`. + if let Ok(clippy) = rustc.with_file_name("cargo-clippy").canonicalize() { + debug!("found clippy: {:?}", &clippy); + Some(clippy) + } else { + anyhow::bail!( + "'Clippy' build specified but '--clippy' not specified and no 'cargo-clippy' found \ + next to 'rustc'" + ); + } + } else { + // No `clippy` provided, but none needed. + None + }; let cargo = if let Some(cargo) = &cargo { cargo .canonicalize() @@ -428,7 +453,7 @@ pub fn get_local_toolchain( let lib_dir = get_lib_dir_from_rustc(&rustc).context("Cannot find libdir for rustc")?; Ok(Toolchain { - components: ToolchainComponents::from_binaries_and_libdir(rustc, rustdoc, cargo, &lib_dir)?, + components: ToolchainComponents::from_binaries_and_libdir(rustc, rustdoc, clippy, cargo, &lib_dir)?, id, triple: target_triple, }) @@ -465,16 +490,18 @@ pub fn create_toolchain_from_published_version( }; let rustc = which("rustc")?; let rustdoc = which("rustdoc")?; + let clippy = which("clippy")?; let cargo = which("cargo")?; debug!("Found rustc: {}", rustc.display()); debug!("Found rustdoc: {}", rustdoc.display()); + debug!("Found clippy: {}", clippy.display()); debug!("Found cargo: {}", cargo.display()); let lib_dir = get_lib_dir_from_rustc(&rustc)?; let components = - ToolchainComponents::from_binaries_and_libdir(rustc, Some(rustdoc), cargo, &lib_dir)?; + ToolchainComponents::from_binaries_and_libdir(rustc, Some(rustdoc), Some(clippy), cargo, &lib_dir)?; Ok(Toolchain { components, diff --git a/database/src/lib.rs b/database/src/lib.rs index 42adbf6fb..4c827a32c 100644 --- a/database/src/lib.rs +++ b/database/src/lib.rs @@ -224,6 +224,8 @@ pub enum Profile { Doc, /// An optimized "release" build Opt, + /// A Clippy run + Clippy } impl Profile { @@ -233,6 +235,7 @@ impl Profile { Profile::Opt => "opt", Profile::Debug => "debug", Profile::Doc => "doc", + Profile::Clippy => "clippy" } } } @@ -245,6 +248,7 @@ impl std::str::FromStr for Profile { "debug" => Profile::Debug, "doc" => Profile::Doc, "opt" => Profile::Opt, + "clippy" => Profile::Clippy, _ => return Err(format!("{} is not a profile", s)), }) } diff --git a/site/src/request_handlers/dashboard.rs b/site/src/request_handlers/dashboard.rs index 0e5cf23a8..98f422661 100644 --- a/site/src/request_handlers/dashboard.rs +++ b/site/src/request_handlers/dashboard.rs @@ -150,6 +150,7 @@ pub struct ByProfile { pub debug: T, pub doc: T, pub opt: T, + pub clippy: T } impl ByProfile { @@ -163,6 +164,7 @@ impl ByProfile { debug: f(Profile::Debug).await?, doc: f(Profile::Doc).await?, opt: f(Profile::Opt).await?, + clippy: f(Profile::Clippy).await?, }) } } @@ -175,6 +177,7 @@ impl std::ops::Index for ByProfile { Profile::Debug => &self.debug, Profile::Doc => &self.doc, Profile::Opt => &self.opt, + Profile::Clippy => &self.clippy } } } From 4675a7beda3f2289033b979f53ac284e04fdf526 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Fri, 22 Sep 2023 13:11:14 +0200 Subject: [PATCH 2/6] Add `ToolchainConfig` struct with a builder pattern --- collector/src/bin/collector.rs | 37 ++++++++++------------- collector/src/toolchain.rs | 54 ++++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 30 deletions(-) diff --git a/collector/src/bin/collector.rs b/collector/src/bin/collector.rs index 3959c279f..3c34e2e75 100644 --- a/collector/src/bin/collector.rs +++ b/collector/src/bin/collector.rs @@ -38,7 +38,7 @@ use collector::runtime::{ }; use collector::runtime::{profile_runtime, RuntimeCompilationOpts}; use collector::toolchain::{ - create_toolchain_from_published_version, get_local_toolchain, Sysroot, Toolchain, + create_toolchain_from_published_version, get_local_toolchain, Sysroot, Toolchain, ToolchainConfig, }; use collector::utils::cachegrind::cachegrind_diff; use collector::utils::{is_installed, wait_for_future}; @@ -664,10 +664,7 @@ fn main_result() -> anyhow::Result { let toolchain = get_local_toolchain( &[Profile::Opt], rustc, - None, - None, - None, - None, + ToolchainConfig::default(), id, target_triple.clone(), )?; @@ -723,10 +720,7 @@ fn main_result() -> anyhow::Result { let toolchain = get_local_toolchain( &[Profile::Opt], rustc, - None, - None, - None, - None, + ToolchainConfig::default(), id, target_triple.clone(), )?; @@ -762,10 +756,11 @@ fn main_result() -> anyhow::Result { let toolchain = get_local_toolchain( &profiles, &local.rustc, - opts.rustdoc.as_deref(), - opts.clippy.as_deref(), - local.cargo.as_deref(), - local.id.as_deref(), + *ToolchainConfig::default() + .rustdoc(opts.rustdoc.as_deref()) + .clippy(opts.clippy.as_deref()) + .cargo(local.cargo.as_deref()) + .id(local.id.as_deref()), "", target_triple, )?; @@ -955,10 +950,11 @@ fn main_result() -> anyhow::Result { let toolchain = get_local_toolchain( profiles, rustc, - opts.rustdoc.as_deref(), - opts.clippy.as_deref(), - local.cargo.as_deref(), - local.id.as_deref(), + *ToolchainConfig::default() + .rustdoc(opts.rustdoc.as_deref()) + .clippy(opts.clippy.as_deref()) + .cargo(local.cargo.as_deref()) + .id(local.id.as_deref()), suffix, target_triple.clone(), )?; @@ -1070,10 +1066,9 @@ fn get_local_toolchain_for_runtime_benchmarks( get_local_toolchain( &[Profile::Opt], &local.rustc, - None, - None, - local.cargo.as_deref(), - local.id.as_deref(), + *ToolchainConfig::default() + .cargo(local.cargo.as_deref()) + .id(local.id.as_deref()), "", target_triple.to_string(), ) diff --git a/collector/src/toolchain.rs b/collector/src/toolchain.rs index 1942fafda..58a33cf65 100644 --- a/collector/src/toolchain.rs +++ b/collector/src/toolchain.rs @@ -292,6 +292,45 @@ impl ToolchainComponents { } } +#[derive(Clone, Copy)] +pub struct ToolchainConfig<'a> { + rustdoc: Option<&'a Path>, + clippy: Option<&'a Path>, + cargo: Option<&'a Path>, + id: Option<&'a str>, +} + +impl<'a> ToolchainConfig<'a> { + pub fn default() -> Self { + Self { + rustdoc: None, + clippy: None, + cargo: None, + id: None + } + } + + pub fn rustdoc(&mut self, rustdoc: Option<&'a Path>) -> &mut Self { + self.rustdoc = rustdoc; + self + } + + pub fn clippy(&mut self, clippy: Option<&'a Path>) -> &mut Self { + self.clippy = clippy; + self + } + + pub fn cargo(&mut self, cargo: Option<&'a Path>) -> &mut Self { + self.cargo = cargo; + self + } + + pub fn id(&mut self, id: Option<&'a str>) -> &mut Self { + self.id = id; + self + } +} + /// Get a toolchain from the input. /// - `rustc`: check if the given one is acceptable. /// - `rustdoc`: if one is given, check if it is acceptable. Otherwise, if @@ -301,10 +340,7 @@ impl ToolchainComponents { pub fn get_local_toolchain( profiles: &[Profile], rustc: &str, - rustdoc: Option<&Path>, - clippy: Option<&Path>, - cargo: Option<&Path>, - id: Option<&str>, + toolchain_config: ToolchainConfig<'_>, id_suffix: &str, target_triple: String, ) -> anyhow::Result { @@ -359,7 +395,7 @@ pub fn get_local_toolchain( debug!("found rustc: {:?}", &rustc); // When the id comes from a +toolchain, the suffix is *not* added. - let id = if let Some(id) = id { + let id = if let Some(id) = toolchain_config.id { let mut id = id.to_owned(); id.push_str(id_suffix); id @@ -374,7 +410,7 @@ pub fn get_local_toolchain( // When specifying rustc via a path, the suffix is always added to the // id. - let mut id = if let Some(id) = id { + let mut id = if let Some(id) = toolchain_config.id { id.to_owned() } else { "Id".to_string() @@ -385,7 +421,7 @@ pub fn get_local_toolchain( }; let rustdoc = - if let Some(rustdoc) = &rustdoc { + if let Some(rustdoc) = &toolchain_config.rustdoc { Some(rustdoc.canonicalize().with_context(|| { format!("failed to canonicalize rustdoc executable {:?}", rustdoc) })?) @@ -406,7 +442,7 @@ pub fn get_local_toolchain( }; let clippy = - if let Some(clippy) = &clippy { + if let Some(clippy) = &toolchain_config.clippy { Some(clippy.canonicalize().with_context(|| { format!("failed to canonicalize clippy executable {:?}", clippy) })?) @@ -425,7 +461,7 @@ pub fn get_local_toolchain( // No `clippy` provided, but none needed. None }; - let cargo = if let Some(cargo) = &cargo { + let cargo = if let Some(cargo) = &toolchain_config.cargo { cargo .canonicalize() .with_context(|| format!("failed to canonicalize cargo executable {:?}", cargo))? From e74d88dd54cbfb8c614e1291d7f7f92de058546b Mon Sep 17 00:00:00 2001 From: blyxyas Date: Sun, 24 Sep 2023 16:15:09 +0200 Subject: [PATCH 3/6] Don't run `cargo-clippy` if not available + Refactor + Remove Clippy from `Profile::all` --- collector/src/bin/collector.rs | 13 +++++++++++-- collector/src/compile/benchmark/profile.rs | 2 +- collector/src/toolchain.rs | 16 +++++----------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/collector/src/bin/collector.rs b/collector/src/bin/collector.rs index 3c34e2e75..11b1e641c 100644 --- a/collector/src/bin/collector.rs +++ b/collector/src/bin/collector.rs @@ -1197,9 +1197,18 @@ fn bench_published_artifact( let artifact_id = ArtifactId::Tag(toolchain.id.clone()); let profiles = if collector::version_supports_doc(&toolchain.id) { - Profile::all() + vec![ + Profile::Check, + Profile::Debug, + Profile::Doc, + Profile::Opt + ] } else { - Profile::all_non_doc() + vec![ + Profile::Check, + Profile::Debug, + Profile::Opt, + ] }; let scenarios = if collector::version_supports_incremental(&toolchain.id) { Scenario::all() diff --git a/collector/src/compile/benchmark/profile.rs b/collector/src/compile/benchmark/profile.rs index cb7e89bdc..6acd494ea 100644 --- a/collector/src/compile/benchmark/profile.rs +++ b/collector/src/compile/benchmark/profile.rs @@ -17,7 +17,7 @@ pub enum Profile { impl Profile { pub fn all() -> Vec { - vec![Profile::Check, Profile::Debug, Profile::Doc, Profile::Opt, Profile::Clippy] + vec![Profile::Check, Profile::Debug, Profile::Doc, Profile::Opt] } // This also leaves Clippy out diff --git a/collector/src/toolchain.rs b/collector/src/toolchain.rs index 58a33cf65..8970ba303 100644 --- a/collector/src/toolchain.rs +++ b/collector/src/toolchain.rs @@ -123,7 +123,10 @@ impl SysrootDownload { let components = ToolchainComponents::from_binaries_and_libdir( sysroot_bin("rustc")?, Some(sysroot_bin("rustdoc")?), - Some(sysroot_bin("clippy")?), + match sysroot_bin("cargo-clippy") { + Err(_) => None, + Ok(path) => Some(path) + }, sysroot_bin("cargo")?, &self.directory.join(&self.rust_sha).join("lib"), )?; @@ -292,7 +295,7 @@ impl ToolchainComponents { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Default)] pub struct ToolchainConfig<'a> { rustdoc: Option<&'a Path>, clippy: Option<&'a Path>, @@ -301,15 +304,6 @@ pub struct ToolchainConfig<'a> { } impl<'a> ToolchainConfig<'a> { - pub fn default() -> Self { - Self { - rustdoc: None, - clippy: None, - cargo: None, - id: None - } - } - pub fn rustdoc(&mut self, rustdoc: Option<&'a Path>) -> &mut Self { self.rustdoc = rustdoc; self From 36cee863c4cd2a6b21eabdada93a05fcdc29e07d Mon Sep 17 00:00:00 2001 From: blyxyas Date: Sun, 24 Sep 2023 16:19:52 +0200 Subject: [PATCH 4/6] Format --- collector/benchlib/src/benchmark.rs | 11 ++++-- collector/src/bin/collector.rs | 18 +++------- collector/src/toolchain.rs | 48 +++++++++++++++----------- database/src/lib.rs | 4 +-- site/src/request_handlers/dashboard.rs | 4 +-- 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/collector/benchlib/src/benchmark.rs b/collector/benchlib/src/benchmark.rs index 80c85da1a..f8222d3c3 100644 --- a/collector/benchlib/src/benchmark.rs +++ b/collector/benchlib/src/benchmark.rs @@ -119,8 +119,15 @@ impl<'a> BenchmarkGroup<'a> { fn profile_benchmark(self, args: ProfileArgs) -> anyhow::Result<()> { let Some(benchmark) = self.benchmarks.get(args.benchmark.as_str()) else { - return Err(anyhow::anyhow!("Benchmark `{}` not found. Available benchmarks: {}", args.benchmark, - self.benchmarks.keys().map(|s| s.to_string()).collect::>().join(", "))); + return Err(anyhow::anyhow!( + "Benchmark `{}` not found. Available benchmarks: {}", + args.benchmark, + self.benchmarks + .keys() + .map(|s| s.to_string()) + .collect::>() + .join(", ") + )); }; (benchmark.profile_fn)(); diff --git a/collector/src/bin/collector.rs b/collector/src/bin/collector.rs index 11b1e641c..91410e95f 100644 --- a/collector/src/bin/collector.rs +++ b/collector/src/bin/collector.rs @@ -38,7 +38,8 @@ use collector::runtime::{ }; use collector::runtime::{profile_runtime, RuntimeCompilationOpts}; use collector::toolchain::{ - create_toolchain_from_published_version, get_local_toolchain, Sysroot, Toolchain, ToolchainConfig, + create_toolchain_from_published_version, get_local_toolchain, Sysroot, Toolchain, + ToolchainConfig, }; use collector::utils::cachegrind::cachegrind_diff; use collector::utils::{is_installed, wait_for_future}; @@ -378,7 +379,7 @@ struct CompileTimeOptions { /// The path to the local clippy to measure #[arg(long)] - clippy: Option + clippy: Option, } #[derive(Debug, clap::Args)] @@ -1197,18 +1198,9 @@ fn bench_published_artifact( let artifact_id = ArtifactId::Tag(toolchain.id.clone()); let profiles = if collector::version_supports_doc(&toolchain.id) { - vec![ - Profile::Check, - Profile::Debug, - Profile::Doc, - Profile::Opt - ] + vec![Profile::Check, Profile::Debug, Profile::Doc, Profile::Opt] } else { - vec![ - Profile::Check, - Profile::Debug, - Profile::Opt, - ] + vec![Profile::Check, Profile::Debug, Profile::Opt] }; let scenarios = if collector::version_supports_incremental(&toolchain.id) { Scenario::all() diff --git a/collector/src/toolchain.rs b/collector/src/toolchain.rs index 8970ba303..5a1d334ea 100644 --- a/collector/src/toolchain.rs +++ b/collector/src/toolchain.rs @@ -125,7 +125,7 @@ impl SysrootDownload { Some(sysroot_bin("rustdoc")?), match sysroot_bin("cargo-clippy") { Err(_) => None, - Ok(path) => Some(path) + Ok(path) => Some(path), }, sysroot_bin("cargo")?, &self.directory.join(&self.rust_sha).join("lib"), @@ -435,26 +435,27 @@ pub fn get_local_toolchain( None }; - let clippy = - if let Some(clippy) = &toolchain_config.clippy { - Some(clippy.canonicalize().with_context(|| { + let clippy = if let Some(clippy) = &toolchain_config.clippy { + Some( + clippy.canonicalize().with_context(|| { format!("failed to canonicalize clippy executable {:?}", clippy) - })?) - } else if profiles.contains(&Profile::Clippy) { - // We need a `clippy`. Look for one next to `rustc`. - if let Ok(clippy) = rustc.with_file_name("cargo-clippy").canonicalize() { - debug!("found clippy: {:?}", &clippy); - Some(clippy) - } else { - anyhow::bail!( + })?, + ) + } else if profiles.contains(&Profile::Clippy) { + // We need a `clippy`. Look for one next to `rustc`. + if let Ok(clippy) = rustc.with_file_name("cargo-clippy").canonicalize() { + debug!("found clippy: {:?}", &clippy); + Some(clippy) + } else { + anyhow::bail!( "'Clippy' build specified but '--clippy' not specified and no 'cargo-clippy' found \ next to 'rustc'" ); - } - } else { - // No `clippy` provided, but none needed. - None - }; + } + } else { + // No `clippy` provided, but none needed. + None + }; let cargo = if let Some(cargo) = &toolchain_config.cargo { cargo .canonicalize() @@ -483,7 +484,9 @@ pub fn get_local_toolchain( let lib_dir = get_lib_dir_from_rustc(&rustc).context("Cannot find libdir for rustc")?; Ok(Toolchain { - components: ToolchainComponents::from_binaries_and_libdir(rustc, rustdoc, clippy, cargo, &lib_dir)?, + components: ToolchainComponents::from_binaries_and_libdir( + rustc, rustdoc, clippy, cargo, &lib_dir, + )?, id, triple: target_triple, }) @@ -530,8 +533,13 @@ pub fn create_toolchain_from_published_version( let lib_dir = get_lib_dir_from_rustc(&rustc)?; - let components = - ToolchainComponents::from_binaries_and_libdir(rustc, Some(rustdoc), Some(clippy), cargo, &lib_dir)?; + let components = ToolchainComponents::from_binaries_and_libdir( + rustc, + Some(rustdoc), + Some(clippy), + cargo, + &lib_dir, + )?; Ok(Toolchain { components, diff --git a/database/src/lib.rs b/database/src/lib.rs index 4c827a32c..1265590c5 100644 --- a/database/src/lib.rs +++ b/database/src/lib.rs @@ -225,7 +225,7 @@ pub enum Profile { /// An optimized "release" build Opt, /// A Clippy run - Clippy + Clippy, } impl Profile { @@ -235,7 +235,7 @@ impl Profile { Profile::Opt => "opt", Profile::Debug => "debug", Profile::Doc => "doc", - Profile::Clippy => "clippy" + Profile::Clippy => "clippy", } } } diff --git a/site/src/request_handlers/dashboard.rs b/site/src/request_handlers/dashboard.rs index 98f422661..cceba421c 100644 --- a/site/src/request_handlers/dashboard.rs +++ b/site/src/request_handlers/dashboard.rs @@ -150,7 +150,7 @@ pub struct ByProfile { pub debug: T, pub doc: T, pub opt: T, - pub clippy: T + pub clippy: T, } impl ByProfile { @@ -177,7 +177,7 @@ impl std::ops::Index for ByProfile { Profile::Debug => &self.debug, Profile::Doc => &self.doc, Profile::Opt => &self.opt, - Profile::Clippy => &self.clippy + Profile::Clippy => &self.clippy, } } } From 9a2089d3e8985a5e6b424bff270578d202feb218 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 25 Sep 2023 17:13:25 +0200 Subject: [PATCH 5/6] Fix typo --- collector/src/toolchain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/src/toolchain.rs b/collector/src/toolchain.rs index 5a1d334ea..7a8e81e67 100644 --- a/collector/src/toolchain.rs +++ b/collector/src/toolchain.rs @@ -448,7 +448,7 @@ pub fn get_local_toolchain( Some(clippy) } else { anyhow::bail!( - "'Clippy' build specified but '--clippy' not specified and no 'cargo-clippy' found \ + "'Clippy' build specified but '--cargo-clippy' not specified and no 'cargo-clippy' found \ next to 'rustc'" ); } From 2f6ae0f14cc1b74a220e4df5f0dbeec742a670ed Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 25 Sep 2023 17:33:21 +0200 Subject: [PATCH 6/6] Mini stylistic choice --- collector/src/toolchain.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/collector/src/toolchain.rs b/collector/src/toolchain.rs index 7a8e81e67..4171789f8 100644 --- a/collector/src/toolchain.rs +++ b/collector/src/toolchain.rs @@ -123,10 +123,7 @@ impl SysrootDownload { let components = ToolchainComponents::from_binaries_and_libdir( sysroot_bin("rustc")?, Some(sysroot_bin("rustdoc")?), - match sysroot_bin("cargo-clippy") { - Err(_) => None, - Ok(path) => Some(path), - }, + sysroot_bin("cargo-clippy").ok(), sysroot_bin("cargo")?, &self.directory.join(&self.rust_sha).join("lib"), )?;