From 2bfaffbf8227fbfe99b80d1fdd87163bb7051014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20sp1rit=E2=80=8B?= Date: Mon, 16 Aug 2021 13:23:53 +0200 Subject: [PATCH 1/2] proc_macro_api: make commit & date suffix of binary version optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Florian "sp1rit"​ --- crates/proc_macro_api/src/version.rs | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/proc_macro_api/src/version.rs b/crates/proc_macro_api/src/version.rs index fa2b60fcb9..abd28e6182 100644 --- a/crates/proc_macro_api/src/version.rs +++ b/crates/proc_macro_api/src/version.rs @@ -14,8 +14,8 @@ use snap::read::FrameDecoder as SnapDecoder; pub struct RustCInfo { pub version: (usize, usize, usize), pub channel: String, - pub commit: String, - pub date: String, + pub commit: Option, + pub date: Option, } /// Read rustc dylib information @@ -38,18 +38,24 @@ pub fn read_dylib_info(dylib_path: &AbsPath) -> io::Result { let version = version_parts.next().ok_or_else(|| err!("no version"))?; let channel = version_parts.next().unwrap_or_default().to_string(); - let commit = items.next().ok_or_else(|| err!("no commit info"))?; - // remove ( - if commit.len() == 0 { - return Err(err!("commit format error")); - } - let commit = commit[1..].to_string(); - let date = items.next().ok_or_else(|| err!("no date info"))?; - // remove ) - if date.len() == 0 { - return Err(err!("date format error")); - } - let date = date[0..date.len() - 2].to_string(); + let commit = match items.next() { + Some(commit) => { + match commit.len() { + 0 => None, + _ => Some(commit[1..].to_string() /* remove ( */) + } + }, + None => None + }; + let date = match items.next() { + Some(date) => { + match date.len() { + 0 => None, + _ => Some(date[0..date.len() - 2].to_string() /* remove ) */) + } + }, + None => None + }; let version_numbers = version .split('.') From f69225c4fa3e90a0a452375cf3b9f726f3c0cbcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 17 Aug 2021 19:25:37 +0300 Subject: [PATCH 2/2] Fix formatting --- crates/proc_macro_api/src/version.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/proc_macro_api/src/version.rs b/crates/proc_macro_api/src/version.rs index abd28e6182..4c065c93c4 100644 --- a/crates/proc_macro_api/src/version.rs +++ b/crates/proc_macro_api/src/version.rs @@ -42,19 +42,19 @@ pub fn read_dylib_info(dylib_path: &AbsPath) -> io::Result { Some(commit) => { match commit.len() { 0 => None, - _ => Some(commit[1..].to_string() /* remove ( */) + _ => Some(commit[1..].to_string() /* remove ( */), } - }, - None => None + } + None => None, }; let date = match items.next() { Some(date) => { match date.len() { 0 => None, - _ => Some(date[0..date.len() - 2].to_string() /* remove ) */) + _ => Some(date[0..date.len() - 2].to_string() /* remove ) */), } - }, - None => None + } + None => None, }; let version_numbers = version