-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
55 lines (50 loc) · 1.55 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
45
46
47
48
49
50
51
52
53
54
55
use chrono::offset::Utc;
use std::process;
fn print_vcs_hash() {
static DEFAULT: &str = "dev";
match process::Command::new("fossil")
.args(&["timeline", "-t", "ci", "-n", "1"])
.output()
{
Ok(output) => {
// Output will look something like this (snipped)
// === 2020-08-11 ===
// 19:07:33 [1bbca2a2bf] *CURRENT* Add bash comp.. [296f73511c] (user: jason tags: trunk)
// --- entry limit (1) reached ---
let info = std::str::from_utf8(&output.stdout).unwrap();
let mut hash = String::new();
let mut collecting_hash = false;
for c in info.chars() {
if collecting_hash && c == ']' {
break;
}
if collecting_hash {
hash.push(c)
}
if c == '[' {
collecting_hash = true;
}
}
if hash.len() != 10 {
// Fossil prints a 10 char hash
println!("cargo:rustc-env=BUILD_VCS_HASH={}", DEFAULT);
} else {
println!("cargo:rustc-env=BUILD_VCS_HASH={}", hash);
}
}
Err(_e) => {
println!("cargo:rustc-env=BUILD_VCS_HASH={}", DEFAULT);
}
};
}
fn print_build_time() {
println!(
"cargo:rustc-env=BUILD_TIMESTAMP={}",
Utc::now().format("%Y-%m-%d %H:%M:%S %Z")
);
}
fn main() {
print_vcs_hash();
print_build_time();
if cfg!(debug_assertions) {};
}