23 lines
614 B
Rust
23 lines
614 B
Rust
|
use git2::Repository;
|
||
|
use std::{env, fs, io::Write};
|
||
|
|
||
|
fn main() {
|
||
|
let outdir = env::var("OUT_DIR").unwrap();
|
||
|
let outfile = format!("{}/buildinfo.txt", outdir);
|
||
|
|
||
|
let repo = Repository::open(env::current_dir().unwrap()).unwrap();
|
||
|
let head = repo.head().unwrap();
|
||
|
let head_name = head.shorthand().unwrap();
|
||
|
let commit = head.peel_to_commit().unwrap();
|
||
|
let commit_id = commit.id();
|
||
|
let now = chrono::Local::now();
|
||
|
|
||
|
let mut fh = fs::File::create(&outfile).unwrap();
|
||
|
write!(
|
||
|
fh,
|
||
|
r#""wgvirtipd {} ({}) on {}""#,
|
||
|
commit_id, head_name, now
|
||
|
)
|
||
|
.ok();
|
||
|
}
|