Skip to content

Commit

Permalink
Auto merge of rust-lang#6781 - matthiaskrgr:lintcheck_fix, r=matthias…
Browse files Browse the repository at this point in the history
…krgr

lintcheck fix build (forgot to pass function parameter) and runtime (…

…don't check metadata of directory if it does not exist)

Accidentally broke lintcheck in my previous commit.

changelog: None
  • Loading branch information
bors committed Feb 23, 2021
2 parents f02df27 + eaae95b commit a5c5c8f
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions clippy_dev/src/lintcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,14 @@ fn filter_clippy_warnings(line: &str) -> bool {

/// get the path to lintchecks crate sources .toml file, check LINTCHECK_TOML first but if it's
/// empty use the default path
fn lintcheck_config_toml() -> PathBuf {
fn lintcheck_config_toml(toml_path: Option<&str>) -> PathBuf {
PathBuf::from(
env::var("LINTCHECK_TOML").unwrap_or(toml_path.unwrap_or("clippy_dev/lintcheck_crates.toml").to_string()),
env::var("LINTCHECK_TOML").unwrap_or(
toml_path
.clone()
.unwrap_or("clippy_dev/lintcheck_crates.toml")
.to_string(),
),
)
}

Expand All @@ -332,7 +337,7 @@ fn build_clippy() {

/// Read a `toml` file and return a list of `CrateSources` that we want to check with clippy
fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
let toml_path = lintcheck_config_toml();
let toml_path = lintcheck_config_toml(toml_path);
// save it so that we can use the name of the sources.toml as name for the logfile later.
let toml_filename = toml_path.file_stem().unwrap().to_str().unwrap().to_string();
let toml_content: String =
Expand Down Expand Up @@ -444,10 +449,10 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> String {

/// check if the latest modification of the logfile is older than the modification date of the
/// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck
fn lintcheck_needs_rerun() -> bool {
fn lintcheck_needs_rerun(toml_path: Option<&str>) -> bool {
let clippy_modified: std::time::SystemTime = {
let mut times = ["target/debug/clippy-driver", "target/debug/cargo-clippy"]
.into_iter()
.iter()
.map(|p| {
std::fs::metadata(p)
.expect("failed to get metadata of file")
Expand All @@ -458,7 +463,7 @@ fn lintcheck_needs_rerun() -> bool {
std::cmp::max(times.next().unwrap(), times.next().unwrap())
};

let logs_modified: std::time::SystemTime = std::fs::metadata(lintcheck_config_toml())
let logs_modified: std::time::SystemTime = std::fs::metadata(lintcheck_config_toml(toml_path))
.expect("failed to get metadata of file")
.modified()
.expect("failed to get modification date");
Expand All @@ -473,16 +478,22 @@ pub fn run(clap_config: &ArgMatches) {
build_clippy();
println!("Done compiling");

let clap_toml_path = clap_config.value_of("crates-toml");

// if the clippy bin is newer than our logs, throw away target dirs to force clippy to
// refresh the logs
if lintcheck_needs_rerun() {
if lintcheck_needs_rerun(clap_toml_path) {
let shared_target_dir = "target/lintcheck/shared_target_dir";
if std::fs::metadata(&shared_target_dir)
.expect("failed to get metadata of shared target dir")
.is_dir()
{
println!("Clippy is newer than lint check logs, clearing lintcheck shared target dir...");
std::fs::remove_dir_all(&shared_target_dir).expect("failed to remove target/lintcheck/shared_target_dir");
match std::fs::metadata(&shared_target_dir) {
Ok(metadata) => {
if metadata.is_dir() {
println!("Clippy is newer than lint check logs, clearing lintcheck shared target dir...");
std::fs::remove_dir_all(&shared_target_dir)
.expect("failed to remove target/lintcheck/shared_target_dir");
}
},
Err(_) => { // dir probably does not exist, don't remove anything
},
}
}

Expand All @@ -506,7 +517,7 @@ pub fn run(clap_config: &ArgMatches) {
// download and extract the crates, then run clippy on them and collect clippys warnings
// flatten into one big list of warnings

let (filename, crates) = read_crates(clap_config.value_of("crates-toml"));
let (filename, crates) = read_crates(clap_toml_path);

let clippy_warnings: Vec<ClippyWarning> = if let Some(only_one_crate) = clap_config.value_of("only") {
// if we don't have the specified crate in the .toml, throw an error
Expand Down

0 comments on commit a5c5c8f

Please sign in to comment.