From efb8d14064e67cf6a1b705402d52e8f330cf3f7e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 22 May 2022 09:01:09 -0700 Subject: [PATCH] config: avoid rebuilding when git index changes Focus instead on the head and check whether a commit is made. --- Cargo.lock | 26 ++++++++++++++++++++++++++ config/Cargo.toml | 3 +++ config/build.rs | 25 +++++++++++++++++++------ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c24e7a8a..075897c16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/config/Cargo.toml b/config/Cargo.toml index 52ea39263..508b03f8c 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -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" diff --git a/config/build.rs b/config/build.rs index 519aae21e..e451384b4 100644 --- a/config/build.rs +++ b/config/build.rs @@ -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());