|
1 |
| -use std::process::exit; |
2 |
| -fn main() -> () { |
3 |
| - exit(0) |
| 1 | +fn main() { |
| 2 | + let git_output = std::process::Command::new("git") |
| 3 | + .args(["rev-parse", "--git-dir"]) |
| 4 | + .output() |
| 5 | + .ok(); |
| 6 | + let git_dir = git_output.as_ref().and_then(|output| { |
| 7 | + std::str::from_utf8(&output.stdout) |
| 8 | + .ok() |
| 9 | + .and_then(|s| s.strip_suffix('\n').or_else(|| s.strip_suffix("\r\n"))) |
| 10 | + }); |
| 11 | + |
| 12 | + // Tell cargo to rebuild if the head or any relevant refs change. |
| 13 | + if let Some(git_dir) = git_dir { |
| 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={}/HEAD", git_dir); |
| 18 | + } |
| 19 | + if git_path.join("packed-refs").exists() { |
| 20 | + println!("cargo:rerun-if-changed={}/packed-refs", git_dir); |
| 21 | + } |
| 22 | + if refs_path.join("heads").exists() { |
| 23 | + println!("cargo:rerun-if-changed={}/refs/heads", git_dir); |
| 24 | + } |
| 25 | + if refs_path.join("tags").exists() { |
| 26 | + println!("cargo:rerun-if-changed={}/refs/tags", git_dir); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + let git_output = std::process::Command::new("git") |
| 31 | + .args(["describe", "--always", "--tags", "--long", "--dirty"]) |
| 32 | + .output() |
| 33 | + .ok(); |
| 34 | + let git_info = git_output |
| 35 | + .as_ref() |
| 36 | + .and_then(|output| std::str::from_utf8(&output.stdout).ok().map(str::trim)); |
| 37 | + |
| 38 | + if let Some(git_info) = git_info { |
| 39 | + println!("cargo:rustc-env=_GIT_INFO={}", git_info); |
| 40 | + } |
4 | 41 | }
|
0 commit comments