@@ -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 ;
@@ -68,7 +67,7 @@ pub struct Config {
68
67
pub skip_only_host_steps : bool ,
69
68
70
69
pub on_fail : Option < String > ,
71
- pub stage : Option < u32 > ,
70
+ pub stage : u32 ,
72
71
pub keep_stage : Vec < u32 > ,
73
72
pub src : PathBuf ,
74
73
pub jobs : Option < u32 > ,
@@ -313,6 +312,12 @@ struct Build {
313
312
configure_args : Option < Vec < String > > ,
314
313
local_rebuild : Option < bool > ,
315
314
print_step_timings : Option < bool > ,
315
+ doc_stage : Option < u32 > ,
316
+ build_stage : Option < u32 > ,
317
+ test_stage : Option < u32 > ,
318
+ install_stage : Option < u32 > ,
319
+ dist_stage : Option < u32 > ,
320
+ bench_stage : Option < u32 > ,
316
321
}
317
322
318
323
/// TOML representation of various global install decisions.
@@ -495,13 +500,11 @@ impl Config {
495
500
496
501
pub fn parse ( args : & [ String ] ) -> Config {
497
502
let flags = Flags :: parse ( & args) ;
498
- let file = flags. config . clone ( ) ;
499
503
let mut config = Config :: default_opts ( ) ;
500
504
config. exclude = flags. exclude ;
501
505
config. rustc_error_format = flags. rustc_error_format ;
502
506
config. json_output = flags. json_output ;
503
507
config. on_fail = flags. on_fail ;
504
- config. stage = flags. stage ;
505
508
config. jobs = flags. jobs . map ( threads_from_config) ;
506
509
config. cmd = flags. cmd ;
507
510
config. incremental = flags. incremental ;
@@ -518,8 +521,14 @@ impl Config {
518
521
config. out = dir;
519
522
}
520
523
521
- let toml = file
524
+ #[ cfg( test) ]
525
+ let toml = TomlConfig :: default ( ) ;
526
+ #[ cfg( not( test) ) ]
527
+ let toml = flags
528
+ . config
522
529
. map ( |file| {
530
+ use std:: process;
531
+
523
532
let contents = t ! ( fs:: read_to_string( & file) ) ;
524
533
match toml:: from_str ( & contents) {
525
534
Ok ( table) => table,
@@ -535,7 +544,7 @@ impl Config {
535
544
} )
536
545
. unwrap_or_else ( TomlConfig :: default) ;
537
546
538
- let build = toml. build . clone ( ) . unwrap_or_default ( ) ;
547
+ let build = toml. build . unwrap_or_default ( ) ;
539
548
540
549
// If --target was specified but --host wasn't specified, don't run any host-only tests.
541
550
let has_hosts = build. host . is_some ( ) || flags. host . is_some ( ) ;
@@ -579,6 +588,44 @@ impl Config {
579
588
set ( & mut config. configure_args , build. configure_args ) ;
580
589
set ( & mut config. local_rebuild , build. local_rebuild ) ;
581
590
set ( & mut config. print_step_timings , build. print_step_timings ) ;
591
+
592
+ // See https://github.com/rust-lang/compiler-team/issues/326
593
+ config. stage = match config. cmd {
594
+ Subcommand :: Doc { .. } => flags. stage . or ( build. doc_stage ) . unwrap_or ( 0 ) ,
595
+ Subcommand :: Build { .. } => flags. stage . or ( build. build_stage ) . unwrap_or ( 1 ) ,
596
+ Subcommand :: Test { .. } => flags. stage . or ( build. test_stage ) . unwrap_or ( 1 ) ,
597
+ Subcommand :: Bench { .. } => flags. stage . or ( build. bench_stage ) . unwrap_or ( 2 ) ,
598
+ Subcommand :: Dist { .. } => flags. stage . or ( build. dist_stage ) . unwrap_or ( 2 ) ,
599
+ Subcommand :: Install { .. } => flags. stage . or ( build. install_stage ) . unwrap_or ( 2 ) ,
600
+ // These are all bootstrap tools, which don't depend on the compiler.
601
+ // The stage we pass shouldn't matter, but use 0 just in case.
602
+ Subcommand :: Clean { .. }
603
+ | Subcommand :: Check { .. }
604
+ | Subcommand :: Clippy { .. }
605
+ | Subcommand :: Fix { .. }
606
+ | Subcommand :: Run { .. }
607
+ | Subcommand :: Format { .. } => flags. stage . unwrap_or ( 0 ) ,
608
+ } ;
609
+
610
+ // CI should always run stage 2 builds, unless it specifically states otherwise
611
+ #[ cfg( not( test) ) ]
612
+ if flags. stage . is_none ( ) && crate :: CiEnv :: current ( ) != crate :: CiEnv :: None {
613
+ match config. cmd {
614
+ Subcommand :: Test { .. }
615
+ | Subcommand :: Doc { .. }
616
+ | Subcommand :: Build { .. }
617
+ | Subcommand :: Bench { .. }
618
+ | Subcommand :: Dist { .. }
619
+ | Subcommand :: Install { .. } => assert_eq ! ( config. stage, 2 ) ,
620
+ Subcommand :: Clean { .. }
621
+ | Subcommand :: Check { .. }
622
+ | Subcommand :: Clippy { .. }
623
+ | Subcommand :: Fix { .. }
624
+ | Subcommand :: Run { .. }
625
+ | Subcommand :: Format { .. } => { }
626
+ }
627
+ }
628
+
582
629
config. verbose = cmp:: max ( config. verbose , flags. verbose ) ;
583
630
584
631
if let Some ( ref install) = toml. install {
0 commit comments