mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-08 04:56:58 +00:00
rustc_tool_utils: fix failure to create proper non-repo version string when used in crates on crates.io, bump version
This commit is contained in:
parent
3de9a3de54
commit
31d96300ef
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rustc_tools_util"
|
name = "rustc_tools_util"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Matthias Krüger <matthias.krueger@famsik.de>"]
|
authors = ["Matthias Krüger <matthias.krueger@famsik.de>"]
|
||||||
description = "small helper to generate version information for git packages"
|
description = "small helper to generate version information for git packages"
|
||||||
repository = "https://github.com/rust-lang/rust-clippy"
|
repository = "https://github.com/rust-lang/rust-clippy"
|
||||||
|
@ -46,16 +46,17 @@ pub struct VersionInfo {
|
|||||||
|
|
||||||
impl std::fmt::Display for VersionInfo {
|
impl std::fmt::Display for VersionInfo {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
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!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{} {}.{}.{} ({} {})",
|
"{} {}.{}.{} ({} {})",
|
||||||
self.crate_name,
|
self.crate_name, self.major, self.minor, self.patch, hash_trimmed, date_trimmed,
|
||||||
self.major,
|
|
||||||
self.minor,
|
|
||||||
self.patch,
|
|
||||||
self.commit_hash.clone().unwrap_or_default().trim(),
|
|
||||||
self.commit_date.clone().unwrap_or_default().trim(),
|
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
|
write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
|
||||||
@ -121,7 +122,7 @@ mod test {
|
|||||||
let vi = get_version_info!();
|
let vi = get_version_info!();
|
||||||
assert_eq!(vi.major, 0);
|
assert_eq!(vi.major, 0);
|
||||||
assert_eq!(vi.minor, 1);
|
assert_eq!(vi.minor, 1);
|
||||||
assert_eq!(vi.patch, 0);
|
assert_eq!(vi.patch, 1);
|
||||||
assert_eq!(vi.crate_name, "rustc_tools_util");
|
assert_eq!(vi.crate_name, "rustc_tools_util");
|
||||||
// hard to make positive tests for these since they will always change
|
// hard to make positive tests for these since they will always change
|
||||||
assert!(vi.commit_hash.is_none());
|
assert!(vi.commit_hash.is_none());
|
||||||
@ -131,7 +132,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_display_local() {
|
fn test_display_local() {
|
||||||
let vi = get_version_info!();
|
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]
|
#[test]
|
||||||
@ -140,7 +141,7 @@ mod test {
|
|||||||
let s = format!("{:?}", vi);
|
let s = format!("{:?}", vi);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
s,
|
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 }"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user