|
6 | 6 |
|
7 | 7 | #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
8 | 8 | #![feature(once_cell)]
|
| 9 | +#![feature(decl_macro)] |
9 | 10 | #![recursion_limit = "256"]
|
10 | 11 | #![allow(rustc::potential_query_instability)]
|
11 | 12 | #![deny(rustc::untranslatable_diagnostic)]
|
@@ -742,20 +743,41 @@ fn print_crate_info(
|
742 | 743 | }
|
743 | 744 |
|
744 | 745 | /// Prints version information
|
745 |
| -pub fn version(binary: &str, matches: &getopts::Matches) { |
| 746 | +/// |
| 747 | +/// NOTE: this is a macro to support drivers built at a different time than the main `rustc_driver` crate. |
| 748 | +pub macro version($binary: literal, $matches: expr) { |
| 749 | + fn unw(x: Option<&str>) -> &str { |
| 750 | + x.unwrap_or("unknown") |
| 751 | + } |
| 752 | + $crate::version_at_macro_invocation( |
| 753 | + $binary, |
| 754 | + $matches, |
| 755 | + unw(option_env!("CFG_VERSION")), |
| 756 | + unw(option_env!("CFG_VER_HASH")), |
| 757 | + unw(option_env!("CFG_VER_DATE")), |
| 758 | + unw(option_env!("CFG_RELEASE")), |
| 759 | + ) |
| 760 | +} |
| 761 | + |
| 762 | +#[doc(hidden)] // use the macro instead |
| 763 | +pub fn version_at_macro_invocation( |
| 764 | + binary: &str, |
| 765 | + matches: &getopts::Matches, |
| 766 | + version: &str, |
| 767 | + commit_hash: &str, |
| 768 | + commit_date: &str, |
| 769 | + release: &str, |
| 770 | +) { |
746 | 771 | let verbose = matches.opt_present("verbose");
|
747 | 772 |
|
748 |
| - println!("{} {}", binary, util::version_str().unwrap_or("unknown version")); |
| 773 | + println!("{} {}", binary, version); |
749 | 774 |
|
750 | 775 | if verbose {
|
751 |
| - fn unw(x: Option<&str>) -> &str { |
752 |
| - x.unwrap_or("unknown") |
753 |
| - } |
754 | 776 | println!("binary: {}", binary);
|
755 |
| - println!("commit-hash: {}", unw(util::commit_hash_str())); |
756 |
| - println!("commit-date: {}", unw(util::commit_date_str())); |
| 777 | + println!("commit-hash: {}", commit_hash); |
| 778 | + println!("commit-date: {}", commit_date); |
757 | 779 | println!("host: {}", config::host_triple());
|
758 |
| - println!("release: {}", unw(util::release_str())); |
| 780 | + println!("release: {}", release); |
759 | 781 |
|
760 | 782 | let debug_flags = matches.opt_strs("Z");
|
761 | 783 | let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
|
@@ -1071,7 +1093,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
|
1071 | 1093 | }
|
1072 | 1094 |
|
1073 | 1095 | if matches.opt_present("version") {
|
1074 |
| - version("rustc", &matches); |
| 1096 | + version!("rustc", &matches); |
1075 | 1097 | return None;
|
1076 | 1098 | }
|
1077 | 1099 |
|
@@ -1216,7 +1238,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
1216 | 1238 | format!("we would appreciate a bug report: {}", bug_report_url).into(),
|
1217 | 1239 | format!(
|
1218 | 1240 | "rustc {} running on {}",
|
1219 |
| - util::version_str().unwrap_or("unknown_version"), |
| 1241 | + util::version_str!().unwrap_or("unknown_version"), |
1220 | 1242 | config::host_triple()
|
1221 | 1243 | )
|
1222 | 1244 | .into(),
|
|
0 commit comments