Add build metadata to engine in VERSION file + debug view
parent
866155a230
commit
d4eedab39c
@ -0,0 +1,38 @@
|
||||
fn main() {
|
||||
{
|
||||
use std::process::Command;
|
||||
use chrono::prelude::*;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
// Date of build
|
||||
let now = Utc::now().format("%Y%m%d%H%M%S");
|
||||
|
||||
// Latest commit ID
|
||||
let git_sha = String::from_utf8(
|
||||
Command::new("git")
|
||||
.arg("rev-parse")
|
||||
.arg("--short")
|
||||
.arg("HEAD")
|
||||
.output()
|
||||
.expect("Failed to get git sha")
|
||||
.stdout
|
||||
).expect("Read stdout from git sha command");
|
||||
|
||||
// If the workspace is dirty or clean
|
||||
let clean = Command::new("git")
|
||||
.arg("diff")
|
||||
.arg("--quiet")
|
||||
.status()
|
||||
.expect("Failed to run git diff")
|
||||
.success();
|
||||
|
||||
let mut file = File::create("VERSION").expect("Create VERSION file");
|
||||
|
||||
if clean {
|
||||
write!(file, "0.0.0-{now}+{}", git_sha.trim()).expect("Write version to VERSION file");
|
||||
} else {
|
||||
write!(file, "0.0.0-{now}+{}-dirty", git_sha.trim()).expect("Write version to VERSION file");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
/// Include the version of this build from an auto-generated version file
|
||||
pub const VERSION: &str = include_str!("../VERSION");
|
||||
Loading…
Reference in New Issue