From bdb6e5ca1e391081248d22ad38207f4df4af8e61 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 4 Mar 2021 09:48:03 -0500 Subject: [PATCH] Tell cargo to track logging environment variables Previously, changing the value of `RUSTC_LOG` would not rebuild, and, because cargo caches output, show exactly the same logging as before. This was confusing. Emit `RUSTC_LOG` with other `depinfo` dependencies so cargo knows to rebuild when it's changed. Note that this only adds RUSTC_LOG to depinfo. Unfortunately, adding RUSTDOC_LOG only when running as rustdoc doesn't help because rustdoc doesn't emit depinfo at all. Unconditionally emitting RUSTDOC_LOG in the depinfo doesn't help because cargo ignores it for everything except rustc itself. I am not yet sure how to fix this; see https://github.com/rust-lang/cargo/issues/8374 for more info. --- compiler/rustc_session/src/session.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 493bbb3a76201..5f8429f00212b 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1350,11 +1350,16 @@ pub fn build_session( let mut parse_sess = ParseSess::with_span_handler(span_diagnostic, source_map); parse_sess.assume_incomplete_release = sopts.debugging_opts.assume_incomplete_release; + let dep_info = parse_sess.env_depinfo.get_mut(); + for log_var in &["RUSTC_LOG", "RUSTC_LOG_COLOR"] { + let val = std::env::var(log_var).as_deref().ok().map(Symbol::intern); + dep_info.insert((Symbol::intern(log_var), val)); + } + let sysroot = match &sopts.maybe_sysroot { Some(sysroot) => sysroot.clone(), None => filesearch::get_or_default_sysroot(), }; - let host_triple = config::host_triple(); let target_triple = sopts.target_triple.triple(); let host_tlib_path = SearchPath::from_sysroot_and_triple(&sysroot, host_triple);