2024-05-16 18:17:58 +03:00
|
|
|
use chrono::TimeZone;
|
|
|
|
|
2024-03-27 16:07:05 +03:00
|
|
|
fn get_git_hash() -> String {
|
|
|
|
use std::process::Command;
|
|
|
|
|
2024-05-30 16:59:46 +03:00
|
|
|
// Allow builds from `git archive` generated tarballs if output of `git get-tar-commit-id` is
|
|
|
|
// set in an env var.
|
2024-05-30 17:03:16 +03:00
|
|
|
if let Ok(commit) = std::env::var("BUILD_GIT_COMMIT_ID") {
|
2024-05-30 16:59:46 +03:00
|
|
|
return commit[..7].to_string();
|
|
|
|
};
|
2024-03-27 16:07:05 +03:00
|
|
|
let commit = Command::new("git")
|
|
|
|
.arg("rev-parse")
|
2024-05-30 16:59:46 +03:00
|
|
|
.arg("--short=7")
|
2024-03-27 16:07:05 +03:00
|
|
|
.arg("--verify")
|
|
|
|
.arg("HEAD")
|
|
|
|
.output();
|
|
|
|
if let Ok(commit_output) = commit {
|
|
|
|
let commit_string =
|
|
|
|
String::from_utf8_lossy(&commit_output.stdout);
|
|
|
|
|
|
|
|
return commit_string.lines().next().unwrap_or("").into();
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!("Can not get git commit: {}", commit.unwrap_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2024-05-16 18:17:58 +03:00
|
|
|
let now = match std::env::var("SOURCE_DATE_EPOCH") {
|
|
|
|
Ok(val) => chrono::Local
|
|
|
|
.timestamp_opt(val.parse::<i64>().unwrap(), 0)
|
|
|
|
.unwrap(),
|
|
|
|
Err(_) => chrono::Local::now(),
|
|
|
|
};
|
|
|
|
let build_date = now.date_naive();
|
2024-03-27 16:07:05 +03:00
|
|
|
|
|
|
|
let build_name = if std::env::var("GITUI_RELEASE").is_ok() {
|
|
|
|
format!(
|
|
|
|
"{} {} ({})",
|
|
|
|
env!("CARGO_PKG_VERSION"),
|
|
|
|
build_date,
|
|
|
|
get_git_hash()
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
format!("nightly {} ({})", build_date, get_git_hash())
|
|
|
|
};
|
|
|
|
|
|
|
|
println!("cargo:warning=buildname '{}'", build_name);
|
|
|
|
println!("cargo:rustc-env=GITUI_BUILD_NAME={}", build_name);
|
|
|
|
}
|