use build.rs to pass REPOID to rustc-env

This commit is contained in:
Dietmar Maurer 2021-05-06 13:00:03 +02:00
parent 572cd0381b
commit d8769d659e
3 changed files with 26 additions and 1 deletions

View File

@ -15,6 +15,7 @@ edition = "2018"
license = "AGPL-3" license = "AGPL-3"
description = "Proxmox Backup" description = "Proxmox Backup"
homepage = "https://www.proxmox.com" homepage = "https://www.proxmox.com"
build = "build.rs"
exclude = [ "build", "debian", "tests/catar_data/test_symlink/symlink1"] exclude = [ "build", "debian", "tests/catar_data/test_symlink/symlink1"]

24
build.rs Normal file
View File

@ -0,0 +1,24 @@
// build.rs
use std::env;
use std::process::Command;
fn main() {
let repoid = match env::var("REPOID") {
Ok(repoid) => repoid,
Err(_) => {
match Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
{
Ok(output) => {
String::from_utf8(output.stdout).unwrap()
}
Err(err) => {
panic!("git rev-parse failed: {}", err);
}
}
}
};
println!("cargo:rustc-env=REPOID={}", repoid);
}

View File

@ -13,7 +13,7 @@ pub const PROXMOX_PKG_VERSION: &str =
env!("CARGO_PKG_VERSION_MINOR"), env!("CARGO_PKG_VERSION_MINOR"),
); );
pub const PROXMOX_PKG_RELEASE: &str = env!("CARGO_PKG_VERSION_PATCH"); pub const PROXMOX_PKG_RELEASE: &str = env!("CARGO_PKG_VERSION_PATCH");
pub const PROXMOX_PKG_REPOID: &str = env!("CARGO_PKG_REPOSITORY"); pub const PROXMOX_PKG_REPOID: &str = env!("REPOID");
fn get_version( fn get_version(
_param: Value, _param: Value,