33//! `./x.py test` (aka [`Kind::Test`]) is currently allowed to reach build steps in other modules.
44//! However, this contains ~all test parts we expect people to be able to build and run locally.
55
6+ // (This file should be split up, but having tidy block all changes is not helpful.)
7+ // ignore-tidy-filelength
8+
69use std:: collections:: HashSet ;
710use std:: env:: split_paths;
811use std:: ffi:: { OsStr , OsString } ;
@@ -17,6 +20,7 @@ use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
1720use crate :: core:: build_steps:: llvm:: get_llvm_version;
1821use crate :: core:: build_steps:: run:: { get_completion_paths, get_help_path} ;
1922use crate :: core:: build_steps:: synthetic_targets:: MirOptPanicAbortSyntheticTarget ;
23+ use crate :: core:: build_steps:: test:: compiletest:: CompiletestMode ;
2024use crate :: core:: build_steps:: tool:: {
2125 self , RustcPrivateCompilers , SourceType , TEST_FLOAT_PARSE_ALLOW_FEATURES , Tool ,
2226 ToolTargetBuildMode , get_tool_target_compiler,
@@ -39,6 +43,8 @@ use crate::utils::helpers::{
3943use crate :: utils:: render_tests:: { add_flags_and_try_run_tests, try_run_tests} ;
4044use crate :: { CLang , CodegenBackendKind , DocTests , GitRepo , Mode , PathSet , envify} ;
4145
46+ mod compiletest;
47+
4248/// Runs `cargo test` on various internal tools used by bootstrap.
4349#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
4450pub struct CrateBootstrap {
@@ -1085,7 +1091,7 @@ impl Step for RustdocJSNotStd {
10851091 builder. ensure ( Compiletest {
10861092 test_compiler : self . compiler ,
10871093 target : self . target ,
1088- mode : "rustdoc-js" ,
1094+ mode : CompiletestMode :: RustdocJs ,
10891095 suite : "rustdoc-js" ,
10901096 path : "tests/rustdoc-js" ,
10911097 compare_mode : None ,
@@ -1478,7 +1484,7 @@ macro_rules! test {
14781484 builder. ensure( Compiletest {
14791485 test_compiler: self . test_compiler,
14801486 target: self . target,
1481- mode: $mode,
1487+ mode: const { $mode } ,
14821488 suite: $suite,
14831489 path: $path,
14841490 compare_mode: ( const {
@@ -1493,89 +1499,99 @@ macro_rules! test {
14931499 } ;
14941500}
14951501
1496- test ! ( Ui { path: "tests/ui" , mode: "ui" , suite: "ui" , default : true } ) ;
1502+ test ! ( Ui { path: "tests/ui" , mode: CompiletestMode :: Ui , suite: "ui" , default : true } ) ;
14971503
1498- test ! ( Crashes { path: "tests/crashes" , mode: "crashes" , suite: "crashes" , default : true } ) ;
1504+ test ! ( Crashes {
1505+ path: "tests/crashes" ,
1506+ mode: CompiletestMode :: Crashes ,
1507+ suite: "crashes" ,
1508+ default : true ,
1509+ } ) ;
14991510
15001511test ! ( CodegenLlvm {
15011512 path: "tests/codegen-llvm" ,
1502- mode: "codegen" ,
1513+ mode: CompiletestMode :: Codegen ,
15031514 suite: "codegen-llvm" ,
15041515 default : true
15051516} ) ;
15061517
15071518test ! ( CodegenUnits {
15081519 path: "tests/codegen-units" ,
1509- mode: "codegen-units" ,
1520+ mode: CompiletestMode :: CodegenUnits ,
15101521 suite: "codegen-units" ,
15111522 default : true ,
15121523} ) ;
15131524
15141525test ! ( Incremental {
15151526 path: "tests/incremental" ,
1516- mode: "incremental" ,
1527+ mode: CompiletestMode :: Incremental ,
15171528 suite: "incremental" ,
15181529 default : true ,
15191530} ) ;
15201531
15211532test ! ( Debuginfo {
15221533 path: "tests/debuginfo" ,
1523- mode: "debuginfo" ,
1534+ mode: CompiletestMode :: Debuginfo ,
15241535 suite: "debuginfo" ,
15251536 default : true ,
15261537 compare_mode: Some ( "split-dwarf" ) ,
15271538} ) ;
15281539
15291540test ! ( UiFullDeps {
15301541 path: "tests/ui-fulldeps" ,
1531- mode: "ui" ,
1542+ mode: CompiletestMode :: Ui ,
15321543 suite: "ui-fulldeps" ,
15331544 default : true ,
15341545 IS_HOST : true ,
15351546} ) ;
15361547
15371548test ! ( Rustdoc {
15381549 path: "tests/rustdoc" ,
1539- mode: "rustdoc" ,
1550+ mode: CompiletestMode :: Rustdoc ,
15401551 suite: "rustdoc" ,
15411552 default : true ,
15421553 IS_HOST : true ,
15431554} ) ;
15441555test ! ( RustdocUi {
15451556 path: "tests/rustdoc-ui" ,
1546- mode: "ui" ,
1557+ mode: CompiletestMode :: Ui ,
15471558 suite: "rustdoc-ui" ,
15481559 default : true ,
15491560 IS_HOST : true ,
15501561} ) ;
15511562
15521563test ! ( RustdocJson {
15531564 path: "tests/rustdoc-json" ,
1554- mode: "rustdoc-json" ,
1565+ mode: CompiletestMode :: RustdocJson ,
15551566 suite: "rustdoc-json" ,
15561567 default : true ,
15571568 IS_HOST : true ,
15581569} ) ;
15591570
15601571test ! ( Pretty {
15611572 path: "tests/pretty" ,
1562- mode: "pretty" ,
1573+ mode: CompiletestMode :: Pretty ,
15631574 suite: "pretty" ,
15641575 default : true ,
15651576 IS_HOST : true ,
15661577} ) ;
15671578
1568- test ! ( RunMake { path: "tests/run-make" , mode: "run-make" , suite: "run-make" , default : true } ) ;
1579+ test ! ( RunMake {
1580+ path: "tests/run-make" ,
1581+ mode: CompiletestMode :: RunMake ,
1582+ suite: "run-make" ,
1583+ default : true ,
1584+ } ) ;
15691585test ! ( RunMakeCargo {
15701586 path: "tests/run-make-cargo" ,
1571- mode: "run-make" ,
1587+ mode: CompiletestMode :: RunMake ,
15721588 suite: "run-make-cargo" ,
15731589 default : true
15741590} ) ;
15751591
15761592test ! ( AssemblyLlvm {
15771593 path: "tests/assembly-llvm" ,
1578- mode: "assembly" ,
1594+ mode: CompiletestMode :: Assembly ,
15791595 suite: "assembly-llvm" ,
15801596 default : true
15811597} ) ;
@@ -1586,13 +1602,14 @@ test!(AssemblyLlvm {
15861602pub struct Coverage {
15871603 pub compiler : Compiler ,
15881604 pub target : TargetSelection ,
1589- pub mode : & ' static str ,
1605+ pub ( crate ) mode : CompiletestMode ,
15901606}
15911607
15921608impl Coverage {
15931609 const PATH : & ' static str = "tests/coverage" ;
15941610 const SUITE : & ' static str = "coverage" ;
1595- const ALL_MODES : & [ & str ] = & [ "coverage-map" , "coverage-run" ] ;
1611+ const ALL_MODES : & [ CompiletestMode ] =
1612+ & [ CompiletestMode :: CoverageMap , CompiletestMode :: CoverageRun ] ;
15961613}
15971614
15981615impl Step for Coverage {
@@ -1608,7 +1625,7 @@ impl Step for Coverage {
16081625 // - `./x test coverage-run -- tests/coverage/trivial.rs`
16091626 run = run. suite_path ( Self :: PATH ) ;
16101627 for mode in Self :: ALL_MODES {
1611- run = run. alias ( mode) ;
1628+ run = run. alias ( mode. as_str ( ) ) ;
16121629 }
16131630 run
16141631 }
@@ -1631,23 +1648,25 @@ impl Step for Coverage {
16311648 for path in & run. paths {
16321649 match path {
16331650 PathSet :: Set ( _) => {
1634- for mode in Self :: ALL_MODES {
1635- if path. assert_single_path ( ) . path == Path :: new ( mode) {
1651+ for & mode in Self :: ALL_MODES {
1652+ if path. assert_single_path ( ) . path == Path :: new ( mode. as_str ( ) ) {
16361653 modes. push ( mode) ;
16371654 break ;
16381655 }
16391656 }
16401657 }
16411658 PathSet :: Suite ( _) => {
1642- modes. extend ( Self :: ALL_MODES ) ;
1659+ modes. extend_from_slice ( Self :: ALL_MODES ) ;
16431660 break ;
16441661 }
16451662 }
16461663 }
16471664
16481665 // Skip any modes that were explicitly skipped/excluded on the command-line.
16491666 // FIXME(Zalathar): Integrate this into central skip handling somehow?
1650- modes. retain ( |mode| !run. builder . config . skip . iter ( ) . any ( |skip| skip == Path :: new ( mode) ) ) ;
1667+ modes. retain ( |mode| {
1668+ !run. builder . config . skip . iter ( ) . any ( |skip| skip == Path :: new ( mode. as_str ( ) ) )
1669+ } ) ;
16511670
16521671 // FIXME(Zalathar): Make these commands skip all coverage tests, as expected:
16531672 // - `./x test --skip=tests`
@@ -1678,7 +1697,7 @@ impl Step for Coverage {
16781697
16791698test ! ( CoverageRunRustdoc {
16801699 path: "tests/coverage-run-rustdoc" ,
1681- mode: "coverage-run" ,
1700+ mode: CompiletestMode :: CoverageRun ,
16821701 suite: "coverage-run-rustdoc" ,
16831702 default : true ,
16841703 IS_HOST : true ,
@@ -1712,7 +1731,7 @@ impl Step for MirOpt {
17121731 builder. ensure ( Compiletest {
17131732 test_compiler : self . compiler ,
17141733 target,
1715- mode : "mir-opt" ,
1734+ mode : CompiletestMode :: MirOpt ,
17161735 suite : "mir-opt" ,
17171736 path : "tests/mir-opt" ,
17181737 compare_mode : None ,
@@ -1755,7 +1774,7 @@ struct Compiletest {
17551774 /// The compiler that we're testing.
17561775 test_compiler : Compiler ,
17571776 target : TargetSelection ,
1758- mode : & ' static str ,
1777+ mode : CompiletestMode ,
17591778 suite : & ' static str ,
17601779 path : & ' static str ,
17611780 compare_mode : Option < & ' static str > ,
@@ -1791,7 +1810,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17911810 let suite_path = self . path ;
17921811
17931812 // Skip codegen tests if they aren't enabled in configuration.
1794- if !builder. config . codegen_tests && mode == "codegen" {
1813+ if !builder. config . codegen_tests && mode == CompiletestMode :: Codegen {
17951814 return ;
17961815 }
17971816
@@ -1829,7 +1848,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18291848 target,
18301849 } ) ;
18311850 }
1832- if mode == "run-make" {
1851+ if mode == CompiletestMode :: RunMake {
18331852 builder. tool_exe ( Tool :: RunMakeSupport ) ;
18341853 }
18351854
@@ -1886,7 +1905,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18861905 // suites, `run-make` and `run-make-cargo`. That way, contributors who do not need to run
18871906 // the `run-make` tests that need in-tree cargo do not need to spend time building in-tree
18881907 // cargo.
1889- if mode == "run-make" {
1908+ if mode == CompiletestMode :: RunMake {
18901909 // We need to pass the compiler that was used to compile run-make-support,
18911910 // because we have to use the same compiler to compile rmake.rs recipes.
18921911 let stage0_rustc_path = builder. compiler ( 0 , test_compiler. host ) ;
@@ -1910,17 +1929,18 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19101929 }
19111930
19121931 // 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"
1932+ if matches ! (
1933+ mode,
1934+ CompiletestMode :: RunMake
1935+ | CompiletestMode :: Rustdoc
1936+ | CompiletestMode :: RustdocJs
1937+ | CompiletestMode :: RustdocJson
1938+ ) || matches ! ( suite, "rustdoc-ui" | "coverage-run-rustdoc" )
19191939 {
19201940 cmd. arg ( "--rustdoc-path" ) . arg ( builder. rustdoc_for_compiler ( test_compiler) ) ;
19211941 }
19221942
1923- if mode == "rustdoc-json" {
1943+ if mode == CompiletestMode :: RustdocJson {
19241944 // Use the stage0 compiler for jsondocck
19251945 let json_compiler = builder. compiler ( 0 , builder. host_target ) ;
19261946 cmd. arg ( "--jsondocck-path" )
@@ -1930,7 +1950,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19301950 ) ;
19311951 }
19321952
1933- if matches ! ( mode, "coverage-map" | "coverage-run" ) {
1953+ if matches ! ( mode, CompiletestMode :: CoverageMap | CompiletestMode :: CoverageRun ) {
19341954 let coverage_dump = builder. tool_exe ( Tool :: CoverageDump ) ;
19351955 cmd. arg ( "--coverage-dump-path" ) . arg ( coverage_dump) ;
19361956 }
@@ -1957,7 +1977,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19571977 cmd. arg ( "--sysroot-base" ) . arg ( sysroot) ;
19581978
19591979 cmd. arg ( "--suite" ) . arg ( suite) ;
1960- cmd. arg ( "--mode" ) . arg ( mode) ;
1980+ cmd. arg ( "--mode" ) . arg ( mode. as_str ( ) ) ;
19611981 cmd. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
19621982 cmd. arg ( "--host" ) . arg ( & * test_compiler. host . triple ) ;
19631983 cmd. arg ( "--llvm-filecheck" ) . arg ( builder. llvm_filecheck ( builder. config . host_target ) ) ;
@@ -2036,7 +2056,7 @@ Please disable assertions with `rust.debug-assertions = false`.
20362056
20372057 if let Some ( ref nodejs) = builder. config . nodejs {
20382058 cmd. arg ( "--nodejs" ) . arg ( nodejs) ;
2039- } else if mode == "rustdoc-js" {
2059+ } else if mode == CompiletestMode :: RustdocJs {
20402060 panic ! ( "need nodejs to run rustdoc-js suite" ) ;
20412061 }
20422062 if builder. config . rust_optimize_tests {
@@ -2055,7 +2075,7 @@ Please disable assertions with `rust.debug-assertions = false`.
20552075 let mut flags = if is_rustdoc { Vec :: new ( ) } else { vec ! [ "-Crpath" . to_string( ) ] } ;
20562076 flags. push ( format ! (
20572077 "-Cdebuginfo={}" ,
2058- if mode == "codegen" {
2078+ if mode == CompiletestMode :: Codegen {
20592079 // codegen tests typically check LLVM IR and are sensitive to additional debuginfo.
20602080 // So do not apply `rust.debuginfo-level-tests` for codegen tests.
20612081 if builder. config. rust_debuginfo_level_tests
@@ -2122,7 +2142,7 @@ Please disable assertions with `rust.debug-assertions = false`.
21222142 cmd. arg ( "--android-cross-path" ) . arg ( android_cross_path) ;
21232143 }
21242144
2125- if mode == "debuginfo" {
2145+ if mode == CompiletestMode :: Debuginfo {
21262146 if let Some ( debuggers:: Gdb { gdb } ) = debuggers:: discover_gdb ( builder, android. as_ref ( ) )
21272147 {
21282148 cmd. arg ( "--gdb" ) . arg ( gdb. as_ref ( ) ) ;
@@ -2155,7 +2175,7 @@ Please disable assertions with `rust.debug-assertions = false`.
21552175 // in rustdoc-js mode, allow filters to be rs files or js files.
21562176 // use a late-initialized Vec to avoid cloning for other modes.
21572177 let mut paths_v;
2158- if mode == "rustdoc-js" {
2178+ if mode == CompiletestMode :: RustdocJs {
21592179 paths_v = paths. to_vec ( ) ;
21602180 for p in & mut paths_v {
21612181 if let Some ( ext) = p. extension ( )
@@ -2237,7 +2257,9 @@ Please disable assertions with `rust.debug-assertions = false`.
22372257 cmd. arg ( "--host-rustcflags" ) . arg ( link_llvm) ;
22382258 }
22392259
2240- 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+ {
22412263 // The llvm/bin directory contains many useful cross-platform
22422264 // tools. Pass the path to run-make tests so they can use them.
22432265 // (The coverage-run tests also need these tools to process
@@ -2249,7 +2271,7 @@ Please disable assertions with `rust.debug-assertions = false`.
22492271 cmd. arg ( "--llvm-bin-dir" ) . arg ( llvm_bin_path) ;
22502272 }
22512273
2252- if !builder. config . dry_run ( ) && mode == "run-make" {
2274+ if !builder. config . dry_run ( ) && mode == CompiletestMode :: RunMake {
22532275 // If LLD is available, add it to the PATH
22542276 if builder. config . lld_enabled {
22552277 let lld_install_root =
@@ -2269,7 +2291,7 @@ Please disable assertions with `rust.debug-assertions = false`.
22692291
22702292 // Only pass correct values for these flags for the `run-make` suite as it
22712293 // requires that a C++ compiler was configured which isn't always the case.
2272- if !builder. config . dry_run ( ) && mode == "run-make" {
2294+ if !builder. config . dry_run ( ) && mode == CompiletestMode :: RunMake {
22732295 let mut cflags = builder. cc_handled_clags ( target, CLang :: C ) ;
22742296 cflags. extend ( builder. cc_unhandled_cflags ( target, GitRepo :: Rustc , CLang :: C ) ) ;
22752297 let mut cxxflags = builder. cc_handled_clags ( target, CLang :: Cxx ) ;
@@ -2385,7 +2407,7 @@ Please disable assertions with `rust.debug-assertions = false`.
23852407 builder. metrics . begin_test_suite (
23862408 build_helper:: metrics:: TestSuiteMetadata :: Compiletest {
23872409 suite : suite. into ( ) ,
2388- mode : mode. into ( ) ,
2410+ mode : mode. to_string ( ) ,
23892411 compare_mode : None ,
23902412 target : self . target . triple . to_string ( ) ,
23912413 host : self . test_compiler . host . triple . to_string ( ) ,
@@ -2408,7 +2430,7 @@ Please disable assertions with `rust.debug-assertions = false`.
24082430 builder. metrics . begin_test_suite (
24092431 build_helper:: metrics:: TestSuiteMetadata :: Compiletest {
24102432 suite : suite. into ( ) ,
2411- mode : mode. into ( ) ,
2433+ mode : mode. to_string ( ) ,
24122434 compare_mode : Some ( compare_mode. into ( ) ) ,
24132435 target : self . target . triple . to_string ( ) ,
24142436 host : self . test_compiler . host . triple . to_string ( ) ,
0 commit comments