Skip to content

Commit a4ecceb

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

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
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/freshness.rs

+60-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::death;
1414
use cargo_test_support::paths::{self, CargoPathExt};
1515
use cargo_test_support::registry::Package;
1616
use cargo_test_support::{
17-
basic_manifest, is_coarse_mtime, project, rustc_host, rustc_host_env, sleep_ms,
17+
basic_manifest, basic_lib_manifest, is_coarse_mtime, project, rustc_host, rustc_host_env, sleep_ms,
1818
};
1919

2020
#[cargo_test]
@@ -2814,3 +2814,62 @@ directory sources are not [..]
28142814
)
28152815
.run();
28162816
}
2817+
2818+
#[cargo_test]
2819+
fn skip_mtime_check_in_selected_cargo_home_subdirs() {
2820+
let p = project()
2821+
.at("cargo_home/registry/foo")
2822+
.file("Cargo.toml", &basic_lib_manifest("foo"))
2823+
.file("src/lib.rs", "")
2824+
.build();
2825+
let project_root = p.root();
2826+
let cargo_home = project_root.parent().unwrap().parent().unwrap();
2827+
p.cargo("check -v")
2828+
.env("CARGO_HOME", &cargo_home)
2829+
.with_stderr(
2830+
"\
2831+
[CHECKING] foo v0.5.0 ([CWD])
2832+
[RUNNING] `rustc --crate-name foo src/lib.rs [..]
2833+
[FINISHED] dev [..]",
2834+
)
2835+
.run();
2836+
p.change_file("src/lib.rs", "illegal syntax");
2837+
p.cargo("check -v")
2838+
.env("CARGO_HOME", &cargo_home)
2839+
.with_stderr(
2840+
"\
2841+
[FRESH] foo v0.5.0 ([CWD])
2842+
[FINISHED] dev [..]",
2843+
)
2844+
.run();
2845+
}
2846+
2847+
#[cargo_test]
2848+
fn use_mtime_cache_in_cargo_home() {
2849+
let p = project()
2850+
.at("cargo_home/foo")
2851+
.file("Cargo.toml", &basic_lib_manifest("foo"))
2852+
.file("src/lib.rs", "")
2853+
.build();
2854+
let project_root = p.root();
2855+
let cargo_home = project_root.parent().unwrap();
2856+
p.cargo("check -v")
2857+
.env("CARGO_HOME", &cargo_home)
2858+
.with_stderr(
2859+
"\
2860+
[CHECKING] foo v0.5.0 ([CWD])
2861+
[RUNNING] `rustc --crate-name foo src/lib.rs [..]
2862+
[FINISHED] dev [..]",
2863+
)
2864+
.run();
2865+
p.change_file("src/lib.rs", "illegal syntax");
2866+
p.cargo("check -v")
2867+
.env("CARGO_HOME", &cargo_home)
2868+
.with_stderr(
2869+
"\
2870+
[DIRTY] foo v0.5.0 ([CWD]): [..]
2871+
[CHECKING] foo v0.5.0 ([CWD])
2872+
[RUNNING] `rustc --crate-name foo src/lib.rs [..]",
2873+
)
2874+
.run_expect_error();
2875+
}

0 commit comments

Comments
 (0)