Skip to content

Commit 6d50cff

Browse files
committed
Auto merge of #7256 - xFrednet:7172-trick-cargos-caching-for-collection, r=flip1995
Adding the ability to invalidate caches to force metadata collection This adds the discussed hack to touch `clippy_lints/src/lib.rs` to invalidate cargos cache and force metadata collection. I've decided to use the [`filetime`](https://github.com/alexcrichton/filetime) crate instead of the touch command to make is cross-platform and just cleaner in general. Looking at the maintainers I would say that it's a save crate to use xD. --- cc: #7172 I know this ID without looking it up now... This is not good changelog: none r? `@flip1995`
2 parents cd4abf9 + e3a1ae7 commit 6d50cff

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ derive-new = "0.5"
3939
regex = "1.4"
4040
quote = "1"
4141
syn = { version = "1", features = ["full"] }
42+
# This is used by the `collect-metadata` alias.
43+
filetime = "0.2"
4244

4345
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
4446
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

tests/dogfood.rs

+31
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,39 @@ fn dogfood_subprojects() {
179179
#[ignore]
180180
#[cfg(feature = "metadata-collector-lint")]
181181
fn run_metadata_collection_lint() {
182+
use std::fs::File;
183+
use std::time::SystemTime;
184+
185+
// Setup for validation
186+
let metadata_output_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("util/gh-pages/metadata_collection.json");
187+
let start_time = SystemTime::now();
188+
189+
// Run collection as is
182190
std::env::set_var("ENABLE_METADATA_COLLECTION", "1");
183191
run_clippy_for_project("clippy_lints");
192+
193+
// Check if cargo caching got in the way
194+
if let Ok(file) = File::open(metadata_output_path) {
195+
if let Ok(metadata) = file.metadata() {
196+
if let Ok(last_modification) = metadata.modified() {
197+
if last_modification > start_time {
198+
// The output file has been modified. Most likely by a hungry
199+
// metadata collection monster. So We'll return.
200+
return;
201+
}
202+
}
203+
}
204+
}
205+
206+
// Force cargo to invalidate the caches
207+
filetime::set_file_mtime(
208+
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("clippy_lints/src/lib.rs"),
209+
filetime::FileTime::now(),
210+
)
211+
.unwrap();
212+
213+
// Running the collection again
214+
run_clippy_for_project("clippy_lints");
184215
}
185216

186217
fn run_clippy_for_project(project: &str) {

0 commit comments

Comments
 (0)