-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dogfood and CI fixes #6849
Merged
Merged
Dogfood and CI fixes #6849
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26265bb
ci: Sync clippy and clippy_bors workflows
flip1995 5ebe6d3
Fix dogfood test
flip1995 3c502ec
Remove hack that forces dogfood to run on nightly
flip1995 1d71d9a
Fix dogfood errors in clippy_lints
flip1995 4aaad08
Fix dogfood errors in clippy_dev
flip1995 74eb448
Extract directory creation into its own function
flip1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,12 @@ | |
|
||
#![cfg(feature = "lintcheck")] | ||
#![allow(clippy::filter_map, clippy::collapsible_else_if)] | ||
#![allow(clippy::blocks_in_if_conditions)] // FP on `if x.iter().any(|x| ...)` | ||
|
||
use crate::clippy_project_root; | ||
|
||
use std::collections::HashMap; | ||
use std::process::Command; | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
use std::{collections::HashMap, io::ErrorKind}; | ||
use std::{ | ||
env, fmt, | ||
fs::write, | ||
|
@@ -116,9 +115,21 @@ impl CrateSource { | |
// url to download the crate from crates.io | ||
let url = format!("https://crates.io/api/v1/crates/{}/{}/download", name, version); | ||
println!("Downloading and extracting {} {} from {}", name, version, url); | ||
let _ = std::fs::create_dir("target/lintcheck/"); | ||
let _ = std::fs::create_dir(&krate_download_dir); | ||
let _ = std::fs::create_dir(&extract_dir); | ||
std::fs::create_dir("target/lintcheck/").unwrap_or_else(|err| { | ||
if err.kind() != ErrorKind::AlreadyExists { | ||
panic!("cannot create lintcheck target dir"); | ||
} | ||
}); | ||
std::fs::create_dir(&krate_download_dir).unwrap_or_else(|err| { | ||
if err.kind() != ErrorKind::AlreadyExists { | ||
panic!("cannot create crate download dir"); | ||
} | ||
}); | ||
std::fs::create_dir(&extract_dir).unwrap_or_else(|err| { | ||
if err.kind() != ErrorKind::AlreadyExists { | ||
panic!("cannot create crate extraction dir"); | ||
} | ||
}); | ||
|
||
let krate_file_path = krate_download_dir.join(format!("{}-{}.crate.tar.gz", name, version)); | ||
// don't download/extract if we already have done so | ||
|
@@ -198,18 +209,18 @@ impl CrateSource { | |
// the source path of the crate we copied, ${copy_dest}/crate_name | ||
let crate_root = copy_dest.join(name); // .../crates/local_crate | ||
|
||
if !crate_root.exists() { | ||
println!("Copying {} to {}", path.display(), copy_dest.display()); | ||
|
||
dir::copy(path, ©_dest, &dir::CopyOptions::new()).unwrap_or_else(|_| { | ||
panic!("Failed to copy from {}, to {}", path.display(), crate_root.display()) | ||
}); | ||
} else { | ||
if crate_root.exists() { | ||
println!( | ||
"Not copying {} to {}, destination already exists", | ||
path.display(), | ||
crate_root.display() | ||
); | ||
} else { | ||
println!("Copying {} to {}", path.display(), copy_dest.display()); | ||
|
||
dir::copy(path, ©_dest, &dir::CopyOptions::new()).unwrap_or_else(|_| { | ||
panic!("Failed to copy from {}, to {}", path.display(), crate_root.display()) | ||
}); | ||
} | ||
|
||
Crate { | ||
|
@@ -236,8 +247,8 @@ impl Crate { | |
// advance the atomic index by one | ||
let index = target_dir_index.fetch_add(1, Ordering::SeqCst); | ||
// "loop" the index within 0..thread_limit | ||
let target_dir_index = index % thread_limit; | ||
let perc = ((index * 100) as f32 / total_crates_to_lint as f32) as u8; | ||
let thread_index = index % thread_limit; | ||
let perc = (index * 100) / total_crates_to_lint; | ||
|
||
if thread_limit == 1 { | ||
println!( | ||
|
@@ -247,7 +258,7 @@ impl Crate { | |
} else { | ||
println!( | ||
"{}/{} {}% Linting {} {} in target dir {:?}", | ||
index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index | ||
index, total_crates_to_lint, perc, &self.name, &self.version, thread_index | ||
); | ||
} | ||
|
||
|
@@ -269,7 +280,7 @@ impl Crate { | |
// use the looping index to create individual target dirs | ||
.env( | ||
"CARGO_TARGET_DIR", | ||
shared_target_dir.join(format!("_{:?}", target_dir_index)), | ||
shared_target_dir.join(format!("_{:?}", thread_index)), | ||
) | ||
// lint warnings will look like this: | ||
// src/cargo/ops/cargo_compile.rs:127:35: warning: usage of `FromIterator::from_iter` | ||
|
@@ -529,6 +540,10 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool { | |
} | ||
|
||
/// lintchecks `main()` function | ||
/// | ||
/// # Panics | ||
/// | ||
/// This function panics if the clippy binaries don't exist. | ||
pub fn run(clap_config: &ArgMatches) { | ||
let config = LintcheckConfig::from_clap(clap_config); | ||
|
||
|
@@ -579,9 +594,9 @@ pub fn run(clap_config: &ArgMatches) { | |
// if we don't have the specified crate in the .toml, throw an error | ||
if !crates.iter().any(|krate| { | ||
let name = match krate { | ||
CrateSource::CratesIo { name, .. } => name, | ||
CrateSource::Git { name, .. } => name, | ||
CrateSource::Path { name, .. } => name, | ||
CrateSource::CratesIo { name, .. } | CrateSource::Git { name, .. } | CrateSource::Path { name, .. } => { | ||
name | ||
}, | ||
}; | ||
Comment on lines
582
to
586
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's super neat, I'll have to remember that! :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an auto-fixable Clippy lint 😉 |
||
name == only_one_crate | ||
}) { | ||
|
@@ -597,8 +612,7 @@ pub fn run(clap_config: &ArgMatches) { | |
.into_iter() | ||
.map(|krate| krate.download_and_extract()) | ||
.filter(|krate| krate.name == only_one_crate) | ||
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1)) | ||
.flatten() | ||
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1)) | ||
.collect() | ||
} else { | ||
if config.max_jobs > 1 { | ||
|
@@ -621,17 +635,15 @@ pub fn run(clap_config: &ArgMatches) { | |
crates | ||
.into_par_iter() | ||
.map(|krate| krate.download_and_extract()) | ||
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus, num_crates)) | ||
.flatten() | ||
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus, num_crates)) | ||
.collect() | ||
} else { | ||
// run sequential | ||
let num_crates = crates.len(); | ||
crates | ||
.into_iter() | ||
.map(|krate| krate.download_and_extract()) | ||
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates)) | ||
.flatten() | ||
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates)) | ||
.collect() | ||
} | ||
}; | ||
|
@@ -646,7 +658,7 @@ pub fn run(clap_config: &ArgMatches) { | |
.map(|w| (&w.crate_name, &w.message)) | ||
.collect(); | ||
|
||
let mut all_msgs: Vec<String> = clippy_warnings.iter().map(|warning| warning.to_string()).collect(); | ||
let mut all_msgs: Vec<String> = clippy_warnings.iter().map(ToString::to_string).collect(); | ||
all_msgs.sort(); | ||
all_msgs.push("\n\n\n\nStats:\n".into()); | ||
all_msgs.push(stats_formatted); | ||
|
@@ -673,13 +685,13 @@ fn read_stats_from_file(file_path: &Path) -> HashMap<String, usize> { | |
}, | ||
}; | ||
|
||
let lines: Vec<String> = file_content.lines().map(|l| l.to_string()).collect(); | ||
let lines: Vec<String> = file_content.lines().map(ToString::to_string).collect(); | ||
|
||
// search for the beginning "Stats:" and the end "ICEs:" of the section we want | ||
let start = lines.iter().position(|line| line == "Stats:").unwrap(); | ||
let end = lines.iter().position(|line| line == "ICEs:").unwrap(); | ||
|
||
let stats_lines = &lines[start + 1..=end - 1]; | ||
let stats_lines = &lines[start + 1..end]; | ||
|
||
stats_lines | ||
.iter() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to only allow the dir to exist. I think panicking for other things should be fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, seems fine. :)