Skip to content

Commit

Permalink
Integrate Clippy into rustc-perf
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxyas committed Sep 20, 2023
1 parent 1d1400b commit f7fecde
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ impl Profiles {
.dir_names
.insert(InternedString::new("doc"), InternedString::new("debug"));

profile_makers.by_name.insert(
InternedString::new("clippy"),
ProfileMaker::new(Profile::default_dev(), profiles.remove("clippy"))
);
profile_makers
.dir_names
.insert(InternedString::new("clippy"), InternedString::new("debug"));

return Ok(profile_makers);
}

Expand Down
9 changes: 9 additions & 0 deletions collector/src/bin/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ struct CompileTimeOptions {
/// The path to the local rustdoc to measure
#[arg(long)]
rustdoc: Option<PathBuf>,

/// The path to the local clippy to measure
#[arg(long)]
clippy: Option<PathBuf>
}

#[derive(Debug, clap::Args)]
Expand Down Expand Up @@ -663,6 +667,7 @@ fn main_result() -> anyhow::Result<i32> {
None,
None,
None,
None,
id,
target_triple.clone(),
)?;
Expand Down Expand Up @@ -721,6 +726,7 @@ fn main_result() -> anyhow::Result<i32> {
None,
None,
None,
None,
id,
target_triple.clone(),
)?;
Expand Down Expand Up @@ -757,6 +763,7 @@ fn main_result() -> anyhow::Result<i32> {
&profiles,
&local.rustc,
opts.rustdoc.as_deref(),
opts.clippy.as_deref(),
local.cargo.as_deref(),
local.id.as_deref(),
"",
Expand Down Expand Up @@ -949,6 +956,7 @@ fn main_result() -> anyhow::Result<i32> {
profiles,
rustc,
opts.rustdoc.as_deref(),
opts.clippy.as_deref(),
local.cargo.as_deref(),
local.id.as_deref(),
suffix,
Expand Down Expand Up @@ -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(),
"",
Expand Down
3 changes: 3 additions & 0 deletions collector/src/bin/rustc-fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ fn main() {
let mut args = args_os.collect::<Vec<_>>();
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
};
Expand Down
4 changes: 3 additions & 1 deletion collector/src/compile/benchmark/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ pub enum Profile {
Debug,
Doc,
Opt,
Clippy,
}

impl Profile {
pub fn all() -> Vec<Self> {
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<Self> {
vec![Profile::Check, Profile::Debug, Profile::Opt]
}
Expand Down
1 change: 1 addition & 0 deletions collector/src/compile/execute/bencher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 21 additions & 1 deletion collector/src/compile/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -236,6 +240,7 @@ impl<'a> CargoProcess<'a> {
}
Profile::Debug => {}
Profile::Doc => {}
Profile::Clippy => {}
Profile::Opt => {
cmd.arg("--release");
}
Expand Down Expand Up @@ -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.
Expand Down
31 changes: 29 additions & 2 deletions collector/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)?;
Expand Down Expand Up @@ -241,6 +242,7 @@ impl Toolchain {
pub struct ToolchainComponents {
pub rustc: PathBuf,
pub rustdoc: Option<PathBuf>,
pub clippy: Option<PathBuf>,
pub cargo: PathBuf,
pub lib_rustc: Option<PathBuf>,
pub lib_std: Option<PathBuf>,
Expand All @@ -252,12 +254,14 @@ impl ToolchainComponents {
fn from_binaries_and_libdir(
rustc: PathBuf,
rustdoc: Option<PathBuf>,
clippy: Option<PathBuf>,
cargo: PathBuf,
libdir: &Path,
) -> anyhow::Result<Self> {
let mut component = ToolchainComponents {
rustc,
rustdoc,
clippy,
cargo,
..Default::default()
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 rustdoc 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("clippy").canonicalize() {
debug!("found clippy: {:?}", &clippy);
Some(clippy)
} else {
anyhow::bail!(
"'Clippy' build specified but '--clippy' not specified and no 'clippy' found \
next to 'rustc'"
);
}
} else {
// No `clippy` provided, but none needed.
None
};
let cargo = if let Some(cargo) = &cargo {
cargo
.canonicalize()
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion database/src/bin/postgres-to-sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Table for PullRequestBuild {
}

fn sqlite_insert_statement(&self) -> &'static str {
"insert into pull_request_build (bors_sha, pr, parent_sha, complete, requested, include, exclude, runs) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
"insert into pull_request_build (bors_sha, pr, parent_sha, complete, requested, include, exclude, runs, profile) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
}

fn sqlite_execute_insert(&self, statement: &mut rusqlite::Statement, row: tokio_postgres::Row) {
Expand All @@ -295,6 +295,7 @@ impl Table for PullRequestBuild {
row.get::<_, Option<&str>>(5),
row.get::<_, Option<&str>>(6),
row.get::<_, Option<i32>>(7),
row.get::<_, Option<&str>>(8),
])
.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion database/src/bin/sqlite-to-postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl Table for PullRequestBuild {
}

fn sqlite_attributes() -> &'static str {
"bors_sha, pr, parent_sha, complete, requested, include, exclude, runs"
"bors_sha, pr, parent_sha, complete, requested, include, exclude, runs, profile"
}

fn postgres_generated_id_attribute() -> Option<&'static str> {
Expand Down
4 changes: 4 additions & 0 deletions database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ pub enum Profile {
Doc,
/// An optimized "release" build
Opt,
/// A Clippy run
Clippy
}

impl Profile {
Expand All @@ -233,6 +235,7 @@ impl Profile {
Profile::Opt => "opt",
Profile::Debug => "debug",
Profile::Doc => "doc",
Profile::Clippy => "clippy"
}
}
}
Expand All @@ -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)),
})
}
Expand Down
1 change: 1 addition & 0 deletions database/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub trait Connection: Send + Sync {
include: Option<&str>,
exclude: Option<&str>,
runs: Option<i32>,
profile: Option<&str>
);
/// Returns true if this PR was queued waiting for a commit
async fn pr_attach_commit(
Expand Down
7 changes: 4 additions & 3 deletions database/src/pool/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,12 @@ where
include: Option<&str>,
exclude: Option<&str>,
runs: Option<i32>,
profile: Option<&str>
) {
if let Err(e) = self.conn()
.execute(
"insert into pull_request_build (pr, complete, requested, include, exclude, runs) VALUES ($1, false, CURRENT_TIMESTAMP, $2, $3, $4)",
&[&(pr as i32), &include, &exclude, &runs],
"insert into pull_request_build (pr, complete, requested, include, exclude, runs, profile) VALUES ($1, false, CURRENT_TIMESTAMP, $2, $3, $4)",
&[&(pr as i32), &include, &exclude, &runs, &profile],
)
.await {
log::error!("failed to queue_pr({}, {:?}, {:?}, {:?}): {:?}", pr, include, exclude, runs, e);
Expand Down Expand Up @@ -785,7 +786,7 @@ where
.query_opt(
"update pull_request_build SET complete = true
where bors_sha = $1
returning pr, bors_sha, parent_sha, include, exclude, runs, commit_date",
returning pr, bors_sha, parent_sha, include, exclude, runs, profile, commit_date",
&[&sha],
)
.await
Expand Down
5 changes: 3 additions & 2 deletions database/src/pool/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,14 @@ impl Connection for SqliteConnection {
include: Option<&str>,
exclude: Option<&str>,
runs: Option<i32>,
profile: Option<&str>
) {
self.raw_ref()
.prepare_cached(
"insert into pull_request_build (pr, complete, requested, include, exclude, runs) VALUES (?, 0, strftime('%s','now'), ?, ?, ?)",
"insert into pull_request_build (pr, complete, requested, include, exclude, runs, profile) VALUES (?, 0, strftime('%s','now'), ?, ?, ?, ?)",
)
.unwrap()
.execute(params![pr, include, exclude, &runs])
.execute(params![pr, include, exclude, &runs, profile])
.unwrap();
}
async fn pr_attach_commit(
Expand Down
2 changes: 1 addition & 1 deletion site/src/github/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BOT_USER_AGENT: &str = "perf-rust-lang-org-server";

/// A client for interacting with the GitHub API
pub struct Client {
repository_url: String,
pub repository_url: String,
token: String,
inner: reqwest::Client,
}
Expand Down
3 changes: 3 additions & 0 deletions site/src/request_handlers/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub struct ByProfile<T> {
pub debug: T,
pub doc: T,
pub opt: T,
pub clippy: T
}

impl<T> ByProfile<T> {
Expand All @@ -163,6 +164,7 @@ impl<T> ByProfile<T> {
debug: f(Profile::Debug).await?,
doc: f(Profile::Doc).await?,
opt: f(Profile::Opt).await?,
clippy: f(Profile::Clippy).await?,
})
}
}
Expand All @@ -175,6 +177,7 @@ impl<T> std::ops::Index<Profile> for ByProfile<T> {
Profile::Debug => &self.debug,
Profile::Doc => &self.doc,
Profile::Opt => &self.opt,
Profile::Clippy => &self.clippy
}
}
}
Loading

0 comments on commit f7fecde

Please sign in to comment.