mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-16 22:18:40 +00:00
rustc_tools_util: try to handle case of not having CFG_RELEASE_CHANNEL better when getting compiler channel.
This commit is contained in:
parent
78d13e007f
commit
8012b91198
2 changed files with 33 additions and 10 deletions
|
@ -30,6 +30,10 @@ fn main() {
|
||||||
"cargo:rustc-env=COMMIT_DATE={}",
|
"cargo:rustc-env=COMMIT_DATE={}",
|
||||||
rustc_tools_util::get_commit_date().unwrap_or_default()
|
rustc_tools_util::get_commit_date().unwrap_or_default()
|
||||||
);
|
);
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}",
|
||||||
|
rustc_tools_util::get_channel_from_compiler_output().unwrap_or_default()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
````
|
````
|
||||||
|
|
|
@ -8,7 +8,7 @@ macro_rules! get_version_info {
|
||||||
let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
|
let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
|
||||||
let crate_name = String::from(env!("CARGO_PKG_NAME"));
|
let crate_name = String::from(env!("CARGO_PKG_NAME"));
|
||||||
|
|
||||||
let host_compiler = $crate::get_channel();
|
let host_compiler = option_env!("RUSTC_RELEASE_CHANNEL").map(str::to_string);
|
||||||
let commit_hash = option_env!("GIT_HASH").map(str::to_string);
|
let commit_hash = option_env!("GIT_HASH").map(str::to_string);
|
||||||
let commit_date = option_env!("COMMIT_DATE").map(str::to_string);
|
let commit_date = option_env!("COMMIT_DATE").map(str::to_string);
|
||||||
|
|
||||||
|
@ -79,15 +79,6 @@ impl std::fmt::Debug for VersionInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_channel() -> Option<String> {
|
|
||||||
if let Ok(channel) = env::var("CFG_RELEASE_CHANNEL") {
|
|
||||||
Some(channel)
|
|
||||||
} else {
|
|
||||||
// we could ask ${RUSTC} -Vv and do some parsing and find out
|
|
||||||
Some(String::from("nightly"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_commit_hash() -> Option<String> {
|
pub fn get_commit_hash() -> Option<String> {
|
||||||
std::process::Command::new("git")
|
std::process::Command::new("git")
|
||||||
.args(&["rev-parse", "--short", "HEAD"])
|
.args(&["rev-parse", "--short", "HEAD"])
|
||||||
|
@ -104,6 +95,34 @@ pub fn get_commit_date() -> Option<String> {
|
||||||
.and_then(|r| String::from_utf8(r.stdout).ok())
|
.and_then(|r| String::from_utf8(r.stdout).ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_channel() -> Option<String> {
|
||||||
|
match env::var("CFG_RELEASE_CHANNEL") {
|
||||||
|
Ok(channel) => Some(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") {
|
||||||
|
Some(String::from("beta"))
|
||||||
|
} else if rustc_output.contains("stable") {
|
||||||
|
Some(String::from("stable"))
|
||||||
|
} else {
|
||||||
|
// default to nightly if we fail to parse
|
||||||
|
Some(String::from("nightly"))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// default to nightly
|
||||||
|
None => Some(String::from("nightly")),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Add table
Reference in a new issue