Skip to content

Commit 0670fef

Browse files
committed
Ensure rerun-if-changed files exist in build.rs
When using the "cargo:rerun-if-changed=<path>" directive in the build.rs script, the absense of the path triggers cargo to rebuild. The .git/packed-refs file does not always exist in a git repository; especially a fresh repository. This was causing CI builds to take a very long time due to cargo having to relink the stg executable many, many times for `make doc`. This problem is solved by having the build script test the existance of each "rerun-if-changed" file candidate.
1 parent c87f946 commit 0670fef

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

build.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ fn main() {
1111

1212
// Tell cargo to rebuild if the head or any relevant refs change.
1313
if let Some(git_dir) = git_dir {
14-
println!("cargo:rerun-if-changed={git_dir}/HEAD");
15-
println!("cargo:rerun-if-changed={git_dir}/refs/heads");
16-
println!("cargo:rerun-if-changed={git_dir}/refs/tags");
17-
println!("cargo:rerun-if-changed={git_dir}/packed-refs");
14+
let git_path = std::path::Path::new(git_dir);
15+
let refs_path = git_path.join("refs");
16+
if git_path.join("HEAD").exists() {
17+
println!("cargo:rerun-if-changed={git_dir}/HEAD");
18+
}
19+
if git_path.join("packed-refs").exists() {
20+
println!("cargo:rerun-if-changed={git_dir}/packed-refs");
21+
}
22+
if refs_path.join("heads").exists() {
23+
println!("cargo:rerun-if-changed={git_dir}/refs/heads");
24+
}
25+
if refs_path.join("tags").exists() {
26+
println!("cargo:rerun-if-changed={git_dir}/refs/tags");
27+
}
1828
}
1929

2030
let git_output = std::process::Command::new("git")

0 commit comments

Comments
 (0)