change some version stuff
This commit is contained in:
29
build.rs
29
build.rs
@@ -2,22 +2,39 @@ use regex::Regex;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let mut wlx_build = get_version().unwrap_or(format!("{} (Cargo)", env!("CARGO_PKG_VERSION")));
|
||||
let mut wlx_build = get_version().unwrap_or(format!("{}-unknown", env!("CARGO_PKG_VERSION")));
|
||||
|
||||
if std::env::var("GITHUB_ACTIONS").is_ok() {
|
||||
wlx_build = format!("{} (AppImage)", &wlx_build)
|
||||
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", "--always"])
|
||||
.args(["describe", "--tags", "--abbrev=7", "--dirty"])
|
||||
.output()?;
|
||||
|
||||
let output_str = String::from_utf8(output.stdout)?;
|
||||
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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user