Rollup merge of #107761 - oli-obk:miri_🪵, r=TaKO8Ki

Replace a command line flag with an env var to allow tools to initialize the tracing loggers at their own discretion

fixes https://github.com/rust-lang/miri/issues/2778

this was introduced in https://github.com/rust-lang/rust/pull/104645, so this PR reverts the flag-part and uses an env var instead.
This commit is contained in:
Michael Goulet 2023-02-08 20:01:25 -08:00 committed by GitHub
commit 32bb73eede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 37 deletions

View File

@ -229,10 +229,6 @@ fn run_compiler(
registry: diagnostics_registry(), registry: diagnostics_registry(),
}; };
if !tracing::dispatcher::has_been_set() {
init_rustc_env_logger_with_backtrace_option(&config.opts.unstable_opts.log_backtrace);
}
match make_input(config.opts.error_format, &matches.free) { match make_input(config.opts.error_format, &matches.free) {
Err(reported) => return Err(reported), Err(reported) => return Err(reported),
Ok(Some(input)) => { Ok(Some(input)) => {
@ -1251,16 +1247,7 @@ pub fn install_ice_hook() {
/// This allows tools to enable rust logging without having to magically match rustc's /// This allows tools to enable rust logging without having to magically match rustc's
/// tracing crate version. /// tracing crate version.
pub fn init_rustc_env_logger() { pub fn init_rustc_env_logger() {
init_rustc_env_logger_with_backtrace_option(&None); init_env_logger("RUSTC_LOG");
}
/// This allows tools to enable rust logging without having to magically match rustc's
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to
/// choose a target module you wish to show backtraces along with its logging.
pub fn init_rustc_env_logger_with_backtrace_option(backtrace_target: &Option<String>) {
if let Err(error) = rustc_log::init_rustc_env_logger_with_backtrace_option(backtrace_target) {
early_error(ErrorOutputType::default(), &error.to_string());
}
} }
/// This allows tools to enable rust logging without having to magically match rustc's /// This allows tools to enable rust logging without having to magically match rustc's
@ -1324,6 +1311,7 @@ pub(super) fn install() {}
pub fn main() -> ! { pub fn main() -> ! {
let start_time = Instant::now(); let start_time = Instant::now();
let start_rss = get_resident_set_size(); let start_rss = get_resident_set_size();
init_rustc_env_logger();
signal_handler::install(); signal_handler::install();
let mut callbacks = TimePassesCallbacks::default(); let mut callbacks = TimePassesCallbacks::default();
install_ice_hook(); install_ice_hook();

View File

@ -758,7 +758,6 @@ macro_rules! tracked {
tracked!(link_only, true); tracked!(link_only, true);
tracked!(llvm_plugins, vec![String::from("plugin_name")]); tracked!(llvm_plugins, vec![String::from("plugin_name")]);
tracked!(location_detail, LocationDetail { file: true, line: false, column: false }); tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
tracked!(log_backtrace, Some("filter".to_string()));
tracked!(maximal_hir_to_mir_coverage, true); tracked!(maximal_hir_to_mir_coverage, true);
tracked!(merge_functions, Some(MergeFunctions::Disabled)); tracked!(merge_functions, Some(MergeFunctions::Disabled));
tracked!(mir_emit_retag, true); tracked!(mir_emit_retag, true);

View File

@ -54,25 +54,12 @@
use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::layer::SubscriberExt;
pub fn init_rustc_env_logger() -> Result<(), Error> { pub fn init_rustc_env_logger() -> Result<(), Error> {
init_rustc_env_logger_with_backtrace_option(&None) init_env_logger("RUSTC_LOG")
}
pub fn init_rustc_env_logger_with_backtrace_option(
backtrace_target: &Option<String>,
) -> Result<(), Error> {
init_env_logger_with_backtrace_option("RUSTC_LOG", backtrace_target)
} }
/// In contrast to `init_rustc_env_logger` this allows you to choose an env var /// In contrast to `init_rustc_env_logger` this allows you to choose an env var
/// other than `RUSTC_LOG`. /// other than `RUSTC_LOG`.
pub fn init_env_logger(env: &str) -> Result<(), Error> { pub fn init_env_logger(env: &str) -> Result<(), Error> {
init_env_logger_with_backtrace_option(env, &None)
}
pub fn init_env_logger_with_backtrace_option(
env: &str,
backtrace_target: &Option<String>,
) -> Result<(), Error> {
let filter = match env::var(env) { let filter = match env::var(env) {
Ok(env) => EnvFilter::new(env), Ok(env) => EnvFilter::new(env),
_ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)), _ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)),
@ -106,8 +93,8 @@ pub fn init_env_logger_with_backtrace_option(
let layer = layer.with_thread_ids(true).with_thread_names(true); let layer = layer.with_thread_ids(true).with_thread_names(true);
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer); let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
match backtrace_target { match env::var(format!("{env}_BACKTRACE")) {
Some(str) => { Ok(str) => {
let fmt_layer = tracing_subscriber::fmt::layer() let fmt_layer = tracing_subscriber::fmt::layer()
.with_writer(io::stderr) .with_writer(io::stderr)
.without_time() .without_time()
@ -115,7 +102,7 @@ pub fn init_env_logger_with_backtrace_option(
let subscriber = subscriber.with(fmt_layer); let subscriber = subscriber.with(fmt_layer);
tracing::subscriber::set_global_default(subscriber).unwrap(); tracing::subscriber::set_global_default(subscriber).unwrap();
} }
None => { Err(_) => {
tracing::subscriber::set_global_default(subscriber).unwrap(); tracing::subscriber::set_global_default(subscriber).unwrap();
} }
}; };

View File

@ -1413,8 +1413,6 @@ pub(crate) fn parse_proc_macro_execution_strategy(
"what location details should be tracked when using caller_location, either \ "what location details should be tracked when using caller_location, either \
`none`, or a comma separated list of location details, for which \ `none`, or a comma separated list of location details, for which \
valid options are `file`, `line`, and `column` (default: `file,line,column`)"), valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
log_backtrace: Option<String> = (None, parse_opt_string, [TRACKED],
"add a backtrace along with logging"),
ls: bool = (false, parse_bool, [UNTRACKED], ls: bool = (false, parse_bool, [UNTRACKED],
"list the symbols defined by a library crate (default: no)"), "list the symbols defined by a library crate (default: no)"),
macro_backtrace: bool = (false, parse_bool, [UNTRACKED], macro_backtrace: bool = (false, parse_bool, [UNTRACKED],

View File

@ -77,7 +77,6 @@
-Z llvm-plugins=val -- a list LLVM plugins to enable (space separated) -Z llvm-plugins=val -- a list LLVM plugins to enable (space separated)
-Z llvm-time-trace=val -- generate JSON tracing data file from LLVM data (default: no) -Z llvm-time-trace=val -- generate JSON tracing data file from LLVM data (default: no)
-Z location-detail=val -- what location details should be tracked when using caller_location, either `none`, or a comma separated list of location details, for which valid options are `file`, `line`, and `column` (default: `file,line,column`) -Z location-detail=val -- what location details should be tracked when using caller_location, either `none`, or a comma separated list of location details, for which valid options are `file`, `line`, and `column` (default: `file,line,column`)
-Z log-backtrace=val -- add a backtrace along with logging
-Z ls=val -- list the symbols defined by a library crate (default: no) -Z ls=val -- list the symbols defined by a library crate (default: no)
-Z macro-backtrace=val -- show macro backtraces (default: no) -Z macro-backtrace=val -- show macro backtraces (default: no)
-Z maximal-hir-to-mir-coverage=val -- save as much information as possible about the correspondence between MIR and HIR as source scopes (default: no) -Z maximal-hir-to-mir-coverage=val -- save as much information as possible about the correspondence between MIR and HIR as source scopes (default: no)

View File

@ -1,9 +1,9 @@
// run-pass // run-pass
// //
// This test makes sure that log-backtrace option doesn't give a compilation error. // This test makes sure that log-backtrace option at least parses correctly
// //
// dont-check-compiler-stdout // dont-check-compiler-stdout
// dont-check-compiler-stderr // dont-check-compiler-stderr
// rustc-env:RUSTC_LOG=info // rustc-env:RUSTC_LOG=info
// compile-flags: -Zlog-backtrace=rustc_metadata::creader // rustc-env:RUSTC_LOG_BACKTRACE=rustc_metadata::creader
fn main() {} fn main() {}