Skip to content

Commit 97181c8

Browse files
committed
only skip mtime check on $CARGO_HOME/{git,registry}
Closes #12090 Commit
1 parent e1e2f2d commit 97181c8

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

src/cargo/core/compiler/fingerprint/mod.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,14 +1857,25 @@ where
18571857
Err(..) => return Some(StaleItem::MissingFile(reference.to_path_buf())),
18581858
};
18591859

1860+
let skipable_dirs = if let Ok(cargo_home) = home::cargo_home() {
1861+
let skipable_dirs: Vec<_> = ["git", "registry"]
1862+
.into_iter()
1863+
.map(|subfolder| cargo_home.join(subfolder))
1864+
.collect();
1865+
Some(skipable_dirs)
1866+
} else { None };
1867+
18601868
for path in paths {
18611869
let path = path.as_ref();
18621870

1863-
// Assuming anything in cargo_home is immutable (see also #9455 about marking it readonly)
1864-
// which avoids rebuilds when CI caches $CARGO_HOME/registry/{index, cache} and
1865-
// $CARGO_HOME/git/db across runs, keeping the content the same but changing the mtime.
1866-
if let Ok(true) = home::cargo_home().map(|home| path.starts_with(home)) {
1867-
continue;
1871+
// Assuming anything in cargo_home/{git, registry} is immutable
1872+
// (see also #9455 about marking the src directory readonly) which avoids rebuilds when CI
1873+
// caches $CARGO_HOME/registry/{index, cache} and $CARGO_HOME/git/db across runs, keeping
1874+
// the content the same but changing the mtime.
1875+
if let Some(ref skipable_dirs) = skipable_dirs {
1876+
if skipable_dirs.iter().any(|dir| path.starts_with(dir)) {
1877+
continue;
1878+
}
18681879
}
18691880
let path_mtime = match mtime_cache.entry(path.to_path_buf()) {
18701881
Entry::Occupied(o) => *o.get(),

tests/testsuite/build.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5972,6 +5972,56 @@ fn build_with_relative_cargo_home_path() {
59725972
p.cargo("build").env("CARGO_HOME", "./cargo_home/").run();
59735973
}
59745974

5975+
#[cargo_test]
5976+
fn skip_mtime_check_in_selected_cargo_home_subdirs() {
5977+
// Run once without cache
5978+
let p = project()
5979+
.at("cargo_home/registry/foo")
5980+
.file("Cargo.toml", &basic_bin_manifest("foo"))
5981+
.file("src/main.rs", r#"fn main() { println!("1"); }"#)
5982+
.build();
5983+
let project_root = p.root();
5984+
let cargo_home = project_root
5985+
.parent().unwrap()
5986+
.parent().unwrap()
5987+
.to_str().unwrap();
5988+
p.cargo("run")
5989+
.env("CARGO_HOME", &cargo_home)
5990+
.with_stdout("1")
5991+
.run();
5992+
// Run with cache
5993+
p.change_file("src/main.rs", r#"fn main() { println!("2"); }"#);
5994+
p.cargo("run")
5995+
.env("CARGO_HOME", &cargo_home)
5996+
.with_stdout("1")
5997+
.run();
5998+
}
5999+
6000+
#[cargo_test]
6001+
fn use_mtime_cache_in_cargo_home() {
6002+
println!("Without cache");
6003+
let p = project()
6004+
.at("cargo_home/foo")
6005+
.file("Cargo.toml", &basic_bin_manifest("foo"))
6006+
.file("src/main.rs", r#"fn main() { println!("1"); }"#)
6007+
.build();
6008+
let project_root = p.root();
6009+
let cargo_home = project_root
6010+
.parent().unwrap()
6011+
.parent().unwrap()
6012+
.to_str().unwrap();
6013+
p.cargo("run")
6014+
.env("CARGO_HOME", &cargo_home)
6015+
.with_stdout("1")
6016+
.run();
6017+
println!("With cache");
6018+
p.change_file("src/main.rs", r#"fn main() { println!("2"); }"#);
6019+
p.cargo("run")
6020+
.env("CARGO_HOME", &cargo_home)
6021+
.with_stdout("2")
6022+
.run();
6023+
}
6024+
59756025
#[cargo_test]
59766026
fn user_specific_cfgs_are_filtered_out() {
59776027
let p = project()

0 commit comments

Comments
 (0)