about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-05-25 14:08:02 +0000
committerbors <bors@rust-lang.org>2021-05-25 14:08:02 +0000
commit6d50cff45afeeca85a14f1284badf9fc4b5b7668 (patch)
tree64d60cb7ea22ebb58172360ded26accbfff73703
parentcd4abf93e08fc68f3bf287ab556935da457dc391 (diff)
parente3a1ae7bfea265d0c452ce4511349c00ca0ee1b8 (diff)
downloadrust-6d50cff45afeeca85a14f1284badf9fc4b5b7668.tar.gz
rust-6d50cff45afeeca85a14f1284badf9fc4b5b7668.zip
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`
-rw-r--r--Cargo.toml2
-rw-r--r--tests/dogfood.rs31
2 files changed, 33 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 848476a9d05..458c28c2748 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -39,6 +39,8 @@ derive-new = "0.5"
 regex = "1.4"
 quote = "1"
 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.
 # See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
diff --git a/tests/dogfood.rs b/tests/dogfood.rs
index 5d9f128753f..7de130c7dbe 100644
--- a/tests/dogfood.rs
+++ b/tests/dogfood.rs
@@ -179,8 +179,39 @@ fn dogfood_subprojects() {
 #[ignore]
 #[cfg(feature = "metadata-collector-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");
     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) {