@@ -38,24 +38,40 @@ impl Step for CleanTools {
3838 run. never ( )
3939 }
4040
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.
4541 fn run ( self , builder : & Builder ) {
4642 let build = builder. build ;
4743 let compiler = self . compiler ;
4844 let target = self . target ;
4945 let mode = self . mode ;
5046
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
5655 } ;
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+ }
5975 }
6076}
6177
@@ -70,7 +86,7 @@ struct ToolBuild {
7086}
7187
7288impl Step for ToolBuild {
73- type Output = PathBuf ;
89+ type Output = Option < PathBuf > ;
7490
7591 fn should_run ( run : ShouldRun ) -> ShouldRun {
7692 run. never ( )
@@ -80,7 +96,7 @@ impl Step for ToolBuild {
8096 ///
8197 /// This will build the specified tool with the specified `host` compiler in
8298 /// `stage` into the normal cargo output directory.
83- fn run ( self , builder : & Builder ) -> PathBuf {
99+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
84100 let build = builder. build ;
85101 let compiler = self . compiler ;
86102 let target = self . target ;
@@ -100,7 +116,15 @@ impl Step for ToolBuild {
100116
101117 let mut cargo = prepare_tool_cargo ( builder, compiler, target, "build" , path) ;
102118 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+ }
104128 }
105129}
106130
@@ -209,7 +233,7 @@ macro_rules! tool {
209233 mode: $mode,
210234 path: $path,
211235 expectation: BuildExpectation :: None ,
212- } )
236+ } ) . expect ( "expected to build -- BuildExpectation::None" )
213237 }
214238 }
215239 ) +
@@ -257,7 +281,7 @@ impl Step for RemoteTestServer {
257281 mode : Mode :: Libstd ,
258282 path : "src/tools/remote-test-server" ,
259283 expectation : BuildExpectation :: None ,
260- } )
284+ } ) . expect ( "expected to build -- BuildExpectation::None" )
261285 }
262286}
263287
@@ -375,7 +399,7 @@ impl Step for Cargo {
375399 mode : Mode :: Librustc ,
376400 path : "src/tools/cargo" ,
377401 expectation : BuildExpectation :: None ,
378- } )
402+ } ) . expect ( "BuildExpectation::None - expected to build" )
379403 }
380404}
381405
@@ -386,7 +410,7 @@ pub struct Clippy {
386410}
387411
388412impl Step for Clippy {
389- type Output = PathBuf ;
413+ type Output = Option < PathBuf > ;
390414 const DEFAULT : bool = true ;
391415 const ONLY_HOSTS : bool = true ;
392416
@@ -401,7 +425,7 @@ impl Step for Clippy {
401425 } ) ;
402426 }
403427
404- fn run ( self , builder : & Builder ) -> PathBuf {
428+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
405429 // Clippy depends on procedural macros (serde), which requires a full host
406430 // compiler to be available, so we need to depend on that.
407431 builder. ensure ( compile:: Rustc {
@@ -426,7 +450,7 @@ pub struct Rls {
426450}
427451
428452impl Step for Rls {
429- type Output = PathBuf ;
453+ type Output = Option < PathBuf > ;
430454 const DEFAULT : bool = true ;
431455 const ONLY_HOSTS : bool = true ;
432456
@@ -442,7 +466,7 @@ impl Step for Rls {
442466 } ) ;
443467 }
444468
445- fn run ( self , builder : & Builder ) -> PathBuf {
469+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
446470 builder. ensure ( native:: Openssl {
447471 target : self . target ,
448472 } ) ;
@@ -470,7 +494,7 @@ pub struct Rustfmt {
470494}
471495
472496impl Step for Rustfmt {
473- type Output = PathBuf ;
497+ type Output = Option < PathBuf > ;
474498 const DEFAULT : bool = true ;
475499 const ONLY_HOSTS : bool = true ;
476500
@@ -486,7 +510,7 @@ impl Step for Rustfmt {
486510 } ) ;
487511 }
488512
489- fn run ( self , builder : & Builder ) -> PathBuf {
513+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
490514 builder. ensure ( ToolBuild {
491515 compiler : self . compiler ,
492516 target : self . target ,
@@ -506,7 +530,7 @@ pub struct Miri {
506530}
507531
508532impl Step for Miri {
509- type Output = PathBuf ;
533+ type Output = Option < PathBuf > ;
510534 const DEFAULT : bool = true ;
511535 const ONLY_HOSTS : bool = true ;
512536
@@ -522,7 +546,7 @@ impl Step for Miri {
522546 } ) ;
523547 }
524548
525- fn run ( self , builder : & Builder ) -> PathBuf {
549+ fn run ( self , builder : & Builder ) -> Option < PathBuf > {
526550 builder. ensure ( ToolBuild {
527551 compiler : self . compiler ,
528552 target : self . target ,
0 commit comments