-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
36 lines (32 loc) · 891 Bytes
/
build.rs
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
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::process::Command;
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("build-info.txt");
let hash = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.map(|out| out.stdout)
.map(|mut hash| {
hash.truncate(9);
hash
});
let date = Command::new("date")
.arg("+%Y-%m-%d")
.output()
.map(|out| out.stdout)
.map(|mut date| {
date.truncate(10);
date
});
let mut file = File::create(path).unwrap();
if let (Ok(h), Ok(d)) = (hash, date) {
file.write_all(b" (").unwrap();
file.write_all(&h).unwrap();
file.write_all(b" ").unwrap();
file.write_all(&d).unwrap();
file.write_all(b")").unwrap();
}
}