Adding the ability to invalidate caches to force metadata collection

This commit is contained in:
xFrednet 2021-05-20 22:29:09 +02:00
parent 60826e77c3
commit e3a1ae7bfe
2 changed files with 33 additions and 0 deletions

View File

@ -39,6 +39,8 @@ derive-new = "0.5"
regex = "1.4" regex = "1.4"
quote = "1" quote = "1"
syn = { version = "1", features = ["full"] } syn = { version = "1", features = ["full"] }
# This is used by the `collect-metadata` alias.
filetime = "0.2"
# A noop dependency that changes in the Rust repository, it's a bit of a hack. # A noop dependency that changes in the Rust repository, it's a bit of a hack.
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` # See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

View File

@ -179,8 +179,39 @@ fn dogfood_subprojects() {
#[ignore] #[ignore]
#[cfg(feature = "metadata-collector-lint")] #[cfg(feature = "metadata-collector-lint")]
fn run_metadata_collection_lint() { fn run_metadata_collection_lint() {
use std::fs::File;
use std::time::SystemTime;
// Setup for validation
let metadata_output_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("util/gh-pages/metadata_collection.json");
let start_time = SystemTime::now();
// Run collection as is
std::env::set_var("ENABLE_METADATA_COLLECTION", "1"); std::env::set_var("ENABLE_METADATA_COLLECTION", "1");
run_clippy_for_project("clippy_lints"); run_clippy_for_project("clippy_lints");
// Check if cargo caching got in the way
if let Ok(file) = File::open(metadata_output_path) {
if let Ok(metadata) = file.metadata() {
if let Ok(last_modification) = metadata.modified() {
if last_modification > start_time {
// The output file has been modified. Most likely by a hungry
// metadata collection monster. So We'll return.
return;
}
}
}
}
// Force cargo to invalidate the caches
filetime::set_file_mtime(
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("clippy_lints/src/lib.rs"),
filetime::FileTime::now(),
)
.unwrap();
// Running the collection again
run_clippy_for_project("clippy_lints");
} }
fn run_clippy_for_project(project: &str) { fn run_clippy_for_project(project: &str) {