forked from seppo0010/rsedis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
executable file
·41 lines (37 loc) · 1.21 KB
/
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
37
38
39
40
41
use std::fs::File;
use std::io::Write;
use std::process::Command;
use std::str::from_utf8;
fn main() {
let mut f = File::create("src/release.rs").unwrap();
{
let hash = match Command::new("git")
.arg("show-ref")
.arg("--head")
.arg("--hash=8")
.output() {
Ok(o) => String::from(from_utf8(&o.stdout[0..8]).unwrap()),
Err(_) => String::from("00000000"),
};
write!(f, "pub const GIT_SHA1: &'static str = \"{}\";\n", &hash[0..8]).unwrap();
}
{
let dirty = match Command::new("git")
.arg("diff")
.arg("--no-ext-diff")
.output() {
Ok(o) => o.stdout.len() > 0,
Err(_) => true,
};
write!(f, "pub const GIT_DIRTY: bool = {};\n", if dirty { "true" } else { "false "}).unwrap();
}
{
let version = match Command::new("rustc")
.arg("--version")
.output() {
Ok(o) => String::from(from_utf8(&o.stdout).unwrap().trim()),
Err(_) => String::new(),
};
write!(f, "pub const RUSTC_VERSION: &'static str = {:?};\n", version).unwrap();
}
}