load commit hash at compile time
This commit is contained in:
parent
ce7f70ad7b
commit
98c22d2408
|
@ -58,5 +58,13 @@ fn main() {
|
||||||
.arg(asset_path(asset))
|
.arg(asset_path(asset))
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
});
|
||||||
|
|
||||||
|
let commit = Command::new("git")
|
||||||
|
.args(&["rev-parse", "HEAD"])
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let commit = String::from_utf8(commit.stdout).unwrap();
|
||||||
|
println!("cargo:rustc-env=COMMIT_HASH={commit}");
|
||||||
}
|
}
|
|
@ -15,6 +15,18 @@ pub struct Redis {
|
||||||
pub prefix: String
|
pub prefix: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct VersionData {
|
||||||
|
pub commit: String
|
||||||
|
}
|
||||||
|
impl Default for VersionData {
|
||||||
|
fn default() -> Self {
|
||||||
|
VersionData {
|
||||||
|
commit: env!("COMMIT_HASH").to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Env {
|
pub struct Env {
|
||||||
pub logging: bool,
|
pub logging: bool,
|
||||||
|
@ -24,7 +36,8 @@ pub struct Env {
|
||||||
pub filedir: String,
|
pub filedir: String,
|
||||||
pub instanceurl: String,
|
pub instanceurl: String,
|
||||||
pub uploadspath: String,
|
pub uploadspath: String,
|
||||||
pub confpath: String
|
pub confpath: String,
|
||||||
|
pub version: VersionData
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_var<T: Into<String>, O: From<String>>(name: T) -> Result<O, String> {
|
fn get_var<T: Into<String>, O: From<String>>(name: T) -> Result<O, String> {
|
||||||
|
@ -140,7 +153,8 @@ pub fn loadenv() -> Result<Env, Box<dyn std::error::Error>> {
|
||||||
return Err(format!("CONF_FILE is {}, which is not a file!", spath).into())
|
return Err(format!("CONF_FILE is {}, which is not a file!", spath).into())
|
||||||
}
|
}
|
||||||
spath
|
spath
|
||||||
}
|
},
|
||||||
|
version: VersionData::default()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue