- let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
- let profile = env::var("PROFILE").unwrap();
- let mut out_file = PathBuf::new();
- out_file.push(manifest_dir);
- out_file.push("target");
- out_file.push(profile);
- out_file.push("default.toml");
+// Try to get hash and date of the last commit on a best effort basis. If anything goes wrong
+// (git not installed or if this is not a git repository) just return an empty string.
+fn commit_info() -> String {
+ match (channel(), commit_hash(), commit_date()) {
+ (channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_end(), date),
+ _ => String::new(),
+ }
+}
+
+fn channel() -> String {
+ if let Ok(channel) = env::var("CFG_RELEASE_CHANNEL") {
+ channel
+ } else {
+ "nightly".to_owned()
+ }
+}
+
+fn commit_hash() -> Option<String> {
+ Command::new("git")
+ .args(&["rev-parse", "--short", "HEAD"])
+ .output()
+ .ok()
+ .and_then(|r| String::from_utf8(r.stdout).ok())
+}