Browse Source

Improve the --version option

pull/5/head
Rodolphe Breard 6 years ago
parent
commit
89660b6cd2
  1. 1
      acmed/Cargo.toml
  2. 45
      acmed/build.rs
  3. 10
      acmed/src/main.rs

1
acmed/Cargo.toml

@ -18,6 +18,7 @@ handlebars = "2.0.0-beta.1"
http_req = "0.4"
log = "0.4"
openssl = "0.10"
openssl-sys = "0.9"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
time = "0.1"

45
acmed/build.rs

@ -60,19 +60,58 @@ fn set_lock() {
if p.name == "http_req" {
let agent = format!("{}/{}", p.name, p.version);
set_rustc_env_var!("ACMED_HTTP_LIB_AGENT", agent);
set_rustc_env_var!("ACMED_HTTP_LIB_NAME", p.name);
set_rustc_env_var!("ACMED_HTTP_LIB_VERSION", p.version);
return;
}
}
}
fn get_openssl_version_unit(n: u64, pos: u32) -> u64 {
let p = 0xff_00_00_00_0 >> (8 * pos);
let n = n & p;
n >> (8 * (3 - pos) + 4)
}
fn get_openssl_version(v: &str) -> String {
let v = u64::from_str_radix(&v, 16).unwrap();
let mut version = vec![];
for i in 0..3 {
let n = get_openssl_version_unit(v, i);
version.push(format!("{}", n));
}
let version = version.join(".");
let p = get_openssl_version_unit(v, 3);
if p != 0 {
let p = p + 0x60;
let p = std::char::from_u32(p as u32).unwrap();
format!("{}{}", version, p)
} else {
version
}
}
fn set_tls() {
if let Ok(v) = env::var("DEP_OPENSSL_VERSION_NUMBER") {
let version = get_openssl_version(&v);
set_rustc_env_var!("ACMED_TLS_LIB_VERSION", version);
set_rustc_env_var!("ACMED_TLS_LIB_NAME", "OpenSSL");
}
if let Ok(v) = env::var("DEP_OPENSSL_LIBRESSL_VERSION_NUMBER") {
let version = get_openssl_version(&v);
set_rustc_env_var!("ACMED_TLS_LIB_VERSION", version);
set_rustc_env_var!("ACMED_TLS_LIB_NAME", "LibreSSL");
}
}
fn set_target() {
match env::var("TARGET") {
Ok(target) => set_rustc_env_var!("ACMED_TARGET", target),
Err(_) => {}
if let Ok(target) = env::var("TARGET") {
set_rustc_env_var!("ACMED_TARGET", target);
};
}
fn main() {
set_target();
set_tls();
set_lock();
}

10
acmed/src/main.rs

@ -32,8 +32,18 @@ pub const DEFAULT_HTTP_FAIL_WAIT_SEC: u64 = 1;
pub const DEFAULT_HOOK_ALLOW_FAILURE: bool = false;
fn main() {
let full_version = format!(
"{} {}\n\nCompiled with:\n {} {}\n {} {}",
APP_VERSION,
env!("ACMED_TARGET"),
env!("ACMED_TLS_LIB_NAME"),
env!("ACMED_TLS_LIB_VERSION"),
env!("ACMED_HTTP_LIB_NAME"),
env!("ACMED_HTTP_LIB_VERSION")
);
let matches = App::new(APP_NAME)
.version(APP_VERSION)
.long_version(full_version.as_str())
.arg(
Arg::with_name("config")
.short("c")

Loading…
Cancel
Save