Skip to content

Commit

Permalink
Auto merge of #3614 - matthiaskrgr:rustc_tool_utils, r=phansch
Browse files Browse the repository at this point in the history
rustc_tool_utils: fix failure to create proper non-repo version string when used in crates on crates.io, bump version
  • Loading branch information
bors committed Jan 3, 2019
2 parents 84aa027 + 31d9630 commit 5277a1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rustc_tools_util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustc_tools_util"
version = "0.1.0"
version = "0.1.1"
authors = ["Matthias Krüger <[email protected]>"]
description = "small helper to generate version information for git packages"
repository = "https://github.com/rust-lang/rust-clippy"
Expand Down
21 changes: 11 additions & 10 deletions rustc_tools_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ pub struct VersionInfo {

impl std::fmt::Display for VersionInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.commit_hash.is_some() {
let hash = self.commit_hash.clone().unwrap_or_default();
let hash_trimmed = hash.trim();

let date = self.commit_date.clone().unwrap_or_default();
let date_trimmed = date.trim();

if (hash_trimmed.len() + date_trimmed.len()) > 0 {
write!(
f,
"{} {}.{}.{} ({} {})",
self.crate_name,
self.major,
self.minor,
self.patch,
self.commit_hash.clone().unwrap_or_default().trim(),
self.commit_date.clone().unwrap_or_default().trim(),
self.crate_name, self.major, self.minor, self.patch, hash_trimmed, date_trimmed,
)?;
} else {
write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
Expand Down Expand Up @@ -121,7 +122,7 @@ mod test {
let vi = get_version_info!();
assert_eq!(vi.major, 0);
assert_eq!(vi.minor, 1);
assert_eq!(vi.patch, 0);
assert_eq!(vi.patch, 1);
assert_eq!(vi.crate_name, "rustc_tools_util");
// hard to make positive tests for these since they will always change
assert!(vi.commit_hash.is_none());
Expand All @@ -131,7 +132,7 @@ mod test {
#[test]
fn test_display_local() {
let vi = get_version_info!();
assert_eq!(vi.to_string(), "rustc_tools_util 0.1.0");
assert_eq!(vi.to_string(), "rustc_tools_util 0.1.1");
}

#[test]
Expand All @@ -140,7 +141,7 @@ mod test {
let s = format!("{:?}", vi);
assert_eq!(
s,
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 1, patch: 0 }"
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 1, patch: 1 }"
);
}

Expand Down

0 comments on commit 5277a1f

Please sign in to comment.