@@ -2,7 +2,7 @@ use std::{
22 env,
33 ffi:: { OsStr , OsString } ,
44 fs:: { self , File } ,
5- io:: { BufRead , BufReader , ErrorKind } ,
5+ io:: { self , BufRead , BufReader , ErrorKind } ,
66 path:: { Path , PathBuf } ,
77 process:: { Command , Stdio } ,
88} ;
@@ -26,6 +26,14 @@ impl Config {
2626 self . verbose > 0
2727 }
2828
29+ pub fn symlink_file < P : AsRef < Path > , Q : AsRef < Path > > ( & self , src : P , link : Q ) -> io:: Result < ( ) > {
30+ #[ cfg( unix) ]
31+ use std:: os:: unix:: fs:: symlink as symlink_file;
32+ #[ cfg( windows) ]
33+ use std:: os:: windows:: fs:: symlink_file;
34+ if !self . dry_run ( ) { symlink_file ( src. as_ref ( ) , link. as_ref ( ) ) } else { Ok ( ( ) ) }
35+ }
36+
2937 pub ( crate ) fn create ( & self , path : & Path , s : & str ) {
3038 if self . dry_run ( ) {
3139 return ;
@@ -331,6 +339,12 @@ impl Config {
331339 let bin_root = self . out . join ( host. triple ) . join ( "rustfmt" ) ;
332340 let rustfmt_path = bin_root. join ( "bin" ) . join ( exe ( "rustfmt" , host) ) ;
333341 let rustfmt_stamp = bin_root. join ( ".rustfmt-stamp" ) ;
342+
343+ let legacy_rustfmt = self . initial_rustc . with_file_name ( exe ( "rustfmt" , host) ) ;
344+ if !legacy_rustfmt. exists ( ) {
345+ t ! ( self . symlink_file( & rustfmt_path, & legacy_rustfmt) ) ;
346+ }
347+
334348 if rustfmt_path. exists ( ) && !program_out_of_date ( & rustfmt_stamp, & channel) {
335349 return Some ( rustfmt_path) ;
336350 }
0 commit comments