config: avoid rebuilding when git index changes

Focus instead on the head and check whether a commit is made.
This commit is contained in:
Wez Furlong committed 2022-05-23 08:16:52 -07:00
1 parent 06e54f9e5a
commit efb8d14064
3 files changed
+48 -6

No files matched your search

Generated
+26
View File
@@ -659,6 +659,7 @@ dependencies = [
"dirs-next",
"enum-display-derive",
"env_logger",
"git2",
"hostname",
"lazy_static",
"libc",
@@ -1520,6 +1521,19 @@ version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "git2"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0155506aab710a86160ddb504a480d2964d7ab5b9e62419be69e0032bc5931c"
dependencies = [
"bitflags",
"libc",
"libgit2-sys",
"log",
"url",
]
[[package]]
name = "gl_generator"
version = "0.14.0"
@@ -1905,6 +1919,18 @@ version = "0.2.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
[[package]]
name = "libgit2-sys"
version = "0.13.4+1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0fa6563431ede25f5cc7f6d803c6afbc1c5d3ad3d4925d12c882bf2b526f5d1"
dependencies = [
"cc",
"libc",
"libz-sys",
"pkg-config",
]
[[package]]
name = "libloading"
version = "0.6.7"
+3
View File
@@ -10,6 +10,9 @@ build = "build.rs"
[dev-dependencies]
env_logger = "0.9"
[build-dependencies]
git2 = { version = "0.14", default-features = false }
[dependencies]
anyhow = "1.0"
bitflags = "1.3"
+19 -6
View File
@@ -56,6 +56,25 @@ fn main() {
}
} else {
// Otherwise we'll derive it from the git information
if let Ok(repo) = git2::Repository::discover(".") {
if let Ok(ref_head) = repo.find_reference("HEAD") {
let repo_path = repo.path().to_path_buf();
if let Ok(resolved) = ref_head.resolve() {
if let Some(name) = resolved.name() {
let path = repo_path.join(name);
if path.exists() {
println!(
"cargo:rerun-if-changed={}",
path.canonicalize().unwrap().display()
);
}
}
}
}
}
let head = Path::new("../.git/HEAD");
if head.exists() {
let head = head.canonicalize().unwrap();
@@ -75,12 +94,6 @@ fn main() {
ci_tag = info.trim().to_string();
}
}
let index = Path::new("../.git/index");
if index.exists() {
let index = index.canonicalize().unwrap();
println!("cargo:rerun-if-changed={}", index.display());
}
}
let target = std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_string());