Skip to content

Commit 70eac07

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

File tree

5 files changed

+44
-39
lines changed

5 files changed

+44
-39
lines changed

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

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::ffi::{OsStr, OsString};
88
use std::path::{Path, PathBuf};
99
use std::{env, fs, iter};
1010

11+
use build_helper::compiletest::Mode as CtMode;
1112
use clap_complete::shells;
1213

1314
use crate::core::build_steps::compile::run_cargo;
@@ -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,20 @@ 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 {
1454+
path: "tests/assembly",
1455+
mode: CtMode::Assembly,
1456+
suite: "assembly",
1457+
default: true
1458+
});
14531459

14541460
/// Runs the coverage test suite at `tests/coverage` in some or all of the
14551461
/// coverage test modes.
@@ -1536,7 +1542,7 @@ impl Step for Coverage {
15361542
builder.ensure(Compiletest {
15371543
compiler,
15381544
target,
1539-
mode,
1545+
mode: mode.parse().unwrap(),
15401546
suite: Self::SUITE,
15411547
path: Self::PATH,
15421548
compare_mode: None,
@@ -1546,7 +1552,7 @@ impl Step for Coverage {
15461552

15471553
test!(CoverageRunRustdoc {
15481554
path: "tests/coverage-run-rustdoc",
1549-
mode: "coverage-run",
1555+
mode: CtMode::CoverageRun,
15501556
suite: "coverage-run-rustdoc",
15511557
default: true,
15521558
only_hosts: true,
@@ -1578,7 +1584,7 @@ impl Step for MirOpt {
15781584
builder.ensure(Compiletest {
15791585
compiler: self.compiler,
15801586
target,
1581-
mode: "mir-opt",
1587+
mode: CtMode::MirOpt,
15821588
suite: "mir-opt",
15831589
path: "tests/mir-opt",
15841590
compare_mode: None,
@@ -1615,7 +1621,7 @@ impl Step for MirOpt {
16151621
struct Compiletest {
16161622
compiler: Compiler,
16171623
target: TargetSelection,
1618-
mode: &'static str,
1624+
mode: CtMode,
16191625
suite: &'static str,
16201626
path: &'static str,
16211627
compare_mode: Option<&'static str>,
@@ -1729,7 +1735,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17291735

17301736
let is_rustdoc = suite == "rustdoc-ui" || suite == "rustdoc-js";
17311737

1732-
if mode == "run-make" {
1738+
if mode == CtMode::RunMake {
17331739
let cargo_path = if builder.top_stage == 0 {
17341740
// If we're using `--stage 0`, we should provide the bootstrap cargo.
17351741
builder.initial_cargo.clone()
@@ -1752,17 +1758,17 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17521758
}
17531759

17541760
// 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"
1761+
if mode == CtMode::Rustdoc
1762+
|| mode == CtMode::RunMake
1763+
|| (mode == CtMode::Ui && is_rustdoc)
1764+
|| mode == CtMode::RustdocJs
1765+
|| mode == CtMode::RustdocJson
17601766
|| suite == "coverage-run-rustdoc"
17611767
{
17621768
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
17631769
}
17641770

1765-
if mode == "rustdoc-json" {
1771+
if mode == CtMode::RustdocJson {
17661772
// Use the beta compiler for jsondocck
17671773
let json_compiler = compiler.with_stage(0);
17681774
cmd.arg("--jsondocck-path")
@@ -1771,7 +1777,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17711777
.arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
17721778
}
17731779

1774-
if matches!(mode, "coverage-map" | "coverage-run") {
1780+
if matches!(mode, CtMode::CoverageMap | CtMode::CoverageRun) {
17751781
let coverage_dump = builder.tool_exe(Tool::CoverageDump);
17761782
cmd.arg("--coverage-dump-path").arg(coverage_dump);
17771783
}
@@ -1789,7 +1795,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17891795
cmd.arg("--sysroot-base").arg(sysroot);
17901796
cmd.arg("--stage-id").arg(stage_id);
17911797
cmd.arg("--suite").arg(suite);
1792-
cmd.arg("--mode").arg(mode);
1798+
cmd.arg("--mode").arg(mode.to_str());
17931799
cmd.arg("--target").arg(target.rustc_target_arg());
17941800
cmd.arg("--host").arg(&*compiler.host.triple);
17951801
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
@@ -1827,7 +1833,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18271833

18281834
if let Some(ref nodejs) = builder.config.nodejs {
18291835
cmd.arg("--nodejs").arg(nodejs);
1830-
} else if mode == "rustdoc-js" {
1836+
} else if mode == CtMode::RustdocJs {
18311837
panic!("need nodejs to run rustdoc-js suite");
18321838
}
18331839
if let Some(ref npm) = builder.config.npm {
@@ -1985,7 +1991,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19851991
cmd.env("RUSTFLAGS", rustflags);
19861992
}
19871993

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

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

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

src/build_helper/src/compiletest.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Types representing arguments to compiletest.
22
3-
use std::str::FromStr;
43
use std::fmt;
4+
use std::str::FromStr;
5+
56
pub use self::Mode::*;
67

78
macro_rules! string_enum {
@@ -46,7 +47,7 @@ macro_rules! string_enum {
4647
pub(crate) use string_enum;
4748

4849
string_enum! {
49-
#[derive(Clone, Copy, PartialEq, Debug)]
50+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
5051
pub enum Mode {
5152
Pretty => "pretty",
5253
DebugInfo => "debuginfo",

src/build_helper/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! Types and functions shared across tools in this workspace.
22
33
pub mod ci;
4+
pub mod compiletest;
45
pub mod drop_bomb;
56
pub mod fs;
67
pub mod git;
78
pub mod metrics;
89
pub mod stage0_parser;
9-
pub mod util;
10-
pub mod compiletest;
1110
#[cfg(test)]
1211
mod tests;
12+
pub mod util;
1313

1414
/// The default set of crates for opt-dist to collect LLVM profiles.
1515
pub const LLVM_PGO_CRATES: &[&str] = &[

src/tools/compiletest/src/common.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
use std::collections::{BTreeSet, HashMap, HashSet};
22
use std::ffi::OsString;
3+
use std::iter;
34
use std::path::{Path, PathBuf};
45
use std::process::Command;
56
use std::sync::OnceLock;
6-
use std::iter;
77

8+
pub use build_helper::compiletest::*;
89
use build_helper::git::GitConfig;
910
use semver::Version;
1011
use serde::de::{Deserialize, Deserializer, Error as _};
1112
use test::{ColorConfig, OutputFormat};
1213

1314
use crate::util::{PathBufExt, add_dylib_path};
14-
pub use build_helper::compiletest::*;
15-
1615

1716
#[derive(Clone, Copy, Debug, PartialEq, Default, serde::Deserialize)]
1817
#[serde(rename_all = "kebab-case")]

src/tools/compiletest/src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,3 @@ fn is_test_test() {
6666
assert!(!is_test(&OsString::from("#a_dog_gif")));
6767
assert!(!is_test(&OsString::from("~a_temp_file")));
6868
}
69-

0 commit comments

Comments
 (0)