diff options
| author | bors <bors@rust-lang.org> | 2019-04-30 07:20:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-30 07:20:58 +0000 |
| commit | 86f73473c8de4598f8ade982dbb9d44f89777c54 (patch) | |
| tree | c8b52d63d7162a080e41ca235583f443f39ffdc3 | |
| parent | d0ff1a585f8bda16edf9023d83a6e19f24ddd11b (diff) | |
| parent | 8012b9119809a9d6ffc350cf884b1aea7d6dda54 (diff) | |
| download | rust-86f73473c8de4598f8ade982dbb9d44f89777c54.tar.gz rust-86f73473c8de4598f8ade982dbb9d44f89777c54.zip | |
Auto merge of #4045 - matthiaskrgr:RTU, r=phansch
rustc_tools_util: try to handle case of not having CFG_RELEASE_CHANNEL better when getting compiler channel. changelog: rustc_tools_util: try to handle case of not having CFG_RELEASE_CHANNEL better when getting compiler channel.
| -rw-r--r-- | rustc_tools_util/README.md | 4 | ||||
| -rw-r--r-- | rustc_tools_util/src/lib.rs | 39 |
2 files changed, 33 insertions, 10 deletions
diff --git a/rustc_tools_util/README.md b/rustc_tools_util/README.md index a88f47e4dbc..79c90b86b6c 100644 --- a/rustc_tools_util/README.md +++ b/rustc_tools_util/README.md @@ -30,6 +30,10 @@ fn main() { "cargo:rustc-env=COMMIT_DATE={}", 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() + ); } ```` diff --git a/rustc_tools_util/src/lib.rs b/rustc_tools_util/src/lib.rs index 19c27754839..8f89d50c64a 100644 --- a/rustc_tools_util/src/lib.rs +++ b/rustc_tools_util/src/lib.rs @@ -8,7 +8,7 @@ macro_rules! get_version_info { let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap(); 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_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> { std::process::Command::new("git") .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()) } +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)] mod test { use super::*; |
