Skip to content

Commit 5e629be

Browse files
committed
Add CompilerKind to distinguish between rustc and rustdoc
1 parent ebf13cc commit 5e629be

File tree

3 files changed

+59
-18
lines changed

3 files changed

+59
-18
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ enum Emit {
255255
LinkArgsAsm,
256256
}
257257

258+
/// Indicates whether we are using `rustc` or `rustdoc` to compile an input file.
259+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
260+
enum CompilerKind {
261+
Rustc,
262+
Rustdoc,
263+
}
264+
258265
impl<'test> TestCx<'test> {
259266
/// Code executed for each revision in turn (or, if there are no
260267
/// revisions, exactly once, with revision == None).
@@ -958,6 +965,8 @@ impl<'test> TestCx<'test> {
958965
local_pm: Option<PassMode>,
959966
passes: Vec<String>,
960967
) -> ProcRes {
968+
let compiler_kind = self.compiler_kind_for_non_aux();
969+
961970
// Only use `make_exe_name` when the test ends up being executed.
962971
let output_file = match will_execute {
963972
WillExecute::Yes => TargetLocation::ThisFile(self.make_exe_name()),
@@ -973,7 +982,7 @@ impl<'test> TestCx<'test> {
973982
// want to actually assert warnings about all this code. Instead
974983
// let's just ignore unused code warnings by defaults and tests
975984
// can turn it back on if needed.
976-
if !self.is_rustdoc()
985+
if compiler_kind == CompilerKind::Rustc
977986
// Note that we use the local pass mode here as we don't want
978987
// to set unused to allow if we've overridden the pass mode
979988
// via command line flags.
@@ -988,6 +997,7 @@ impl<'test> TestCx<'test> {
988997
};
989998

990999
let rustc = self.make_compile_args(
1000+
compiler_kind,
9911001
&self.testpaths.file,
9921002
output_file,
9931003
emit,
@@ -1347,6 +1357,7 @@ impl<'test> TestCx<'test> {
13471357
fn build_minicore(&self) -> Utf8PathBuf {
13481358
let output_file_path = self.output_base_dir().join("libminicore.rlib");
13491359
let mut rustc = self.make_compile_args(
1360+
CompilerKind::Rustc,
13501361
&self.config.minicore_path,
13511362
TargetLocation::ThisFile(output_file_path.clone()),
13521363
Emit::None,
@@ -1404,6 +1415,8 @@ impl<'test> TestCx<'test> {
14041415
// Create the directory for the stdout/stderr files.
14051416
create_dir_all(aux_cx.output_base_dir()).unwrap();
14061417
let mut aux_rustc = aux_cx.make_compile_args(
1418+
// Always use `rustc` for aux crates, even in rustdoc tests.
1419+
CompilerKind::Rustc,
14071420
&aux_path,
14081421
aux_output,
14091422
Emit::None,
@@ -1554,28 +1567,54 @@ impl<'test> TestCx<'test> {
15541567
result
15551568
}
15561569

1557-
fn is_rustdoc(&self) -> bool {
1558-
matches!(
1559-
self.config.suite,
1560-
TestSuite::RustdocUi | TestSuite::RustdocJs | TestSuite::RustdocJson
1561-
)
1570+
/// Choose a compiler kind (rustc or rustdoc) for compiling test files,
1571+
/// based on the test suite being tested.
1572+
fn compiler_kind_for_non_aux(&self) -> CompilerKind {
1573+
match self.config.suite {
1574+
TestSuite::RustdocJs | TestSuite::RustdocJson | TestSuite::RustdocUi => {
1575+
CompilerKind::Rustdoc
1576+
}
1577+
1578+
// Exhaustively match all other suites.
1579+
// Note that some suites never actually use this method, so the
1580+
// return value for those suites is not necessarily meaningful.
1581+
TestSuite::AssemblyLlvm
1582+
| TestSuite::BuildStd
1583+
| TestSuite::CodegenLlvm
1584+
| TestSuite::CodegenUnits
1585+
| TestSuite::Coverage
1586+
| TestSuite::CoverageRunRustdoc
1587+
| TestSuite::Crashes
1588+
| TestSuite::Debuginfo
1589+
| TestSuite::Incremental
1590+
| TestSuite::MirOpt
1591+
| TestSuite::Pretty
1592+
| TestSuite::RunMake
1593+
| TestSuite::RunMakeCargo
1594+
| TestSuite::RustdocGui
1595+
| TestSuite::RustdocHtml
1596+
| TestSuite::RustdocJsStd
1597+
| TestSuite::Ui
1598+
| TestSuite::UiFullDeps => CompilerKind::Rustc,
1599+
}
15621600
}
15631601

15641602
fn make_compile_args(
15651603
&self,
1604+
compiler_kind: CompilerKind,
15661605
input_file: &Utf8Path,
15671606
output_file: TargetLocation,
15681607
emit: Emit,
15691608
allow_unused: AllowUnused,
15701609
link_to_aux: LinkToAux,
15711610
passes: Vec<String>, // Vec of passes under mir-opt test to be dumped
15721611
) -> Command {
1573-
let is_aux = input_file.components().map(|c| c.as_os_str()).any(|c| c == "auxiliary");
1574-
let is_rustdoc = self.is_rustdoc() && !is_aux;
1575-
let mut rustc = if !is_rustdoc {
1576-
Command::new(&self.config.rustc_path)
1577-
} else {
1578-
Command::new(&self.config.rustdoc_path.clone().expect("no rustdoc built yet"))
1612+
let is_rustdoc = compiler_kind == CompilerKind::Rustdoc;
1613+
let mut rustc = match compiler_kind {
1614+
CompilerKind::Rustc => Command::new(&self.config.rustc_path),
1615+
CompilerKind::Rustdoc => {
1616+
Command::new(&self.config.rustdoc_path.clone().expect("no rustdoc built yet"))
1617+
}
15791618
};
15801619
rustc.arg(input_file);
15811620

@@ -2127,6 +2166,7 @@ impl<'test> TestCx<'test> {
21272166
let output_path = self.output_base_name().with_extension("ll");
21282167
let input_file = &self.testpaths.file;
21292168
let rustc = self.make_compile_args(
2169+
CompilerKind::Rustc,
21302170
input_file,
21312171
TargetLocation::ThisFile(output_path.clone()),
21322172
Emit::LlvmIr,

src/tools/compiletest/src/runtest/assembly.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use camino::Utf8PathBuf;
22

3-
use super::{AllowUnused, Emit, LinkToAux, ProcRes, TargetLocation, TestCx};
3+
use crate::runtest::{AllowUnused, CompilerKind, Emit, LinkToAux, ProcRes, TargetLocation, TestCx};
44

55
impl TestCx<'_> {
66
pub(super) fn run_assembly_test(&self) {
@@ -35,6 +35,7 @@ impl TestCx<'_> {
3535
};
3636

3737
let rustc = self.make_compile_args(
38+
CompilerKind::Rustc,
3839
input_file,
3940
TargetLocation::ThisFile(output_path.clone()),
4041
emit,

src/tools/compiletest/src/runtest/ui.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use std::io::Write;
55
use rustfix::{Filter, apply_suggestions, get_suggestions_from_json};
66
use tracing::debug;
77

8-
use super::{
9-
AllowUnused, Emit, FailMode, LinkToAux, PassMode, RunFailMode, RunResult, TargetLocation,
10-
TestCx, TestOutput, Truncated, UI_FIXED, WillExecute,
11-
};
128
use crate::json;
13-
use crate::runtest::ProcRes;
9+
use crate::runtest::{
10+
AllowUnused, Emit, FailMode, LinkToAux, PassMode, ProcRes, RunFailMode, RunResult,
11+
TargetLocation, TestCx, TestOutput, Truncated, UI_FIXED, WillExecute,
12+
};
1413

1514
impl TestCx<'_> {
1615
pub(super) fn run_ui_test(&self) {
@@ -228,6 +227,7 @@ impl TestCx<'_> {
228227
// And finally, compile the fixed code and make sure it both
229228
// succeeds and has no diagnostics.
230229
let mut rustc = self.make_compile_args(
230+
self.compiler_kind_for_non_aux(),
231231
&self.expected_output_path(UI_FIXED),
232232
TargetLocation::ThisFile(self.make_exe_name()),
233233
emit_metadata,

0 commit comments

Comments
 (0)