Skip to content

Commit 2272421

Browse files
committed
bootstrap now uses enum for compiletest modes
1 parent 6250d77 commit 2272421

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
99
use std::{env, fs, iter};
1010

1111
use clap_complete::shells;
12+
use build_helper::compiletest::Mode as CtMode;
1213

1314
use crate::core::build_steps::compile::run_cargo;
1415
use crate::core::build_steps::doc::DocumentationFormat;
@@ -915,7 +916,7 @@ impl Step for RustdocJSNotStd {
915916
builder.ensure(Compiletest {
916917
compiler: self.compiler,
917918
target: self.target,
918-
mode: "rustdoc-js",
919+
mode: CtMode::RustdocJs,
919920
suite: "rustdoc-js",
920921
path: "tests/rustdoc-js",
921922
compare_mode: None,
@@ -1347,68 +1348,68 @@ impl Step for CrateBuildHelper {
13471348
}
13481349
}
13491350

1350-
test!(Ui { path: "tests/ui", mode: "ui", suite: "ui", default: true });
1351+
test!(Ui { path: "tests/ui", mode: CtMode::Ui, suite: "ui", default: true });
13511352

1352-
test!(Crashes { path: "tests/crashes", mode: "crashes", suite: "crashes", default: true });
1353+
test!(Crashes { path: "tests/crashes", mode: CtMode::Crashes, suite: "crashes", default: true });
13531354

1354-
test!(Codegen { path: "tests/codegen", mode: "codegen", suite: "codegen", default: true });
1355+
test!(Codegen { path: "tests/codegen", mode: CtMode::Codegen, suite: "codegen", default: true });
13551356

13561357
test!(CodegenUnits {
13571358
path: "tests/codegen-units",
1358-
mode: "codegen-units",
1359+
mode: CtMode::CodegenUnits,
13591360
suite: "codegen-units",
13601361
default: true,
13611362
});
13621363

13631364
test!(Incremental {
13641365
path: "tests/incremental",
1365-
mode: "incremental",
1366+
mode: CtMode::Incremental,
13661367
suite: "incremental",
13671368
default: true,
13681369
});
13691370

13701371
test!(Debuginfo {
13711372
path: "tests/debuginfo",
1372-
mode: "debuginfo",
1373+
mode: CtMode::DebugInfo,
13731374
suite: "debuginfo",
13741375
default: true,
13751376
compare_mode: Some("split-dwarf"),
13761377
});
13771378

13781379
test!(UiFullDeps {
13791380
path: "tests/ui-fulldeps",
1380-
mode: "ui",
1381+
mode: CtMode::Ui,
13811382
suite: "ui-fulldeps",
13821383
default: true,
13831384
only_hosts: true,
13841385
});
13851386

13861387
test!(Rustdoc {
13871388
path: "tests/rustdoc",
1388-
mode: "rustdoc",
1389+
mode: CtMode::Rustdoc,
13891390
suite: "rustdoc",
13901391
default: true,
13911392
only_hosts: true,
13921393
});
13931394
test!(RustdocUi {
13941395
path: "tests/rustdoc-ui",
1395-
mode: "ui",
1396+
mode: CtMode::Ui,
13961397
suite: "rustdoc-ui",
13971398
default: true,
13981399
only_hosts: true,
13991400
});
14001401

14011402
test!(RustdocJson {
14021403
path: "tests/rustdoc-json",
1403-
mode: "rustdoc-json",
1404+
mode: CtMode::RustdocJson,
14041405
suite: "rustdoc-json",
14051406
default: true,
14061407
only_hosts: true,
14071408
});
14081409

14091410
test!(Pretty {
14101411
path: "tests/pretty",
1411-
mode: "pretty",
1412+
mode: CtMode::Pretty,
14121413
suite: "pretty",
14131414
default: true,
14141415
only_hosts: true,
@@ -1441,15 +1442,15 @@ impl Step for RunMake {
14411442
builder.ensure(Compiletest {
14421443
compiler: self.compiler,
14431444
target: self.target,
1444-
mode: "run-make",
1445+
mode: CtMode::RunMake,
14451446
suite: "run-make",
14461447
path: "tests/run-make",
14471448
compare_mode: None,
14481449
});
14491450
}
14501451
}
14511452

1452-
test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly", default: true });
1453+
test!(Assembly { path: "tests/assembly", mode: CtMode::Assembly, suite: "assembly", default: true });
14531454

14541455
/// Runs the coverage test suite at `tests/coverage` in some or all of the
14551456
/// coverage test modes.
@@ -1536,7 +1537,7 @@ impl Step for Coverage {
15361537
builder.ensure(Compiletest {
15371538
compiler,
15381539
target,
1539-
mode,
1540+
mode: mode.parse().unwrap(),
15401541
suite: Self::SUITE,
15411542
path: Self::PATH,
15421543
compare_mode: None,
@@ -1546,7 +1547,7 @@ impl Step for Coverage {
15461547

15471548
test!(CoverageRunRustdoc {
15481549
path: "tests/coverage-run-rustdoc",
1549-
mode: "coverage-run",
1550+
mode: CtMode::CoverageRun,
15501551
suite: "coverage-run-rustdoc",
15511552
default: true,
15521553
only_hosts: true,
@@ -1578,7 +1579,7 @@ impl Step for MirOpt {
15781579
builder.ensure(Compiletest {
15791580
compiler: self.compiler,
15801581
target,
1581-
mode: "mir-opt",
1582+
mode: CtMode::MirOpt,
15821583
suite: "mir-opt",
15831584
path: "tests/mir-opt",
15841585
compare_mode: None,
@@ -1615,7 +1616,7 @@ impl Step for MirOpt {
16151616
struct Compiletest {
16161617
compiler: Compiler,
16171618
target: TargetSelection,
1618-
mode: &'static str,
1619+
mode: CtMode,
16191620
suite: &'static str,
16201621
path: &'static str,
16211622
compare_mode: Option<&'static str>,
@@ -1729,7 +1730,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17291730

17301731
let is_rustdoc = suite == "rustdoc-ui" || suite == "rustdoc-js";
17311732

1732-
if mode == "run-make" {
1733+
if mode == CtMode::RunMake {
17331734
let cargo_path = if builder.top_stage == 0 {
17341735
// If we're using `--stage 0`, we should provide the bootstrap cargo.
17351736
builder.initial_cargo.clone()
@@ -1752,17 +1753,17 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17521753
}
17531754

17541755
// Avoid depending on rustdoc when we don't need it.
1755-
if mode == "rustdoc"
1756-
|| mode == "run-make"
1757-
|| (mode == "ui" && is_rustdoc)
1758-
|| mode == "rustdoc-js"
1759-
|| mode == "rustdoc-json"
1756+
if mode == CtMode::Rustdoc
1757+
|| mode == CtMode::RunMake
1758+
|| (mode == CtMode::Ui && is_rustdoc)
1759+
|| mode == CtMode::RustdocJs
1760+
|| mode == CtMode::RustdocJson
17601761
|| suite == "coverage-run-rustdoc"
17611762
{
17621763
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
17631764
}
17641765

1765-
if mode == "rustdoc-json" {
1766+
if mode == CtMode::RustdocJson {
17661767
// Use the beta compiler for jsondocck
17671768
let json_compiler = compiler.with_stage(0);
17681769
cmd.arg("--jsondocck-path")
@@ -1771,7 +1772,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17711772
.arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
17721773
}
17731774

1774-
if matches!(mode, "coverage-map" | "coverage-run") {
1775+
if matches!(mode, CtMode::CoverageMap | CtMode::CoverageRun) {
17751776
let coverage_dump = builder.tool_exe(Tool::CoverageDump);
17761777
cmd.arg("--coverage-dump-path").arg(coverage_dump);
17771778
}
@@ -1789,7 +1790,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17891790
cmd.arg("--sysroot-base").arg(sysroot);
17901791
cmd.arg("--stage-id").arg(stage_id);
17911792
cmd.arg("--suite").arg(suite);
1792-
cmd.arg("--mode").arg(mode);
1793+
cmd.arg("--mode").arg(mode.to_str());
17931794
cmd.arg("--target").arg(target.rustc_target_arg());
17941795
cmd.arg("--host").arg(&*compiler.host.triple);
17951796
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
@@ -1827,7 +1828,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18271828

18281829
if let Some(ref nodejs) = builder.config.nodejs {
18291830
cmd.arg("--nodejs").arg(nodejs);
1830-
} else if mode == "rustdoc-js" {
1831+
} else if mode == CtMode::RustdocJs {
18311832
panic!("need nodejs to run rustdoc-js suite");
18321833
}
18331834
if let Some(ref npm) = builder.config.npm {
@@ -1985,7 +1986,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19851986
cmd.env("RUSTFLAGS", rustflags);
19861987
}
19871988

1988-
if !builder.config.dry_run() && matches!(mode, "run-make" | "coverage-run") {
1989+
if !builder.config.dry_run() && matches!(mode, CtMode::RunMake | CtMode::CoverageRun) {
19891990
// The llvm/bin directory contains many useful cross-platform
19901991
// tools. Pass the path to run-make tests so they can use them.
19911992
// (The coverage-run tests also need these tools to process
@@ -1997,7 +1998,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19971998
cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
19981999
}
19992000

2000-
if !builder.config.dry_run() && mode == "run-make" {
2001+
if !builder.config.dry_run() && mode == CtMode::RunMake {
20012002
// If LLD is available, add it to the PATH
20022003
if builder.config.lld_enabled {
20032004
let lld_install_root =
@@ -2017,7 +2018,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
20172018

20182019
// Only pass correct values for these flags for the `run-make` suite as it
20192020
// requires that a C++ compiler was configured which isn't always the case.
2020-
if !builder.config.dry_run() && mode == "run-make" {
2021+
if !builder.config.dry_run() && mode == CtMode::RunMake {
20212022
cmd.arg("--cc")
20222023
.arg(builder.cc(target))
20232024
.arg("--cxx")

src/build_helper/src/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ macro_rules! string_enum {
4646
pub(crate) use string_enum;
4747

4848
string_enum! {
49-
#[derive(Clone, Copy, PartialEq, Debug)]
49+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
5050
pub enum Mode {
5151
Pretty => "pretty",
5252
DebugInfo => "debuginfo",

0 commit comments

Comments
 (0)