Skip to content

Commit ccccfda

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

File tree

2 files changed

+74
-5
lines changed

2 files changed

+74
-5
lines changed

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -1857,14 +1857,27 @@ 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 {
1867+
None
1868+
};
1869+
18601870
for path in paths {
18611871
let path = path.as_ref();
18621872

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;
1873+
// Assuming anything in cargo_home/{git, registry} is immutable
1874+
// (see also #9455 about marking the src directory readonly) which avoids rebuilds when CI
1875+
// caches $CARGO_HOME/registry/{index, cache} and $CARGO_HOME/git/db across runs, keeping
1876+
// the content the same but changing the mtime.
1877+
if let Some(ref skipable_dirs) = skipable_dirs {
1878+
if skipable_dirs.iter().any(|dir| path.starts_with(dir)) {
1879+
continue;
1880+
}
18681881
}
18691882
let path_mtime = match mtime_cache.entry(path.to_path_buf()) {
18701883
Entry::Occupied(o) => *o.get(),

tests/testsuite/build.rs

+56
Original file line numberDiff line numberDiff line change
@@ -5972,6 +5972,62 @@ 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()
5986+
.unwrap()
5987+
.parent()
5988+
.unwrap()
5989+
.to_str()
5990+
.unwrap();
5991+
p.cargo("run")
5992+
.env("CARGO_HOME", &cargo_home)
5993+
.with_stdout("1")
5994+
.run();
5995+
// Run with cache
5996+
p.change_file("src/main.rs", r#"fn main() { println!("2"); }"#);
5997+
p.cargo("run")
5998+
.env("CARGO_HOME", &cargo_home)
5999+
.with_stdout("1")
6000+
.run();
6001+
}
6002+
6003+
#[cargo_test]
6004+
fn use_mtime_cache_in_cargo_home() {
6005+
println!("Without cache");
6006+
let p = project()
6007+
.at("cargo_home/foo")
6008+
.file("Cargo.toml", &basic_bin_manifest("foo"))
6009+
.file("src/main.rs", r#"fn main() { println!("1"); }"#)
6010+
.build();
6011+
let project_root = p.root();
6012+
let cargo_home = project_root
6013+
.parent()
6014+
.unwrap()
6015+
.parent()
6016+
.unwrap()
6017+
.to_str()
6018+
.unwrap();
6019+
p.cargo("run")
6020+
.env("CARGO_HOME", &cargo_home)
6021+
.with_stdout("1")
6022+
.run();
6023+
println!("With cache");
6024+
p.change_file("src/main.rs", r#"fn main() { println!("2"); }"#);
6025+
p.cargo("run")
6026+
.env("CARGO_HOME", &cargo_home)
6027+
.with_stdout("2")
6028+
.run();
6029+
}
6030+
59756031
#[cargo_test]
59766032
fn user_specific_cfgs_are_filtered_out() {
59776033
let p = project()

0 commit comments

Comments
 (0)