@@ -10,7 +10,6 @@ use std::ffi::OsString;
10
10
use std:: fmt;
11
11
use std:: fs;
12
12
use std:: path:: { Path , PathBuf } ;
13
- use std:: process;
14
13
15
14
use crate :: cache:: { Interned , INTERNER } ;
16
15
use crate :: flags:: Flags ;
@@ -57,7 +56,7 @@ pub struct Config {
57
56
pub skip_only_host_steps : bool ,
58
57
59
58
pub on_fail : Option < String > ,
60
- pub stage : Option < u32 > ,
59
+ pub stage : u32 ,
61
60
pub keep_stage : Vec < u32 > ,
62
61
pub src : PathBuf ,
63
62
pub jobs : Option < u32 > ,
@@ -300,6 +299,12 @@ struct Build {
300
299
configure_args : Option < Vec < String > > ,
301
300
local_rebuild : Option < bool > ,
302
301
print_step_timings : Option < bool > ,
302
+ doc_stage : Option < u32 > ,
303
+ build_stage : Option < u32 > ,
304
+ test_stage : Option < u32 > ,
305
+ install_stage : Option < u32 > ,
306
+ dist_stage : Option < u32 > ,
307
+ bench_stage : Option < u32 > ,
303
308
}
304
309
305
310
/// TOML representation of various global install decisions.
@@ -480,13 +485,11 @@ impl Config {
480
485
481
486
pub fn parse ( args : & [ String ] ) -> Config {
482
487
let flags = Flags :: parse ( & args) ;
483
- let file = flags. config . clone ( ) ;
484
488
let mut config = Config :: default_opts ( ) ;
485
489
config. exclude = flags. exclude ;
486
490
config. rustc_error_format = flags. rustc_error_format ;
487
491
config. json_output = flags. json_output ;
488
492
config. on_fail = flags. on_fail ;
489
- config. stage = flags. stage ;
490
493
config. jobs = flags. jobs . map ( threads_from_config) ;
491
494
config. cmd = flags. cmd ;
492
495
config. incremental = flags. incremental ;
@@ -503,8 +506,14 @@ impl Config {
503
506
config. out = dir;
504
507
}
505
508
506
- let toml = file
509
+ #[ cfg( test) ]
510
+ let toml = TomlConfig :: default ( ) ;
511
+ #[ cfg( not( test) ) ]
512
+ let toml = flags
513
+ . config
507
514
. map ( |file| {
515
+ use std:: process;
516
+
508
517
let contents = t ! ( fs:: read_to_string( & file) ) ;
509
518
match toml:: from_str ( & contents) {
510
519
Ok ( table) => table,
@@ -520,7 +529,7 @@ impl Config {
520
529
} )
521
530
. unwrap_or_else ( TomlConfig :: default) ;
522
531
523
- let build = toml. build . clone ( ) . unwrap_or_default ( ) ;
532
+ let build = toml. build . unwrap_or_default ( ) ;
524
533
525
534
// If --target was specified but --host wasn't specified, don't run any host-only tests.
526
535
let has_hosts = build. host . is_some ( ) || flags. host . is_some ( ) ;
@@ -564,6 +573,44 @@ impl Config {
564
573
set ( & mut config. configure_args , build. configure_args ) ;
565
574
set ( & mut config. local_rebuild , build. local_rebuild ) ;
566
575
set ( & mut config. print_step_timings , build. print_step_timings ) ;
576
+
577
+ // See https://github.com/rust-lang/compiler-team/issues/326
578
+ config. stage = match config. cmd {
579
+ Subcommand :: Doc { .. } => flags. stage . or ( build. doc_stage ) . unwrap_or ( 0 ) ,
580
+ Subcommand :: Build { .. } => flags. stage . or ( build. build_stage ) . unwrap_or ( 1 ) ,
581
+ Subcommand :: Test { .. } => flags. stage . or ( build. test_stage ) . unwrap_or ( 1 ) ,
582
+ Subcommand :: Bench { .. } => flags. stage . or ( build. bench_stage ) . unwrap_or ( 2 ) ,
583
+ Subcommand :: Dist { .. } => flags. stage . or ( build. dist_stage ) . unwrap_or ( 2 ) ,
584
+ Subcommand :: Install { .. } => flags. stage . or ( build. install_stage ) . unwrap_or ( 2 ) ,
585
+ // These are all bootstrap tools, which don't depend on the compiler.
586
+ // The stage we pass shouldn't matter, but use 0 just in case.
587
+ Subcommand :: Clean { .. }
588
+ | Subcommand :: Check { .. }
589
+ | Subcommand :: Clippy { .. }
590
+ | Subcommand :: Fix { .. }
591
+ | Subcommand :: Run { .. }
592
+ | Subcommand :: Format { .. } => flags. stage . unwrap_or ( 0 ) ,
593
+ } ;
594
+
595
+ // CI should always run stage 2 builds, unless it specifically states otherwise
596
+ #[ cfg( not( test) ) ]
597
+ if flags. stage . is_none ( ) && crate :: CiEnv :: current ( ) != crate :: CiEnv :: None {
598
+ match config. cmd {
599
+ Subcommand :: Test { .. }
600
+ | Subcommand :: Doc { .. }
601
+ | Subcommand :: Build { .. }
602
+ | Subcommand :: Bench { .. }
603
+ | Subcommand :: Dist { .. }
604
+ | Subcommand :: Install { .. } => assert_eq ! ( config. stage, 2 ) ,
605
+ Subcommand :: Clean { .. }
606
+ | Subcommand :: Check { .. }
607
+ | Subcommand :: Clippy { .. }
608
+ | Subcommand :: Fix { .. }
609
+ | Subcommand :: Run { .. }
610
+ | Subcommand :: Format { .. } => { }
611
+ }
612
+ }
613
+
567
614
config. verbose = cmp:: max ( config. verbose , flags. verbose ) ;
568
615
569
616
if let Some ( ref install) = toml. install {
0 commit comments