diff options
| author | Philipp Krones <hello@philkrones.com> | 2024-08-08 19:13:50 +0200 |
|---|---|---|
| committer | Philipp Krones <hello@philkrones.com> | 2024-08-08 19:13:50 +0200 |
| commit | 1ac76a2062b94b72c36650d21ac1af40b4aea0e3 (patch) | |
| tree | 3a60aacad7bafce6808db3f52f0cfa6c67f29b38 /rustc_tools_util | |
| parent | 4c6a3f4b6eb496c03cb91b582c2ee5e4795ec568 (diff) | |
| download | rust-1ac76a2062b94b72c36650d21ac1af40b4aea0e3.tar.gz rust-1ac76a2062b94b72c36650d21ac1af40b4aea0e3.zip | |
Merge commit 'cb806113e0f83a8f9b47d35b453b676543bcc40e' into clippy-subtree-update
Diffstat (limited to 'rustc_tools_util')
| -rw-r--r-- | rustc_tools_util/Cargo.toml | 3 | ||||
| -rw-r--r-- | rustc_tools_util/src/lib.rs | 59 |
2 files changed, 28 insertions, 34 deletions
diff --git a/rustc_tools_util/Cargo.toml b/rustc_tools_util/Cargo.toml index 877049ae7d0..37b592da132 100644 --- a/rustc_tools_util/Cargo.toml +++ b/rustc_tools_util/Cargo.toml @@ -10,6 +10,3 @@ categories = ["development-tools"] edition = "2018" [dependencies] - -[features] -deny-warnings = [] diff --git a/rustc_tools_util/src/lib.rs b/rustc_tools_util/src/lib.rs index 4c1d8c3733d..2cc38130472 100644 --- a/rustc_tools_util/src/lib.rs +++ b/rustc_tools_util/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] +use std::str; /// This macro creates the version string during compilation from the /// current environment @@ -101,49 +101,46 @@ impl std::fmt::Debug for VersionInfo { #[must_use] pub fn get_commit_hash() -> Option<String> { - std::process::Command::new("git") - .args(["rev-parse", "--short", "HEAD"]) + let output = std::process::Command::new("git") + .args(["rev-parse", "HEAD"]) .output() - .ok() - .and_then(|r| String::from_utf8(r.stdout).ok()) + .ok()?; + let mut stdout = output.status.success().then_some(output.stdout)?; + stdout.truncate(10); + String::from_utf8(stdout).ok() } #[must_use] pub fn get_commit_date() -> Option<String> { - std::process::Command::new("git") + let output = std::process::Command::new("git") .args(["log", "-1", "--date=short", "--pretty=format:%cd"]) .output() - .ok() - .and_then(|r| String::from_utf8(r.stdout).ok()) + .ok()?; + let stdout = output.status.success().then_some(output.stdout)?; + String::from_utf8(stdout).ok() } #[must_use] pub fn get_channel() -> String { - match std::env::var("CFG_RELEASE_CHANNEL") { - Ok(channel) => channel, - Err(_) => { - // if that failed, try to ask rustc -V, do some parsing and find out - match std::process::Command::new("rustc") - .arg("-V") - .output() - .ok() - .and_then(|r| String::from_utf8(r.stdout).ok()) - { - Some(rustc_output) => { - if rustc_output.contains("beta") { - String::from("beta") - } else if rustc_output.contains("stable") { - String::from("stable") - } else { - // default to nightly if we fail to parse - String::from("nightly") - } - }, - // default to nightly - None => String::from("nightly"), + if let Ok(channel) = std::env::var("CFG_RELEASE_CHANNEL") { + return channel; + } + + // if that failed, try to ask rustc -V, do some parsing and find out + if let Ok(output) = std::process::Command::new("rustc").arg("-V").output() { + if output.status.success() { + if let Ok(rustc_output) = str::from_utf8(&output.stdout) { + if rustc_output.contains("beta") { + return String::from("beta"); + } else if rustc_output.contains("stable") { + return String::from("stable"); + } } - }, + } } + + // default to nightly + String::from("nightly") } #[cfg(test)] |
