Skip to content

Commit 19bb97f

Browse files
committed
Clippy locally
1 parent 1d1400b commit 19bb97f

File tree

8 files changed

+73
-4
lines changed

8 files changed

+73
-4
lines changed

collector/src/bin/collector.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ struct CompileTimeOptions {
375375
/// The path to the local rustdoc to measure
376376
#[arg(long)]
377377
rustdoc: Option<PathBuf>,
378+
379+
/// The path to the local clippy to measure
380+
#[arg(long)]
381+
clippy: Option<PathBuf>
378382
}
379383

380384
#[derive(Debug, clap::Args)]
@@ -663,6 +667,7 @@ fn main_result() -> anyhow::Result<i32> {
663667
None,
664668
None,
665669
None,
670+
None,
666671
id,
667672
target_triple.clone(),
668673
)?;
@@ -721,6 +726,7 @@ fn main_result() -> anyhow::Result<i32> {
721726
None,
722727
None,
723728
None,
729+
None,
724730
id,
725731
target_triple.clone(),
726732
)?;
@@ -757,6 +763,7 @@ fn main_result() -> anyhow::Result<i32> {
757763
&profiles,
758764
&local.rustc,
759765
opts.rustdoc.as_deref(),
766+
opts.clippy.as_deref(),
760767
local.cargo.as_deref(),
761768
local.id.as_deref(),
762769
"",
@@ -949,6 +956,7 @@ fn main_result() -> anyhow::Result<i32> {
949956
profiles,
950957
rustc,
951958
opts.rustdoc.as_deref(),
959+
opts.clippy.as_deref(),
952960
local.cargo.as_deref(),
953961
local.id.as_deref(),
954962
suffix,
@@ -1063,6 +1071,7 @@ fn get_local_toolchain_for_runtime_benchmarks(
10631071
&[Profile::Opt],
10641072
&local.rustc,
10651073
None,
1074+
None,
10661075
local.cargo.as_deref(),
10671076
local.id.as_deref(),
10681077
"",

collector/src/bin/rustc-fake.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ fn main() {
3535
let mut args = args_os.collect::<Vec<_>>();
3636
let rustc = env::var_os("RUSTC_REAL").unwrap();
3737
let actually_rustdoc = name.ends_with("rustdoc-fake");
38+
let actually_clippy = name.ends_with("clippy-fake");
3839
let tool = if actually_rustdoc {
3940
env::var_os("RUSTDOC_REAL").unwrap()
41+
} else if actually_clippy {
42+
env::var_os("CLIPPY_REAL").unwrap()
4043
} else {
4144
rustc
4245
};

collector/src/compile/benchmark/profile.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ pub enum Profile {
1212
Debug,
1313
Doc,
1414
Opt,
15+
Clippy,
1516
}
1617

1718
impl Profile {
1819
pub fn all() -> Vec<Self> {
19-
vec![Profile::Check, Profile::Debug, Profile::Doc, Profile::Opt]
20+
vec![Profile::Check, Profile::Debug, Profile::Doc, Profile::Opt, Profile::Clippy]
2021
}
2122

23+
// This also leaves Clippy out
2224
pub fn all_non_doc() -> Vec<Self> {
2325
vec![Profile::Check, Profile::Debug, Profile::Opt]
2426
}

collector/src/compile/execute/bencher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl<'a> BenchProcessor<'a> {
8787
Profile::Debug => database::Profile::Debug,
8888
Profile::Doc => database::Profile::Doc,
8989
Profile::Opt => database::Profile::Opt,
90+
Profile::Clippy => database::Profile::Clippy,
9091
};
9192

9293
if let Some(files) = stats.2 {

collector/src/compile/execute/mod.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl PerfTool {
7272
}
7373
ProfileTool(LlvmLines) => match profile {
7474
Profile::Debug | Profile::Opt => Some("llvm-lines"),
75-
Profile::Check | Profile::Doc => None,
75+
Profile::Check | Profile::Doc | Profile::Clippy => None,
7676
},
7777
}
7878
}
@@ -168,6 +168,10 @@ impl<'a> CargoProcess<'a> {
168168

169169
if let Some(r) = &self.toolchain.components.rustdoc {
170170
cmd.env("RUSTDOC", &*FAKE_RUSTDOC).env("RUSTDOC_REAL", r);
171+
};
172+
173+
if let Some(c) = &self.toolchain.components.clippy {
174+
cmd.env("CLIPPY", &*FAKE_CLIPPY).env("CLIPPY_REAL", c);
171175
}
172176
cmd
173177
}
@@ -236,6 +240,7 @@ impl<'a> CargoProcess<'a> {
236240
}
237241
Profile::Debug => {}
238242
Profile::Doc => {}
243+
Profile::Clippy => {}
239244
Profile::Opt => {
240245
cmd.arg("--release");
241246
}
@@ -354,6 +359,21 @@ lazy_static::lazy_static! {
354359
}
355360
fake_rustdoc
356361
};
362+
static ref FAKE_CLIPPY: PathBuf = {
363+
let mut fake_clippy = env::current_exe().unwrap();
364+
fake_clippy.pop();
365+
fake_clippy.push("clippy-fake");
366+
// link from rustc-fake to rustdoc-fake
367+
if !fake_clippy.exists() {
368+
#[cfg(unix)]
369+
use std::os::unix::fs::symlink;
370+
#[cfg(windows)]
371+
use std::os::windows::fs::symlink_file as symlink;
372+
373+
symlink(&*FAKE_RUSTC, &fake_clippy).expect("failed to make symbolic link");
374+
}
375+
fake_clippy
376+
};
357377
}
358378

359379
/// Used to indicate if we need to retry a run.

collector/src/toolchain.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl SysrootDownload {
123123
let components = ToolchainComponents::from_binaries_and_libdir(
124124
sysroot_bin("rustc")?,
125125
Some(sysroot_bin("rustdoc")?),
126+
Some(sysroot_bin("clippy")?),
126127
sysroot_bin("cargo")?,
127128
&self.directory.join(&self.rust_sha).join("lib"),
128129
)?;
@@ -241,6 +242,7 @@ impl Toolchain {
241242
pub struct ToolchainComponents {
242243
pub rustc: PathBuf,
243244
pub rustdoc: Option<PathBuf>,
245+
pub clippy: Option<PathBuf>,
244246
pub cargo: PathBuf,
245247
pub lib_rustc: Option<PathBuf>,
246248
pub lib_std: Option<PathBuf>,
@@ -252,12 +254,14 @@ impl ToolchainComponents {
252254
fn from_binaries_and_libdir(
253255
rustc: PathBuf,
254256
rustdoc: Option<PathBuf>,
257+
clippy: Option<PathBuf>,
255258
cargo: PathBuf,
256259
libdir: &Path,
257260
) -> anyhow::Result<Self> {
258261
let mut component = ToolchainComponents {
259262
rustc,
260263
rustdoc,
264+
clippy,
261265
cargo,
262266
..Default::default()
263267
};
@@ -298,6 +302,7 @@ pub fn get_local_toolchain(
298302
profiles: &[Profile],
299303
rustc: &str,
300304
rustdoc: Option<&Path>,
305+
clippy: Option<&Path>,
301306
cargo: Option<&Path>,
302307
id: Option<&str>,
303308
id_suffix: &str,
@@ -400,6 +405,26 @@ pub fn get_local_toolchain(
400405
None
401406
};
402407

408+
let clippy =
409+
if let Some(clippy) = &clippy {
410+
Some(clippy.canonicalize().with_context(|| {
411+
format!("failed to canonicalize clippy executable {:?}", clippy)
412+
})?)
413+
} else if profiles.contains(&Profile::Clippy) {
414+
// We need a `clippy`. Look for one next to `rustc`.
415+
if let Ok(clippy) = rustc.with_file_name("cargo-clippy").canonicalize() {
416+
debug!("found clippy: {:?}", &clippy);
417+
Some(clippy)
418+
} else {
419+
anyhow::bail!(
420+
"'Clippy' build specified but '--clippy' not specified and no 'cargo-clippy' found \
421+
next to 'rustc'"
422+
);
423+
}
424+
} else {
425+
// No `clippy` provided, but none needed.
426+
None
427+
};
403428
let cargo = if let Some(cargo) = &cargo {
404429
cargo
405430
.canonicalize()
@@ -428,7 +453,7 @@ pub fn get_local_toolchain(
428453
let lib_dir = get_lib_dir_from_rustc(&rustc).context("Cannot find libdir for rustc")?;
429454

430455
Ok(Toolchain {
431-
components: ToolchainComponents::from_binaries_and_libdir(rustc, rustdoc, cargo, &lib_dir)?,
456+
components: ToolchainComponents::from_binaries_and_libdir(rustc, rustdoc, clippy, cargo, &lib_dir)?,
432457
id,
433458
triple: target_triple,
434459
})
@@ -465,16 +490,18 @@ pub fn create_toolchain_from_published_version(
465490
};
466491
let rustc = which("rustc")?;
467492
let rustdoc = which("rustdoc")?;
493+
let clippy = which("clippy")?;
468494
let cargo = which("cargo")?;
469495

470496
debug!("Found rustc: {}", rustc.display());
471497
debug!("Found rustdoc: {}", rustdoc.display());
498+
debug!("Found clippy: {}", clippy.display());
472499
debug!("Found cargo: {}", cargo.display());
473500

474501
let lib_dir = get_lib_dir_from_rustc(&rustc)?;
475502

476503
let components =
477-
ToolchainComponents::from_binaries_and_libdir(rustc, Some(rustdoc), cargo, &lib_dir)?;
504+
ToolchainComponents::from_binaries_and_libdir(rustc, Some(rustdoc), Some(clippy), cargo, &lib_dir)?;
478505

479506
Ok(Toolchain {
480507
components,

database/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ pub enum Profile {
224224
Doc,
225225
/// An optimized "release" build
226226
Opt,
227+
/// A Clippy run
228+
Clippy
227229
}
228230

229231
impl Profile {
@@ -233,6 +235,7 @@ impl Profile {
233235
Profile::Opt => "opt",
234236
Profile::Debug => "debug",
235237
Profile::Doc => "doc",
238+
Profile::Clippy => "clippy"
236239
}
237240
}
238241
}
@@ -245,6 +248,7 @@ impl std::str::FromStr for Profile {
245248
"debug" => Profile::Debug,
246249
"doc" => Profile::Doc,
247250
"opt" => Profile::Opt,
251+
"clippy" => Profile::Clippy,
248252
_ => return Err(format!("{} is not a profile", s)),
249253
})
250254
}

site/src/request_handlers/dashboard.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pub struct ByProfile<T> {
150150
pub debug: T,
151151
pub doc: T,
152152
pub opt: T,
153+
pub clippy: T
153154
}
154155

155156
impl<T> ByProfile<T> {
@@ -163,6 +164,7 @@ impl<T> ByProfile<T> {
163164
debug: f(Profile::Debug).await?,
164165
doc: f(Profile::Doc).await?,
165166
opt: f(Profile::Opt).await?,
167+
clippy: f(Profile::Clippy).await?,
166168
})
167169
}
168170
}
@@ -175,6 +177,7 @@ impl<T> std::ops::Index<Profile> for ByProfile<T> {
175177
Profile::Debug => &self.debug,
176178
Profile::Doc => &self.doc,
177179
Profile::Opt => &self.opt,
180+
Profile::Clippy => &self.clippy
178181
}
179182
}
180183
}

0 commit comments

Comments
 (0)