Skip to content

Commit 22ebb86

Browse files
Rollup merge of rust-lang#81932 - jyn514:rustdoc-logging, r=Mark-Simulacrum
Always compile rustdoc with debug logging enabled when `download-rustc` is set Previously, logging at DEBUG or below would always be silenced, because rustc compiles tracing with the `static_max_level_info` feature. That makes sense for release artifacts, but not for developing rustdoc. Instead, this compiles two different versions of tracing: one in the release artifacts, distributed in the sysroot, and a new version compiled by rustdoc. Since `rustc_driver` is always linked to the version of sysroot, this copy/pastes `init_env_logging` into rustdoc. To avoid compiling an unnecessary version of tracing when `download-rustc` isn't set, this adds a new `using-ci-artifacts` feature for rustdoc and passes that feature in bootstrap. Addresses rust-lang#81930. This builds on rust-lang#79540. r? `@Mark-Simulacrum`
2 parents 865cf0c + 6dc9934 commit 22ebb86

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -4554,6 +4554,9 @@ dependencies = [
45544554
"serde_json",
45554555
"smallvec 1.6.1",
45564556
"tempfile",
4557+
"tracing",
4558+
"tracing-subscriber",
4559+
"tracing-tree",
45574560
]
45584561

45594562
[[package]]

src/librustdoc/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ tempfile = "3"
1919
itertools = "0.9"
2020
regex = "1"
2121
rustdoc-json-types = { path = "../rustdoc-json-types" }
22+
tracing = "0.1"
23+
tracing-tree = "0.1.6"
24+
25+
[dependencies.tracing-subscriber]
26+
version = "0.2.13"
27+
default-features = false
28+
features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"]
2229

2330
[dev-dependencies]
2431
expect-test = "1.0"

src/librustdoc/lib.rs

+74
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,88 @@ mod visit_lib;
9494
pub fn main() {
9595
rustc_driver::set_sigpipe_handler();
9696
rustc_driver::install_ice_hook();
97+
98+
// When using CI artifacts (with `download_stage1 = true`), tracing is unconditionally built
99+
// with `--features=static_max_level_info`, which disables almost all rustdoc logging. To avoid
100+
// this, compile our own version of `tracing` that logs all levels.
101+
// NOTE: this compiles both versions of tracing unconditionally, because
102+
// - The compile time hit is not that bad, especially compared to rustdoc's incremental times, and
103+
// - Otherwise, there's no warning that logging is being ignored when `download_stage1 = true`.
104+
// NOTE: The reason this doesn't show double logging when `download_stage1 = false` and
105+
// `debug_logging = true` is because all rustc logging goes to its version of tracing (the one
106+
// in the sysroot), and all of rustdoc's logging goes to its version (the one in Cargo.toml).
107+
init_logging();
97108
rustc_driver::init_env_logger("RUSTDOC_LOG");
109+
98110
let exit_code = rustc_driver::catch_with_exit_code(|| match get_args() {
99111
Some(args) => main_args(&args),
100112
_ => Err(ErrorReported),
101113
});
102114
process::exit(exit_code);
103115
}
104116

117+
fn init_logging() {
118+
use std::io;
119+
120+
// FIXME remove these and use winapi 0.3 instead
121+
// Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs, rustc_driver/lib.rs
122+
#[cfg(unix)]
123+
fn stdout_isatty() -> bool {
124+
extern crate libc;
125+
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
126+
}
127+
128+
#[cfg(windows)]
129+
fn stdout_isatty() -> bool {
130+
extern crate winapi;
131+
use winapi::um::consoleapi::GetConsoleMode;
132+
use winapi::um::processenv::GetStdHandle;
133+
use winapi::um::winbase::STD_OUTPUT_HANDLE;
134+
135+
unsafe {
136+
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
137+
let mut out = 0;
138+
GetConsoleMode(handle, &mut out) != 0
139+
}
140+
}
141+
142+
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR") {
143+
Ok(value) => match value.as_ref() {
144+
"always" => true,
145+
"never" => false,
146+
"auto" => stdout_isatty(),
147+
_ => early_error(
148+
ErrorOutputType::default(),
149+
&format!(
150+
"invalid log color value '{}': expected one of always, never, or auto",
151+
value
152+
),
153+
),
154+
},
155+
Err(std::env::VarError::NotPresent) => stdout_isatty(),
156+
Err(std::env::VarError::NotUnicode(_value)) => early_error(
157+
ErrorOutputType::default(),
158+
"non-Unicode log color value: expected one of always, never, or auto",
159+
),
160+
};
161+
let filter = tracing_subscriber::EnvFilter::from_env("RUSTDOC_LOG");
162+
let layer = tracing_tree::HierarchicalLayer::default()
163+
.with_writer(io::stderr)
164+
.with_indent_lines(true)
165+
.with_ansi(color_logs)
166+
.with_targets(true)
167+
.with_wraparound(10)
168+
.with_verbose_exit(true)
169+
.with_verbose_entry(true)
170+
.with_indent_amount(2);
171+
#[cfg(parallel_compiler)]
172+
let layer = layer.with_thread_ids(true).with_thread_names(true);
173+
174+
use tracing_subscriber::layer::SubscriberExt;
175+
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
176+
tracing::subscriber::set_global_default(subscriber).unwrap();
177+
}
178+
105179
fn get_args() -> Option<Vec<String>> {
106180
env::args_os()
107181
.enumerate()

src/test/rustdoc-ui/deprecated-attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// check-pass
22

3-
#![doc(no_default_passes, passes = "collapse-docs unindent-comments")]
3+
#![doc(no_default_passes, passes = "unindent-comments")]
44

55
struct SomeStruct;
66

0 commit comments

Comments
 (0)