-
Notifications
You must be signed in to change notification settings - Fork 27
/
build.rs
40 lines (33 loc) · 1.2 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
use regex::Regex;
use std::process::Command;
fn main() {
let mut wlx_build = get_version().unwrap_or(format!("{}-unknown", env!("CARGO_PKG_VERSION")));
match std::env::var("GITHUB_JOB").as_deref() {
Ok("make_release") => {
wlx_build = format!("{} (Release)", &wlx_build);
}
Ok("build_appimage") => {
wlx_build = format!("{} (AppImage)", &wlx_build);
}
_ => {}
}
println!("cargo:rustc-env=WLX_BUILD={}", &wlx_build);
}
fn get_version() -> Result<String, Box<dyn std::error::Error>> {
let re = Regex::new(r"v([0-9.]+)-([0-9]+)-g([a-f0-9]+)").unwrap(); // safe
let output = Command::new("git")
.args(["describe", "--tags", "--abbrev=7", "--dirty"])
.output()?;
let mut output_str = String::from_utf8(output.stdout)?;
if output_str.is_empty() {
let output = Command::new("git")
.args(["describe", "--tags", "--abbrev=7", "--dirty", "--always"])
.output()?;
output_str = format!(
"{}-{}",
env!("CARGO_PKG_VERSION"),
String::from_utf8(output.stdout)?
);
}
Ok(re.replace_all(&output_str, "${1}.r${2}.${3}").into_owned())
}