Change system_information_string according to request from Spotify (#218)

Spotify requested us to use a system_information_string that looks like
librespot_[short sha]_[random 8 characters build id]
This commit is contained in:
Fabian Zaremba 2017-07-17 14:31:06 +02:00 committed by Paul Liétar
parent aa86ebf549
commit 910974e5e2
4 changed files with 35 additions and 4 deletions

View file

@ -62,6 +62,7 @@ tokio-signal = "0.1"
uuid = { version = "0.4", features = ["v4"] } uuid = { version = "0.4", features = ["v4"] }
[build-dependencies] [build-dependencies]
rand = "0.3.13"
vergen = "0.1.0" vergen = "0.1.0"
protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros", features = ["with-syntex"] } protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros", features = ["with-syntex"] }

View file

@ -1,13 +1,42 @@
extern crate vergen; extern crate vergen;
extern crate protobuf_macros; extern crate protobuf_macros;
extern crate rand;
use rand::Rng;
use std::env; use std::env;
use std::path::PathBuf; use std::path::PathBuf;
use std::fs::OpenOptions;
use std::io::Write;
fn main() { fn main() {
vergen::vergen(vergen::OutputFns::all()).unwrap();
let out = PathBuf::from(env::var("OUT_DIR").unwrap()); let out = PathBuf::from(env::var("OUT_DIR").unwrap());
vergen::vergen(vergen::OutputFns::all()).unwrap();
let build_id: String = rand::thread_rng()
.gen_ascii_chars()
.take(8)
.collect();
let mut version_file =
OpenOptions::new()
.write(true)
.append(true)
.open(&out.join("version.rs"))
.unwrap();
let build_id_fn = format!("
/// Generate a random build id.
pub fn build_id() -> &'static str {{
\"{}\"
}}
", build_id);
if let Err(e) = version_file.write_all(build_id_fn.as_bytes()) {
println!("{}", e);
}
protobuf_macros::expand("src/lib.in.rs", &out.join("lib.rs")).unwrap(); protobuf_macros::expand("src/lib.in.rs", &out.join("lib.rs")).unwrap();
println!("cargo:rerun-if-changed=src/lib.in.rs"); println!("cargo:rerun-if-changed=src/lib.in.rs");

View file

@ -41,7 +41,7 @@ pub fn authenticate(transport: Transport, credentials: Credentials, device_id: S
system_info => { system_info => {
cpu_family: CpuFamily::CPU_UNKNOWN, cpu_family: CpuFamily::CPU_UNKNOWN,
os: Os::OS_UNKNOWN, os: Os::OS_UNKNOWN,
system_information_string: "This is not the client you are looking for".to_owned(), system_information_string: format!("librespot_{}_{}", version::short_sha(), version::build_id()),
device_id: device_id, device_id: device_id,
}, },
version_string: version::version_string(), version_string: version::version_string(),

View file

@ -110,10 +110,11 @@ fn setup(args: &[String]) -> Setup {
let verbose = matches.opt_present("verbose"); let verbose = matches.opt_present("verbose");
setup_logging(verbose); setup_logging(verbose);
info!("librespot {} ({}). Built on {}.", info!("librespot {} ({}). Built on {}. Build ID: {}",
version::short_sha(), version::short_sha(),
version::commit_date(), version::commit_date(),
version::short_now()); version::short_now(),
version::build_id());
let backend_name = matches.opt_str("backend"); let backend_name = matches.opt_str("backend");
if backend_name == Some("?".into()) { if backend_name == Some("?".into()) {