diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2022-11-09 15:39:07 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-09 15:39:07 -0500 | 
| commit | 70c04a2fd1738ece290631c53c59616c30febdf9 (patch) | |
| tree | bc2d4cc03695a0ead4727eae58f93c2874813fc2 /compiler/rustc_driver/src/lib.rs | |
| parent | 656f56c2d697488bd775449c8e711c5cd1070901 (diff) | |
| parent | a68ec2205335e2c3de8ba56fb6a31b99f10c95a6 (diff) | |
| download | rust-70c04a2fd1738ece290631c53c59616c30febdf9.tar.gz rust-70c04a2fd1738ece290631c53c59616c30febdf9.zip | |
Rollup merge of #104184 - jyn514:rustdoc-version, r=davidtwco
Fix `rustdoc --version` when used with download-rustc Previously, rustdoc would unconditionally report the version that *rustc* was compiled with. That showed things like `nightly-2022-10-30`, which wasn't right, since this was a `dev` build compiled from source. Fix it by changing `rustc_driver::version` to a macro expanded at invocation time. cc https://github.com/rust-lang/rust/issues/103206#issuecomment-1284123084
Diffstat (limited to 'compiler/rustc_driver/src/lib.rs')
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 42 | 
1 files changed, 32 insertions, 10 deletions
| diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 423f0cdddfd..e043368fdfe 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -6,6 +6,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(once_cell)] +#![feature(decl_macro)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] #![deny(rustc::untranslatable_diagnostic)] @@ -753,20 +754,41 @@ fn print_crate_info( } /// Prints version information -pub fn version(binary: &str, matches: &getopts::Matches) { +/// +/// NOTE: this is a macro to support drivers built at a different time than the main `rustc_driver` crate. +pub macro version($binary: literal, $matches: expr) { + fn unw(x: Option<&str>) -> &str { + x.unwrap_or("unknown") + } + $crate::version_at_macro_invocation( + $binary, + $matches, + unw(option_env!("CFG_VERSION")), + unw(option_env!("CFG_VER_HASH")), + unw(option_env!("CFG_VER_DATE")), + unw(option_env!("CFG_RELEASE")), + ) +} + +#[doc(hidden)] // use the macro instead +pub fn version_at_macro_invocation( + binary: &str, + matches: &getopts::Matches, + version: &str, + commit_hash: &str, + commit_date: &str, + release: &str, +) { let verbose = matches.opt_present("verbose"); - println!("{} {}", binary, util::version_str().unwrap_or("unknown version")); + println!("{} {}", binary, version); if verbose { - fn unw(x: Option<&str>) -> &str { - x.unwrap_or("unknown") - } println!("binary: {}", binary); - println!("commit-hash: {}", unw(util::commit_hash_str())); - println!("commit-date: {}", unw(util::commit_date_str())); + println!("commit-hash: {}", commit_hash); + println!("commit-date: {}", commit_date); println!("host: {}", config::host_triple()); - println!("release: {}", unw(util::release_str())); + println!("release: {}", release); let debug_flags = matches.opt_strs("Z"); let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend=")); @@ -1082,7 +1104,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> { } if matches.opt_present("version") { - version("rustc", &matches); + version!("rustc", &matches); return None; } @@ -1227,7 +1249,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { format!("we would appreciate a bug report: {}", bug_report_url).into(), format!( "rustc {} running on {}", - util::version_str().unwrap_or("unknown_version"), + util::version_str!().unwrap_or("unknown_version"), config::host_triple() ) .into(), | 
