mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
only skip mtime check on $CARGO_HOME/{git,registry}
Closes #12090 Commit Fix formatting Fix tests Fix formatting Fix formatting Fix formatting
This commit is contained in:
parent
e1e2f2d4be
commit
839069f03f
@ -1857,14 +1857,27 @@ where
|
||||
Err(..) => return Some(StaleItem::MissingFile(reference.to_path_buf())),
|
||||
};
|
||||
|
||||
let skipable_dirs = if let Ok(cargo_home) = home::cargo_home() {
|
||||
let skipable_dirs: Vec<_> = ["git", "registry"]
|
||||
.into_iter()
|
||||
.map(|subfolder| cargo_home.join(subfolder))
|
||||
.collect();
|
||||
Some(skipable_dirs)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
for path in paths {
|
||||
let path = path.as_ref();
|
||||
|
||||
// Assuming anything in cargo_home is immutable (see also #9455 about marking it readonly)
|
||||
// which avoids rebuilds when CI caches $CARGO_HOME/registry/{index, cache} and
|
||||
// $CARGO_HOME/git/db across runs, keeping the content the same but changing the mtime.
|
||||
if let Ok(true) = home::cargo_home().map(|home| path.starts_with(home)) {
|
||||
continue;
|
||||
// Assuming anything in cargo_home/{git, registry} is immutable
|
||||
// (see also #9455 about marking the src directory readonly) which avoids rebuilds when CI
|
||||
// caches $CARGO_HOME/registry/{index, cache} and $CARGO_HOME/git/db across runs, keeping
|
||||
// the content the same but changing the mtime.
|
||||
if let Some(ref skipable_dirs) = skipable_dirs {
|
||||
if skipable_dirs.iter().any(|dir| path.starts_with(dir)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let path_mtime = match mtime_cache.entry(path.to_path_buf()) {
|
||||
Entry::Occupied(o) => *o.get(),
|
||||
|
@ -14,7 +14,8 @@ use super::death;
|
||||
use cargo_test_support::paths::{self, CargoPathExt};
|
||||
use cargo_test_support::registry::Package;
|
||||
use cargo_test_support::{
|
||||
basic_manifest, is_coarse_mtime, project, rustc_host, rustc_host_env, sleep_ms,
|
||||
basic_lib_manifest, basic_manifest, is_coarse_mtime, project, rustc_host, rustc_host_env,
|
||||
sleep_ms,
|
||||
};
|
||||
|
||||
#[cargo_test]
|
||||
@ -2814,3 +2815,62 @@ directory sources are not [..]
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn skip_mtime_check_in_selected_cargo_home_subdirs() {
|
||||
let p = project()
|
||||
.at("cargo_home/registry/foo")
|
||||
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
let project_root = p.root();
|
||||
let cargo_home = project_root.parent().unwrap().parent().unwrap();
|
||||
p.cargo("check -v")
|
||||
.env("CARGO_HOME", &cargo_home)
|
||||
.with_stderr(
|
||||
"\
|
||||
[CHECKING] foo v0.5.0 ([CWD])
|
||||
[RUNNING] `rustc --crate-name foo src/lib.rs [..]
|
||||
[FINISHED] dev [..]",
|
||||
)
|
||||
.run();
|
||||
p.change_file("src/lib.rs", "illegal syntax");
|
||||
p.cargo("check -v")
|
||||
.env("CARGO_HOME", &cargo_home)
|
||||
.with_stderr(
|
||||
"\
|
||||
[FRESH] foo v0.5.0 ([CWD])
|
||||
[FINISHED] dev [..]",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn use_mtime_cache_in_cargo_home() {
|
||||
let p = project()
|
||||
.at("cargo_home/foo")
|
||||
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
let project_root = p.root();
|
||||
let cargo_home = project_root.parent().unwrap();
|
||||
p.cargo("check -v")
|
||||
.env("CARGO_HOME", &cargo_home)
|
||||
.with_stderr(
|
||||
"\
|
||||
[CHECKING] foo v0.5.0 ([CWD])
|
||||
[RUNNING] `rustc --crate-name foo src/lib.rs [..]
|
||||
[FINISHED] dev [..]",
|
||||
)
|
||||
.run();
|
||||
p.change_file("src/lib.rs", "illegal syntax");
|
||||
p.cargo("check -v")
|
||||
.env("CARGO_HOME", &cargo_home)
|
||||
.with_stderr(
|
||||
"\
|
||||
[DIRTY] foo v0.5.0 ([CWD]): [..]
|
||||
[CHECKING] foo v0.5.0 ([CWD])
|
||||
[RUNNING] `rustc --crate-name foo src/lib.rs [..]",
|
||||
)
|
||||
.run_expect_error();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user