summaryrefslogtreecommitdiffstats
path: root/build.rs
blob: 64470c19f4514b83e25d39011be9c6ba19a0545a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn get_git_hash() -> String {
	use std::process::Command;

	let commit = Command::new("git")
		.arg("rev-parse")
		.arg("--short")
		.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() {
	let build_date = chrono::Local::now().date_naive();

	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);
}