-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild.rs
More file actions
49 lines (42 loc) · 1.28 KB
/
Copy pathbuild.rs
File metadata and controls
49 lines (42 loc) · 1.28 KB
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
use std::env;
use std::process::Command;
fn get_version() -> String {
let cargo_pkg_version = env::var("CARGO_PKG_VERSION").unwrap();
let git_short_hash = match Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
{
Ok(v) => String::from_utf8(v.stdout)
.expect("failed to read stdout")
.trim_end()
.to_string(),
Err(err) => {
eprintln!("`git rev-parse` err: {}", err);
"unknown".to_string()
}
};
let dirty = match Command::new("git").args(["status", "--short"]).output() {
Ok(v) => {
if v.stdout.is_empty() {
String::new()
} else {
"-dirty".to_string()
}
}
Err(e) => {
eprintln!("`git status --short` err: {e}");
String::new()
}
};
format!("{cargo_pkg_version}-{git_short_hash}{dirty}")
}
fn main() {
println!("cargo:rerun-if-changed=../.git/HEAD");
println!("cargo:rerun-if-changed=build.rs");
let _ = Command::new("git")
.args(["config", "core.hooksPath", ".githooks"])
.output();
if env::var("CLASHTUI_VERSION").is_err() {
println!("cargo:rustc-env=CLASHTUI_VERSION={}", get_version());
}
}