Skip to content

Commit 839069f

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

File tree

2 files changed

+79
-6
lines changed

2 files changed

+79
-6
lines changed

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

Lines changed: 18 additions & 5 deletions
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

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ 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_lib_manifest, basic_manifest, is_coarse_mtime, project, rustc_host, rustc_host_env,
18+
sleep_ms,
1819
};
1920

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

0 commit comments

Comments
 (0)