forked from everx-labs/ever-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
50 lines (43 loc) · 1.89 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
/*
* Copyright 2018-2021 TON DEV SOLUTIONS LTD.
*
* Licensed under the SOFTWARE EVALUATION License (the "License"); you may not use
* this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* limitations under the License.
*/
use std::process::Command;
fn main() {
let mut git_branch = String::from("Unknown");
let mut git_commit = String::from("Unknown");
let mut commit_date = String::from("Unknown");
let mut build_time = String::from("Unknown");
let branch = Command::new("git")
.args(&["rev-parse", "--abbrev-ref", "HEAD"])
.output();
if let Ok(branch) = branch {
git_branch = String::from_utf8(branch.stdout).unwrap_or_else(|_| "Unknown".to_string());
}
let last = Command::new("git").args(&["rev-parse", "HEAD"]).output();
if let Ok(last) = last {
git_commit = String::from_utf8(last.stdout).unwrap_or_else(|_| "Unknown".to_string());
}
let time = Command::new("git")
.args(&["log", "-1", "--date=iso", "--pretty=format:%cd"])
.output();
if let Ok(time) = time {
commit_date = String::from_utf8(time.stdout).unwrap_or_else(|_| "Unknown".to_string());
}
let b_time = Command::new("date").args(&["+%Y-%m-%d %T %z"]).output();
if let Ok(b_time) = b_time {
build_time = String::from_utf8(b_time.stdout).unwrap_or_else(|_| "Unknown".to_string());
}
println!("cargo:rustc-env=BUILD_GIT_BRANCH={}", git_branch);
println!("cargo:rustc-env=BUILD_GIT_COMMIT={}", git_commit);
println!("cargo:rustc-env=BUILD_GIT_DATE={}", commit_date);
println!("cargo:rustc-env=BUILD_TIME={}", build_time);
}