Skip to content

Commit

Permalink
only skip mtime check on $CARGO_HOME/{git,registry}
Browse files Browse the repository at this point in the history
Closes rust-lang#12090

Commit

Fix formatting
  • Loading branch information
jo1gi committed Jul 18, 2023
1 parent e1e2f2d commit ccccfda
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
56 changes: 56 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5972,6 +5972,62 @@ fn build_with_relative_cargo_home_path() {
p.cargo("build").env("CARGO_HOME", "./cargo_home/").run();
}

#[cargo_test]
fn skip_mtime_check_in_selected_cargo_home_subdirs() {
// Run once without cache
let p = project()
.at("cargo_home/registry/foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", r#"fn main() { println!("1"); }"#)
.build();
let project_root = p.root();
let cargo_home = project_root
.parent()
.unwrap()
.parent()
.unwrap()
.to_str()
.unwrap();
p.cargo("run")
.env("CARGO_HOME", &cargo_home)
.with_stdout("1")
.run();
// Run with cache
p.change_file("src/main.rs", r#"fn main() { println!("2"); }"#);
p.cargo("run")
.env("CARGO_HOME", &cargo_home)
.with_stdout("1")
.run();
}

#[cargo_test]
fn use_mtime_cache_in_cargo_home() {
println!("Without cache");
let p = project()
.at("cargo_home/foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", r#"fn main() { println!("1"); }"#)
.build();
let project_root = p.root();
let cargo_home = project_root
.parent()
.unwrap()
.parent()
.unwrap()
.to_str()
.unwrap();
p.cargo("run")
.env("CARGO_HOME", &cargo_home)
.with_stdout("1")
.run();
println!("With cache");
p.change_file("src/main.rs", r#"fn main() { println!("2"); }"#);
p.cargo("run")
.env("CARGO_HOME", &cargo_home)
.with_stdout("2")
.run();
}

#[cargo_test]
fn user_specific_cfgs_are_filtered_out() {
let p = project()
Expand Down

0 comments on commit ccccfda

Please sign in to comment.