@@ -38,24 +38,40 @@ impl Step for CleanTools {
38
38
run. never ( )
39
39
}
40
40
41
- /// Build a tool in `src/tools`
42
- ///
43
- /// This will build the specified tool with the specified `host` compiler in
44
- /// `stage` into the normal cargo output directory.
45
41
fn run ( self , builder : & Builder ) {
46
42
let build = builder. build ;
47
43
let compiler = self . compiler ;
48
44
let target = self . target ;
49
45
let mode = self . mode ;
50
46
51
- let stamp = match mode {
52
- Mode :: Libstd => libstd_stamp ( build, compiler, target) ,
53
- Mode :: Libtest => libtest_stamp ( build, compiler, target) ,
54
- Mode :: Librustc => librustc_stamp ( build, compiler, target) ,
55
- _ => panic ! ( ) ,
47
+ // This is for the original compiler, but if we're forced to use stage 1, then
48
+ // std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
49
+ // we copy the libs forward.
50
+ let tools_dir = build. stage_out ( compiler, Mode :: Tool ) ;
51
+ let compiler = if builder. force_use_stage1 ( compiler, target) {
52
+ builder. compiler ( 1 , compiler. host )
53
+ } else {
54
+ compiler
56
55
} ;
57
- let out_dir = build. cargo_out ( compiler, Mode :: Tool , target) ;
58
- build. clear_if_dirty ( & out_dir, & stamp) ;
56
+
57
+ for & cur_mode in & [ Mode :: Libstd , Mode :: Libtest , Mode :: Librustc ] {
58
+ let stamp = match cur_mode {
59
+ Mode :: Libstd => libstd_stamp ( build, compiler, target) ,
60
+ Mode :: Libtest => libtest_stamp ( build, compiler, target) ,
61
+ Mode :: Librustc => librustc_stamp ( build, compiler, target) ,
62
+ _ => panic ! ( ) ,
63
+ } ;
64
+
65
+ if build. clear_if_dirty ( & tools_dir, & stamp) {
66
+ break ;
67
+ }
68
+
69
+ // If we are a rustc tool, and std changed, we also need to clear ourselves out -- our
70
+ // dependencies depend on std. Therefore, we iterate up until our own mode.
71
+ if mode == cur_mode {
72
+ break ;
73
+ }
74
+ }
59
75
}
60
76
}
61
77
@@ -70,7 +86,7 @@ struct ToolBuild {
70
86
}
71
87
72
88
impl Step for ToolBuild {
73
- type Output = PathBuf ;
89
+ type Output = Option < PathBuf > ;
74
90
75
91
fn should_run ( run : ShouldRun ) -> ShouldRun {
76
92
run. never ( )
@@ -80,7 +96,7 @@ impl Step for ToolBuild {
80
96
///
81
97
/// This will build the specified tool with the specified `host` compiler in
82
98
/// `stage` into the normal cargo output directory.
83
- fn run ( self , builder : & Builder ) -> PathBuf {
99
+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
84
100
let build = builder. build ;
85
101
let compiler = self . compiler ;
86
102
let target = self . target ;
@@ -100,7 +116,15 @@ impl Step for ToolBuild {
100
116
101
117
let mut cargo = prepare_tool_cargo ( builder, compiler, target, "build" , path) ;
102
118
build. run_expecting ( & mut cargo, expectation) ;
103
- build. cargo_out ( compiler, Mode :: Tool , target) . join ( exe ( tool, & compiler. host ) )
119
+ if expectation == BuildExpectation :: Succeeding || expectation == BuildExpectation :: None {
120
+ let cargo_out = build. cargo_out ( compiler, Mode :: Tool , target)
121
+ . join ( exe ( tool, & compiler. host ) ) ;
122
+ let bin = build. tools_dir ( compiler) . join ( exe ( tool, & compiler. host ) ) ;
123
+ copy ( & cargo_out, & bin) ;
124
+ Some ( bin)
125
+ } else {
126
+ None
127
+ }
104
128
}
105
129
}
106
130
@@ -209,7 +233,7 @@ macro_rules! tool {
209
233
mode: $mode,
210
234
path: $path,
211
235
expectation: BuildExpectation :: None ,
212
- } )
236
+ } ) . expect ( "expected to build -- BuildExpectation::None" )
213
237
}
214
238
}
215
239
) +
@@ -257,7 +281,7 @@ impl Step for RemoteTestServer {
257
281
mode : Mode :: Libstd ,
258
282
path : "src/tools/remote-test-server" ,
259
283
expectation : BuildExpectation :: None ,
260
- } )
284
+ } ) . expect ( "expected to build -- BuildExpectation::None" )
261
285
}
262
286
}
263
287
@@ -375,7 +399,7 @@ impl Step for Cargo {
375
399
mode : Mode :: Librustc ,
376
400
path : "src/tools/cargo" ,
377
401
expectation : BuildExpectation :: None ,
378
- } )
402
+ } ) . expect ( "BuildExpectation::None - expected to build" )
379
403
}
380
404
}
381
405
@@ -386,7 +410,7 @@ pub struct Clippy {
386
410
}
387
411
388
412
impl Step for Clippy {
389
- type Output = PathBuf ;
413
+ type Output = Option < PathBuf > ;
390
414
const DEFAULT : bool = true ;
391
415
const ONLY_HOSTS : bool = true ;
392
416
@@ -401,7 +425,7 @@ impl Step for Clippy {
401
425
} ) ;
402
426
}
403
427
404
- fn run ( self , builder : & Builder ) -> PathBuf {
428
+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
405
429
// Clippy depends on procedural macros (serde), which requires a full host
406
430
// compiler to be available, so we need to depend on that.
407
431
builder. ensure ( compile:: Rustc {
@@ -426,7 +450,7 @@ pub struct Rls {
426
450
}
427
451
428
452
impl Step for Rls {
429
- type Output = PathBuf ;
453
+ type Output = Option < PathBuf > ;
430
454
const DEFAULT : bool = true ;
431
455
const ONLY_HOSTS : bool = true ;
432
456
@@ -442,7 +466,7 @@ impl Step for Rls {
442
466
} ) ;
443
467
}
444
468
445
- fn run ( self , builder : & Builder ) -> PathBuf {
469
+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
446
470
builder. ensure ( native:: Openssl {
447
471
target : self . target ,
448
472
} ) ;
@@ -470,7 +494,7 @@ pub struct Rustfmt {
470
494
}
471
495
472
496
impl Step for Rustfmt {
473
- type Output = PathBuf ;
497
+ type Output = Option < PathBuf > ;
474
498
const DEFAULT : bool = true ;
475
499
const ONLY_HOSTS : bool = true ;
476
500
@@ -486,7 +510,7 @@ impl Step for Rustfmt {
486
510
} ) ;
487
511
}
488
512
489
- fn run ( self , builder : & Builder ) -> PathBuf {
513
+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
490
514
builder. ensure ( ToolBuild {
491
515
compiler : self . compiler ,
492
516
target : self . target ,
@@ -506,7 +530,7 @@ pub struct Miri {
506
530
}
507
531
508
532
impl Step for Miri {
509
- type Output = PathBuf ;
533
+ type Output = Option < PathBuf > ;
510
534
const DEFAULT : bool = true ;
511
535
const ONLY_HOSTS : bool = true ;
512
536
@@ -522,7 +546,7 @@ impl Step for Miri {
522
546
} ) ;
523
547
}
524
548
525
- fn run ( self , builder : & Builder ) -> PathBuf {
549
+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
526
550
builder. ensure ( ToolBuild {
527
551
compiler : self . compiler ,
528
552
target : self . target ,
0 commit comments