forked from pi-pi3/julia-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
44 lines (37 loc) · 1.15 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
42
43
44
use std::env;
use std::io::prelude::*;
use std::process::Command;
use std::path::PathBuf;
use std::fs::File;
fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("git_version.rs");
let mut branch = Command::new("git")
.args(&["rev-parse", "--abbrev-ref", "HEAD"])
.output()
.ok()
.map(|out| out.stdout)
.and_then(|out| String::from_utf8(out).ok());
let mut commit = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
.ok()
.map(|out| out.stdout)
.and_then(|out| String::from_utf8(out).ok());
if let Some(br) = branch {
branch = Some(br.replace('\n', ""))
} else {
eprintln!("obtaining git branch failed");
}
if let Some(cm) = commit {
commit = Some(cm.replace('\n', ""))
} else {
eprintln!("obtaining git commit failed");
}
let mut file = File::create(out_path).expect("couldn't open git_version.rs");
write!(
file,
"const BRANCH: Option<&str> = {:?};\nconst COMMIT: Option<&str> = {:?};",
branch,
commit
).expect("couldn't write git version");
}