Skip to content

Commit

Permalink
Rollup merge of #109810 - jyn514:rustdoc-opt-tests, r=TaKO8Ki
Browse files Browse the repository at this point in the history
Replace rustdoc-ui/{c,z}-help tests with a stable run-make test

This make rustdoc resilient to changes in the debugging options while still testing that it matches rustc.

Fixes #109391.
  • Loading branch information
matthiaskrgr authored Apr 12, 2023
2 parents 59a05ad + 67b3919 commit 559b2ea
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 325 deletions.
76 changes: 43 additions & 33 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use rustc_metadata::locator;
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths};
use rustc_session::cstore::MetadataLoader;
use rustc_session::getopts;
use rustc_session::getopts::{self, Matches};
use rustc_session::lint::{Lint, LintId};
use rustc_session::{config, Session};
use rustc_session::{early_error, early_error_no_abort, early_warn};
Expand Down Expand Up @@ -956,6 +956,46 @@ Available lint options:
}
}

/// Show help for flag categories shared between rustdoc and rustc.
///
/// Returns whether a help option was printed.
pub fn describe_flag_categories(matches: &Matches) -> bool {
// Handle the special case of -Wall.
let wall = matches.opt_strs("W");
if wall.iter().any(|x| *x == "all") {
print_wall_help();
rustc_errors::FatalError.raise();
}

// Don't handle -W help here, because we might first load plugins.
let debug_flags = matches.opt_strs("Z");
if debug_flags.iter().any(|x| *x == "help") {
describe_debug_flags();
return true;
}

let cg_flags = matches.opt_strs("C");
if cg_flags.iter().any(|x| *x == "help") {
describe_codegen_flags();
return true;
}

if cg_flags.iter().any(|x| *x == "no-stack-check") {
early_warn(
ErrorOutputType::default(),
"the --no-stack-check flag is deprecated and does nothing",
);
}

if cg_flags.iter().any(|x| *x == "passes=list") {
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
get_codegen_backend(&None, backend_name).print_passes();
return true;
}

false
}

fn describe_debug_flags() {
println!("\nAvailable options:\n");
print_flag_list("-Z", config::Z_OPTIONS);
Expand All @@ -966,7 +1006,7 @@ fn describe_codegen_flags() {
print_flag_list("-C", config::CG_OPTIONS);
}

pub fn print_flag_list<T>(
fn print_flag_list<T>(
cmdline_opt: &str,
flag_list: &[(&'static str, T, &'static str, &'static str)],
) {
Expand Down Expand Up @@ -1059,37 +1099,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
return None;
}

// Handle the special case of -Wall.
let wall = matches.opt_strs("W");
if wall.iter().any(|x| *x == "all") {
print_wall_help();
rustc_errors::FatalError.raise();
}

// Don't handle -W help here, because we might first load plugins.
let debug_flags = matches.opt_strs("Z");
if debug_flags.iter().any(|x| *x == "help") {
describe_debug_flags();
return None;
}

let cg_flags = matches.opt_strs("C");

if cg_flags.iter().any(|x| *x == "help") {
describe_codegen_flags();
return None;
}

if cg_flags.iter().any(|x| *x == "no-stack-check") {
early_warn(
ErrorOutputType::default(),
"the --no-stack-check flag is deprecated and does nothing",
);
}

if cg_flags.iter().any(|x| *x == "passes=list") {
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
get_codegen_backend(&None, backend_name).print_passes();
if describe_flag_categories(&matches) {
return None;
}

Expand Down
10 changes: 1 addition & 9 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::path::PathBuf;
use std::str::FromStr;

use rustc_data_structures::fx::FxHashMap;
use rustc_driver::print_flag_list;
use rustc_session::config::{
self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType,
};
Expand Down Expand Up @@ -328,14 +327,7 @@ impl Options {
return Err(0);
}

let z_flags = matches.opt_strs("Z");
if z_flags.iter().any(|x| *x == "help") {
print_flag_list("-Z", config::Z_OPTIONS);
return Err(0);
}
let c_flags = matches.opt_strs("C");
if c_flags.iter().any(|x| *x == "help") {
print_flag_list("-C", config::CG_OPTIONS);
if rustc_driver::describe_flag_categories(&matches) {
return Err(0);
}

Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ fn run_test(
compiler.stdin(Stdio::piped());
compiler.stderr(Stdio::piped());

debug!("compiler invocation for doctest: {:?}", compiler);

let mut child = compiler.spawn().expect("Failed to spawn rustc process");
{
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
Expand Down
18 changes: 18 additions & 0 deletions tests/run-make/rustdoc-shared-flags/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include ../tools.mk

all: z_help c_help list_passes

c_help:
$(RUSTC) -C help > $(TMPDIR)/rustc.c_help.txt
$(RUSTDOC) -C help > $(TMPDIR)/rustdoc.c_help.txt
$(DIFF) $(TMPDIR)/rustc.c_help.txt $(TMPDIR)/rustdoc.c_help.txt

z_help:
$(RUSTC) -Z help > $(TMPDIR)/rustc.z_help.txt
$(RUSTDOC) -Z help > $(TMPDIR)/rustdoc.z_help.txt
$(DIFF) $(TMPDIR)/rustc.z_help.txt $(TMPDIR)/rustdoc.z_help.txt

list_passes:
$(RUSTC) -C passes=list > $(TMPDIR)/rustc.passes.txt
$(RUSTDOC) -C passes=list > $(TMPDIR)/rustdoc.passes.txt
$(DIFF) $(TMPDIR)/rustc.passes.txt $(TMPDIR)/rustdoc.passes.txt
6 changes: 0 additions & 6 deletions tests/rustdoc-ui/c-help.rs

This file was deleted.

51 changes: 0 additions & 51 deletions tests/rustdoc-ui/c-help.stdout

This file was deleted.

6 changes: 0 additions & 6 deletions tests/rustdoc-ui/z-help.rs

This file was deleted.

Loading

0 comments on commit 559b2ea

Please sign in to comment.