@@ -9,11 +9,12 @@ extern crate rustc_data_structures;
9
9
extern crate rustc_driver;
10
10
extern crate rustc_hir;
11
11
extern crate rustc_interface;
12
+ extern crate rustc_log;
12
13
extern crate rustc_metadata;
13
14
extern crate rustc_middle;
14
15
extern crate rustc_session;
15
16
16
- use std:: env;
17
+ use std:: env:: { self , VarError } ;
17
18
use std:: num:: NonZeroU64 ;
18
19
use std:: path:: PathBuf ;
19
20
use std:: str:: FromStr ;
@@ -183,44 +184,52 @@ macro_rules! show_error {
183
184
( $( $tt: tt) * ) => { show_error( & format_args!( $( $tt) * ) ) } ;
184
185
}
185
186
187
+ fn rustc_logger_config ( ) -> rustc_log:: LoggerConfig {
188
+ // Start with the usual env vars.
189
+ let mut cfg = rustc_log:: LoggerConfig :: from_env ( "RUSTC_LOG" ) ;
190
+ // Enable verbose entry/exit logging by default if MIRI_LOG is set.
191
+ if env:: var_os ( "MIRI_LOG" ) . is_some ( )
192
+ && matches ! ( cfg. verbose_entry_exit, Err ( VarError :: NotPresent ) )
193
+ {
194
+ cfg. verbose_entry_exit = Ok ( format ! ( "1" ) ) ;
195
+ }
196
+
197
+ cfg
198
+ }
199
+
186
200
fn init_early_loggers ( handler : & EarlyErrorHandler ) {
187
201
// Note that our `extern crate log` is *not* the same as rustc's; as a result, we have to
188
202
// initialize them both, and we always initialize `miri`'s first.
189
203
let env = env_logger:: Env :: new ( ) . filter ( "MIRI_LOG" ) . write_style ( "MIRI_LOG_STYLE" ) ;
190
204
env_logger:: init_from_env ( env) ;
191
- // Enable verbose entry/exit logging by default if MIRI_LOG is set.
192
- if env:: var_os ( "MIRI_LOG" ) . is_some ( ) && env:: var_os ( "RUSTC_LOG_ENTRY_EXIT" ) . is_none ( ) {
193
- env:: set_var ( "RUSTC_LOG_ENTRY_EXIT" , "1" ) ;
194
- }
195
- // We only initialize `rustc` if the env var is set (so the user asked for it).
196
- // If it is not set, we avoid initializing now so that we can initialize
197
- // later with our custom settings, and *not* log anything for what happens before
198
- // `miri` gets started.
205
+ // Now for rustc. We only initialize `rustc` if the env var is set (so the user asked for it).
206
+ // If it is not set, we avoid initializing now so that we can initialize later with our custom
207
+ // settings, and *not* log anything for what happens before `miri` gets started.
199
208
if env:: var_os ( "RUSTC_LOG" ) . is_some ( ) {
200
- rustc_driver:: init_rustc_env_logger ( handler) ;
209
+ rustc_driver:: init_logger ( handler, rustc_logger_config ( ) ) ;
201
210
}
202
211
}
203
212
204
213
fn init_late_loggers ( handler : & EarlyErrorHandler , tcx : TyCtxt < ' _ > ) {
205
- // We initialize loggers right before we start evaluation. We overwrite the `RUSTC_LOG`
206
- // env var if it is not set, control it based on `MIRI_LOG`.
207
- // (FIXME: use `var_os`, but then we need to manually concatenate instead of `format!`.)
208
- if let Ok ( var) = env:: var ( "MIRI_LOG" ) {
209
- if env:: var_os ( "RUSTC_LOG" ) . is_none ( ) {
214
+ // If `RUSTC_LOG` is not set, then `init_early_loggers` did not call
215
+ // `rustc_driver::init_logger`, so we have to do this now.
216
+ if env:: var_os ( "RUSTC_LOG" ) . is_none ( ) {
217
+ let mut cfg = rustc_logger_config ( ) ;
218
+ if let Ok ( var) = env:: var ( "MIRI_LOG" ) {
219
+ // Setup rustc logging of the Miri-relevant components.
210
220
// We try to be a bit clever here: if `MIRI_LOG` is just a single level
211
221
// used for everything, we only apply it to the parts of rustc that are
212
222
// CTFE-related. Otherwise, we use it verbatim for `RUSTC_LOG`.
213
223
// This way, if you set `MIRI_LOG=trace`, you get only the right parts of
214
224
// rustc traced, but you can also do `MIRI_LOG=miri=trace,rustc_const_eval::interpret=debug`.
215
225
if log:: Level :: from_str ( & var) . is_ok ( ) {
216
- env:: set_var (
217
- "RUSTC_LOG" ,
218
- format ! ( "rustc_middle::mir::interpret={var},rustc_const_eval::interpret={var}" ) ,
219
- ) ;
226
+ cfg. filter = Ok ( format ! (
227
+ "rustc_middle::mir::interpret={var},rustc_const_eval::interpret={var}"
228
+ ) ) ;
220
229
} else {
221
- env :: set_var ( "RUSTC_LOG" , & var) ;
230
+ cfg . filter = Ok ( var) ;
222
231
}
223
- rustc_driver:: init_rustc_env_logger ( handler) ;
232
+ rustc_driver:: init_logger ( handler, cfg ) ;
224
233
}
225
234
}
226
235
0 commit comments