@@ -17,6 +17,7 @@ use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
1717use crate :: core:: build_steps:: llvm:: get_llvm_version;
1818use crate :: core:: build_steps:: run:: { get_completion_paths, get_help_path} ;
1919use crate :: core:: build_steps:: synthetic_targets:: MirOptPanicAbortSyntheticTarget ;
20+ use crate :: core:: build_steps:: test:: compiletest:: CompiletestMode ;
2021use crate :: core:: build_steps:: tool:: {
2122 self , RustcPrivateCompilers , SourceType , TEST_FLOAT_PARSE_ALLOW_FEATURES , Tool ,
2223 ToolTargetBuildMode , get_tool_target_compiler,
@@ -39,6 +40,8 @@ use crate::utils::helpers::{
3940use crate :: utils:: render_tests:: { add_flags_and_try_run_tests, try_run_tests} ;
4041use crate :: { CLang , CodegenBackendKind , DocTests , GitRepo , Mode , PathSet , envify} ;
4142
43+ mod compiletest;
44+
4245/// Runs `cargo test` on various internal tools used by bootstrap.
4346#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
4447pub struct CrateBootstrap {
@@ -1085,7 +1088,7 @@ impl Step for RustdocJSNotStd {
10851088 builder. ensure ( Compiletest {
10861089 test_compiler : self . compiler ,
10871090 target : self . target ,
1088- mode : "rustdoc-js" ,
1091+ mode : CompiletestMode :: RustdocJs ,
10891092 suite : "rustdoc-js" ,
10901093 path : "tests/rustdoc-js" ,
10911094 compare_mode : None ,
@@ -1478,7 +1481,7 @@ macro_rules! test {
14781481 builder. ensure( Compiletest {
14791482 test_compiler: self . test_compiler,
14801483 target: self . target,
1481- mode: $mode,
1484+ mode: const { $mode } ,
14821485 suite: $suite,
14831486 path: $path,
14841487 compare_mode: ( const {
@@ -1493,89 +1496,99 @@ macro_rules! test {
14931496 } ;
14941497}
14951498
1496- test ! ( Ui { path: "tests/ui" , mode: "ui" , suite: "ui" , default : true } ) ;
1499+ test ! ( Ui { path: "tests/ui" , mode: CompiletestMode :: Ui , suite: "ui" , default : true } ) ;
14971500
1498- test ! ( Crashes { path: "tests/crashes" , mode: "crashes" , suite: "crashes" , default : true } ) ;
1501+ test ! ( Crashes {
1502+ path: "tests/crashes" ,
1503+ mode: CompiletestMode :: Crashes ,
1504+ suite: "crashes" ,
1505+ default : true ,
1506+ } ) ;
14991507
15001508test ! ( CodegenLlvm {
15011509 path: "tests/codegen-llvm" ,
1502- mode: "codegen" ,
1510+ mode: CompiletestMode :: Codegen ,
15031511 suite: "codegen-llvm" ,
15041512 default : true
15051513} ) ;
15061514
15071515test ! ( CodegenUnits {
15081516 path: "tests/codegen-units" ,
1509- mode: "codegen-units" ,
1517+ mode: CompiletestMode :: CodegenUnits ,
15101518 suite: "codegen-units" ,
15111519 default : true ,
15121520} ) ;
15131521
15141522test ! ( Incremental {
15151523 path: "tests/incremental" ,
1516- mode: "incremental" ,
1524+ mode: CompiletestMode :: Incremental ,
15171525 suite: "incremental" ,
15181526 default : true ,
15191527} ) ;
15201528
15211529test ! ( Debuginfo {
15221530 path: "tests/debuginfo" ,
1523- mode: "debuginfo" ,
1531+ mode: CompiletestMode :: Debuginfo ,
15241532 suite: "debuginfo" ,
15251533 default : true ,
15261534 compare_mode: Some ( "split-dwarf" ) ,
15271535} ) ;
15281536
15291537test ! ( UiFullDeps {
15301538 path: "tests/ui-fulldeps" ,
1531- mode: "ui" ,
1539+ mode: CompiletestMode :: Ui ,
15321540 suite: "ui-fulldeps" ,
15331541 default : true ,
15341542 IS_HOST : true ,
15351543} ) ;
15361544
15371545test ! ( Rustdoc {
15381546 path: "tests/rustdoc" ,
1539- mode: "rustdoc" ,
1547+ mode: CompiletestMode :: Rustdoc ,
15401548 suite: "rustdoc" ,
15411549 default : true ,
15421550 IS_HOST : true ,
15431551} ) ;
15441552test ! ( RustdocUi {
15451553 path: "tests/rustdoc-ui" ,
1546- mode: "ui" ,
1554+ mode: CompiletestMode :: Ui ,
15471555 suite: "rustdoc-ui" ,
15481556 default : true ,
15491557 IS_HOST : true ,
15501558} ) ;
15511559
15521560test ! ( RustdocJson {
15531561 path: "tests/rustdoc-json" ,
1554- mode: "rustdoc-json" ,
1562+ mode: CompiletestMode :: RustdocJson ,
15551563 suite: "rustdoc-json" ,
15561564 default : true ,
15571565 IS_HOST : true ,
15581566} ) ;
15591567
15601568test ! ( Pretty {
15611569 path: "tests/pretty" ,
1562- mode: "pretty" ,
1570+ mode: CompiletestMode :: Pretty ,
15631571 suite: "pretty" ,
15641572 default : true ,
15651573 IS_HOST : true ,
15661574} ) ;
15671575
1568- test ! ( RunMake { path: "tests/run-make" , mode: "run-make" , suite: "run-make" , default : true } ) ;
1576+ test ! ( RunMake {
1577+ path: "tests/run-make" ,
1578+ mode: CompiletestMode :: RunMake ,
1579+ suite: "run-make" ,
1580+ default : true ,
1581+ } ) ;
15691582test ! ( RunMakeCargo {
15701583 path: "tests/run-make-cargo" ,
1571- mode: "run-make" ,
1584+ mode: CompiletestMode :: RunMake ,
15721585 suite: "run-make-cargo" ,
15731586 default : true
15741587} ) ;
15751588
15761589test ! ( AssemblyLlvm {
15771590 path: "tests/assembly-llvm" ,
1578- mode: "assembly" ,
1591+ mode: CompiletestMode :: Assembly ,
15791592 suite: "assembly-llvm" ,
15801593 default : true
15811594} ) ;
@@ -1586,13 +1599,14 @@ test!(AssemblyLlvm {
15861599pub struct Coverage {
15871600 pub compiler : Compiler ,
15881601 pub target : TargetSelection ,
1589- pub mode : & ' static str ,
1602+ pub ( crate ) mode : CompiletestMode ,
15901603}
15911604
15921605impl Coverage {
15931606 const PATH : & ' static str = "tests/coverage" ;
15941607 const SUITE : & ' static str = "coverage" ;
1595- const ALL_MODES : & [ & str ] = & [ "coverage-map" , "coverage-run" ] ;
1608+ const ALL_MODES : & [ CompiletestMode ] =
1609+ & [ CompiletestMode :: CoverageMap , CompiletestMode :: CoverageRun ] ;
15961610}
15971611
15981612impl Step for Coverage {
@@ -1608,7 +1622,7 @@ impl Step for Coverage {
16081622 // - `./x test coverage-run -- tests/coverage/trivial.rs`
16091623 run = run. suite_path ( Self :: PATH ) ;
16101624 for mode in Self :: ALL_MODES {
1611- run = run. alias ( mode) ;
1625+ run = run. alias ( mode. as_str ( ) ) ;
16121626 }
16131627 run
16141628 }
@@ -1631,23 +1645,25 @@ impl Step for Coverage {
16311645 for path in & run. paths {
16321646 match path {
16331647 PathSet :: Set ( _) => {
1634- for mode in Self :: ALL_MODES {
1635- if path. assert_single_path ( ) . path == Path :: new ( mode) {
1648+ for & mode in Self :: ALL_MODES {
1649+ if path. assert_single_path ( ) . path == Path :: new ( mode. as_str ( ) ) {
16361650 modes. push ( mode) ;
16371651 break ;
16381652 }
16391653 }
16401654 }
16411655 PathSet :: Suite ( _) => {
1642- modes. extend ( Self :: ALL_MODES ) ;
1656+ modes. extend_from_slice ( Self :: ALL_MODES ) ;
16431657 break ;
16441658 }
16451659 }
16461660 }
16471661
16481662 // Skip any modes that were explicitly skipped/excluded on the command-line.
16491663 // FIXME(Zalathar): Integrate this into central skip handling somehow?
1650- modes. retain ( |mode| !run. builder . config . skip . iter ( ) . any ( |skip| skip == Path :: new ( mode) ) ) ;
1664+ modes. retain ( |mode| {
1665+ !run. builder . config . skip . iter ( ) . any ( |skip| skip == Path :: new ( mode. as_str ( ) ) )
1666+ } ) ;
16511667
16521668 // FIXME(Zalathar): Make these commands skip all coverage tests, as expected:
16531669 // - `./x test --skip=tests`
@@ -1678,7 +1694,7 @@ impl Step for Coverage {
16781694
16791695test ! ( CoverageRunRustdoc {
16801696 path: "tests/coverage-run-rustdoc" ,
1681- mode: "coverage-run" ,
1697+ mode: CompiletestMode :: CoverageRun ,
16821698 suite: "coverage-run-rustdoc" ,
16831699 default : true ,
16841700 IS_HOST : true ,
@@ -1712,7 +1728,7 @@ impl Step for MirOpt {
17121728 builder. ensure ( Compiletest {
17131729 test_compiler : self . compiler ,
17141730 target,
1715- mode : "mir-opt" ,
1731+ mode : CompiletestMode :: MirOpt ,
17161732 suite : "mir-opt" ,
17171733 path : "tests/mir-opt" ,
17181734 compare_mode : None ,
@@ -1755,7 +1771,7 @@ struct Compiletest {
17551771 /// The compiler that we're testing.
17561772 test_compiler : Compiler ,
17571773 target : TargetSelection ,
1758- mode : & ' static str ,
1774+ mode : CompiletestMode ,
17591775 suite : & ' static str ,
17601776 path : & ' static str ,
17611777 compare_mode : Option < & ' static str > ,
@@ -1791,7 +1807,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17911807 let suite_path = self . path ;
17921808
17931809 // Skip codegen tests if they aren't enabled in configuration.
1794- if !builder. config . codegen_tests && mode == "codegen" {
1810+ if !builder. config . codegen_tests && mode == CompiletestMode :: Codegen {
17951811 return ;
17961812 }
17971813
@@ -1829,7 +1845,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18291845 target,
18301846 } ) ;
18311847 }
1832- if mode == "run-make" {
1848+ if mode == CompiletestMode :: RunMake {
18331849 builder. tool_exe ( Tool :: RunMakeSupport ) ;
18341850 }
18351851
@@ -1886,7 +1902,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18861902 // suites, `run-make` and `run-make-cargo`. That way, contributors who do not need to run
18871903 // the `run-make` tests that need in-tree cargo do not need to spend time building in-tree
18881904 // cargo.
1889- if mode == "run-make" {
1905+ if mode == CompiletestMode :: RunMake {
18901906 // We need to pass the compiler that was used to compile run-make-support,
18911907 // because we have to use the same compiler to compile rmake.rs recipes.
18921908 let stage0_rustc_path = builder. compiler ( 0 , test_compiler. host ) ;
@@ -1910,17 +1926,18 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19101926 }
19111927
19121928 // Avoid depending on rustdoc when we don't need it.
1913- if mode == "rustdoc"
1914- || mode == "run-make"
1915- || ( mode == "ui" && is_rustdoc)
1916- || mode == "rustdoc-js"
1917- || mode == "rustdoc-json"
1918- || suite == "coverage-run-rustdoc"
1929+ if matches ! (
1930+ mode,
1931+ CompiletestMode :: RunMake
1932+ | CompiletestMode :: Rustdoc
1933+ | CompiletestMode :: RustdocJs
1934+ | CompiletestMode :: RustdocJson
1935+ ) || matches ! ( suite, "rustdoc-ui" | "coverage-run-rustdoc" )
19191936 {
19201937 cmd. arg ( "--rustdoc-path" ) . arg ( builder. rustdoc_for_compiler ( test_compiler) ) ;
19211938 }
19221939
1923- if mode == "rustdoc-json" {
1940+ if mode == CompiletestMode :: RustdocJson {
19241941 // Use the stage0 compiler for jsondocck
19251942 let json_compiler = builder. compiler ( 0 , builder. host_target ) ;
19261943 cmd. arg ( "--jsondocck-path" )
@@ -1930,7 +1947,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19301947 ) ;
19311948 }
19321949
1933- if matches ! ( mode, "coverage-map" | "coverage-run" ) {
1950+ if matches ! ( mode, CompiletestMode :: CoverageMap | CompiletestMode :: CoverageRun ) {
19341951 let coverage_dump = builder. tool_exe ( Tool :: CoverageDump ) ;
19351952 cmd. arg ( "--coverage-dump-path" ) . arg ( coverage_dump) ;
19361953 }
@@ -1957,7 +1974,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19571974 cmd. arg ( "--sysroot-base" ) . arg ( sysroot) ;
19581975
19591976 cmd. arg ( "--suite" ) . arg ( suite) ;
1960- cmd. arg ( "--mode" ) . arg ( mode) ;
1977+ cmd. arg ( "--mode" ) . arg ( mode. as_str ( ) ) ;
19611978 cmd. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
19621979 cmd. arg ( "--host" ) . arg ( & * test_compiler. host . triple ) ;
19631980 cmd. arg ( "--llvm-filecheck" ) . arg ( builder. llvm_filecheck ( builder. config . host_target ) ) ;
@@ -2036,7 +2053,7 @@ Please disable assertions with `rust.debug-assertions = false`.
20362053
20372054 if let Some ( ref nodejs) = builder. config . nodejs {
20382055 cmd. arg ( "--nodejs" ) . arg ( nodejs) ;
2039- } else if mode == "rustdoc-js" {
2056+ } else if mode == CompiletestMode :: RustdocJs {
20402057 panic ! ( "need nodejs to run rustdoc-js suite" ) ;
20412058 }
20422059 if builder. config . rust_optimize_tests {
@@ -2055,7 +2072,7 @@ Please disable assertions with `rust.debug-assertions = false`.
20552072 let mut flags = if is_rustdoc { Vec :: new ( ) } else { vec ! [ "-Crpath" . to_string( ) ] } ;
20562073 flags. push ( format ! (
20572074 "-Cdebuginfo={}" ,
2058- if mode == "codegen" {
2075+ if mode == CompiletestMode :: Codegen {
20592076 // codegen tests typically check LLVM IR and are sensitive to additional debuginfo.
20602077 // So do not apply `rust.debuginfo-level-tests` for codegen tests.
20612078 if builder. config. rust_debuginfo_level_tests
@@ -2126,7 +2143,7 @@ Please disable assertions with `rust.debug-assertions = false`.
21262143 cmd. arg ( "--android-cross-path" ) . arg ( android_cross_path) ;
21272144 }
21282145
2129- if mode == "debuginfo" {
2146+ if mode == CompiletestMode :: Debuginfo {
21302147 if let Some ( debuggers:: Gdb { gdb } ) = debuggers:: discover_gdb ( builder) {
21312148 cmd. arg ( "--gdb" ) . arg ( gdb) ;
21322149 }
@@ -2158,7 +2175,7 @@ Please disable assertions with `rust.debug-assertions = false`.
21582175 // in rustdoc-js mode, allow filters to be rs files or js files.
21592176 // use a late-initialized Vec to avoid cloning for other modes.
21602177 let mut paths_v;
2161- if mode == "rustdoc-js" {
2178+ if mode == CompiletestMode :: RustdocJs {
21622179 paths_v = paths. to_vec ( ) ;
21632180 for p in & mut paths_v {
21642181 if let Some ( ext) = p. extension ( )
@@ -2240,7 +2257,9 @@ Please disable assertions with `rust.debug-assertions = false`.
22402257 cmd. arg ( "--host-rustcflags" ) . arg ( link_llvm) ;
22412258 }
22422259
2243- if !builder. config . dry_run ( ) && matches ! ( mode, "run-make" | "coverage-run" ) {
2260+ if !builder. config . dry_run ( )
2261+ && matches ! ( mode, CompiletestMode :: RunMake | CompiletestMode :: CoverageRun )
2262+ {
22442263 // The llvm/bin directory contains many useful cross-platform
22452264 // tools. Pass the path to run-make tests so they can use them.
22462265 // (The coverage-run tests also need these tools to process
@@ -2252,7 +2271,7 @@ Please disable assertions with `rust.debug-assertions = false`.
22522271 cmd. arg ( "--llvm-bin-dir" ) . arg ( llvm_bin_path) ;
22532272 }
22542273
2255- if !builder. config . dry_run ( ) && mode == "run-make" {
2274+ if !builder. config . dry_run ( ) && mode == CompiletestMode :: RunMake {
22562275 // If LLD is available, add it to the PATH
22572276 if builder. config . lld_enabled {
22582277 let lld_install_root =
@@ -2272,7 +2291,7 @@ Please disable assertions with `rust.debug-assertions = false`.
22722291
22732292 // Only pass correct values for these flags for the `run-make` suite as it
22742293 // requires that a C++ compiler was configured which isn't always the case.
2275- if !builder. config . dry_run ( ) && mode == "run-make" {
2294+ if !builder. config . dry_run ( ) && mode == CompiletestMode :: RunMake {
22762295 let mut cflags = builder. cc_handled_clags ( target, CLang :: C ) ;
22772296 cflags. extend ( builder. cc_unhandled_cflags ( target, GitRepo :: Rustc , CLang :: C ) ) ;
22782297 let mut cxxflags = builder. cc_handled_clags ( target, CLang :: Cxx ) ;
0 commit comments