1 //! Construct version in the `commit-hash date channel` format
3 use std::{env, path::PathBuf, process::Command};
8 if option_env!("CFG_RELEASE").is_none() {
9 println!("cargo:rustc-env=POKE_RA_DEVS=1");
14 println!("cargo:rerun-if-env-changed=CFG_RELEASE");
16 let mut manifest_dir = PathBuf::from(
17 env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."),
20 while manifest_dir.parent().is_some() {
21 let head_ref = manifest_dir.join(".git/HEAD");
22 if head_ref.exists() {
23 println!("cargo:rerun-if-changed={}", head_ref.display());
30 println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!");
33 fn set_commit_info() {
34 let output = match Command::new("git")
38 .arg("--format=%H %h %cd")
41 Ok(output) if output.status.success() => output,
44 let stdout = String::from_utf8(output.stdout).unwrap();
45 let mut parts = stdout.split_whitespace();
46 let mut next = || parts.next().unwrap();
47 println!("cargo:rustc-env=RA_COMMIT_HASH={}", next());
48 println!("cargo:rustc-env=RA_COMMIT_SHORT_HASH={}", next());
49 println!("cargo:rustc-env=RA_COMMIT_DATE={}", next())