Replace version functions by constants

This commit is contained in:
johannesd3 2021-02-09 19:42:56 +01:00
parent b72485cf46
commit 09e506ed66
5 changed files with 20 additions and 50 deletions

View file

@ -102,7 +102,7 @@ fn initial_state() -> State {
fn initial_device_state(config: ConnectConfig) -> DeviceState { fn initial_device_state(config: ConnectConfig) -> DeviceState {
{ {
let mut msg = DeviceState::new(); let mut msg = DeviceState::new();
msg.set_sw_version(version::version_string()); msg.set_sw_version(version::VERSION_STRING.to_string());
msg.set_is_active(false); msg.set_is_active(false);
msg.set_can_play(true); msg.set_can_play(true);
msg.set_volume(0); msg.set_volume(0);

View file

@ -17,7 +17,7 @@ impl Default for SessionConfig {
fn default() -> SessionConfig { fn default() -> SessionConfig {
let device_id = Uuid::new_v4().to_hyphenated().to_string(); let device_id = Uuid::new_v4().to_hyphenated().to_string();
SessionConfig { SessionConfig {
user_agent: version::version_string(), user_agent: version::VERSION_STRING.to_string(),
device_id: device_id, device_id: device_id,
proxy: None, proxy: None,
ap_port: None, ap_port: None,

View file

@ -88,11 +88,11 @@ pub fn authenticate(
.mut_system_info() .mut_system_info()
.set_system_information_string(format!( .set_system_information_string(format!(
"librespot_{}_{}", "librespot_{}_{}",
version::short_sha(), version::SHA_SHORT,
version::build_id() version::BUILD_ID
)); ));
packet.mut_system_info().set_device_id(device_id); packet.mut_system_info().set_device_id(device_id);
packet.set_version_string(version::version_string()); packet.set_version_string(version::VERSION_STRING.to_string());
let cmd = 0xab; let cmd = 0xab;
let data = packet.write_to_bytes().unwrap(); let data = packet.write_to_bytes().unwrap();

View file

@ -1,44 +1,14 @@
pub fn version_string() -> String { /// Version string of the form "librespot-<sha>"
format!("librespot-{}", short_sha()) pub const VERSION_STRING: &str = concat!("librespot-", env!("VERGEN_SHA_SHORT"));
}
// Generate a timestamp representing now (UTC) in RFC3339 format. /// Generate a timstamp string representing now (UTC).
pub fn now() -> &'static str { pub const BUILD_DATE: &str = env!("VERGEN_BUILD_DATE");
env!("VERGEN_BUILD_TIMESTAMP")
}
// Generate a timstamp string representing now (UTC). /// Short sha of the latest git commit.
pub fn short_now() -> &'static str { pub const SHA_SHORT: &str = env!("VERGEN_SHA_SHORT");
env!("VERGEN_BUILD_DATE")
}
// Generate a SHA string /// Date of the latest git commit.
pub fn sha() -> &'static str { pub const COMMIT_DATE: &str = env!("VERGEN_COMMIT_DATE");
env!("VERGEN_SHA")
}
// Generate a short SHA string /// A random build id.
pub fn short_sha() -> &'static str { pub const BUILD_ID: &str = env!("VERGEN_BUILD_ID");
env!("VERGEN_SHA_SHORT")
}
// Generate the commit date string
pub fn commit_date() -> &'static str {
env!("VERGEN_COMMIT_DATE")
}
// Generate the target triple string
pub fn target() -> &'static str {
env!("VERGEN_TARGET_TRIPLE")
}
// Generate a semver string
pub fn semver() -> &'static str {
// env!("VERGEN_SEMVER")
env!("CARGO_PKG_VERSION")
}
// Generate a random build id.
pub fn build_id() -> &'static str {
env!("VERGEN_BUILD_ID")
}

View file

@ -225,10 +225,10 @@ fn setup(args: &[String]) -> Setup {
info!( info!(
"librespot {} ({}). Built on {}. Build ID: {}", "librespot {} ({}). Built on {}. Build ID: {}",
version::short_sha(), version::SHA_SHORT,
version::commit_date(), version::COMMIT_DATE,
version::short_now(), version::BUILD_DATE,
version::build_id() version::BUILD_ID
); );
let backend_name = matches.opt_str("backend"); let backend_name = matches.opt_str("backend");
@ -329,7 +329,7 @@ fn setup(args: &[String]) -> Setup {
let device_id = device_id(&name); let device_id = device_id(&name);
SessionConfig { SessionConfig {
user_agent: version::version_string(), user_agent: version::VERSION_STRING.to_string(),
device_id: device_id, device_id: device_id,
proxy: matches.opt_str("proxy").or(std::env::var("http_proxy").ok()).map( proxy: matches.opt_str("proxy").or(std::env::var("http_proxy").ok()).map(
|s| { |s| {