@@ -291,7 +291,7 @@ struct Build {
291
291
build_dir : Option < String > ,
292
292
cargo : Option < String > ,
293
293
rustc : Option < String > ,
294
- rustfmt : Option < String > , /* allow bootstrap.py to use rustfmt key */
294
+ rustfmt : Option < PathBuf > ,
295
295
docs : Option < bool > ,
296
296
compiler_docs : Option < bool > ,
297
297
submodules : Option < bool > ,
@@ -493,9 +493,8 @@ impl Config {
493
493
config. src = manifest_dir. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_owned ( ) ;
494
494
config. out = Config :: path_from_python ( "BUILD_DIR" ) ;
495
495
496
- config. initial_rustc = Config :: path_from_python ( "RUSTC" ) ;
497
- config. initial_cargo = Config :: path_from_python ( "CARGO" ) ;
498
- config. initial_rustfmt = env:: var_os ( "RUSTFMT" ) . map ( Config :: normalize_python_path) ;
496
+ config. initial_cargo = PathBuf :: from ( env ! ( "CARGO" ) ) ;
497
+ config. initial_rustc = PathBuf :: from ( env ! ( "RUSTC" ) ) ;
499
498
500
499
config
501
500
}
@@ -584,6 +583,9 @@ impl Config {
584
583
set ( & mut config. full_bootstrap , build. full_bootstrap ) ;
585
584
set ( & mut config. extended , build. extended ) ;
586
585
config. tools = build. tools ;
586
+ if build. rustfmt . is_some ( ) {
587
+ config. initial_rustfmt = build. rustfmt ;
588
+ }
587
589
set ( & mut config. verbose , build. verbose ) ;
588
590
set ( & mut config. sanitizers , build. sanitizers ) ;
589
591
set ( & mut config. profiler , build. profiler ) ;
@@ -832,12 +834,15 @@ impl Config {
832
834
set ( & mut config. missing_tools , t. missing_tools ) ;
833
835
}
834
836
837
+ // Cargo does not provide a RUSTFMT environment variable, so we
838
+ // synthesize it manually. Note that we also later check the config.toml
839
+ // and set this to that path if necessary.
840
+ let rustfmt = config. initial_rustc . with_file_name ( exe ( "rustfmt" , config. build ) ) ;
841
+ config. initial_rustfmt = if rustfmt. exists ( ) { Some ( rustfmt) } else { None } ;
842
+
835
843
// Now that we've reached the end of our configuration, infer the
836
844
// default values for all options that we haven't otherwise stored yet.
837
845
838
- set ( & mut config. initial_rustc , build. rustc . map ( PathBuf :: from) ) ;
839
- set ( & mut config. initial_cargo , build. cargo . map ( PathBuf :: from) ) ;
840
-
841
846
config. llvm_skip_rebuild = llvm_skip_rebuild. unwrap_or ( false ) ;
842
847
843
848
let default = false ;
0 commit comments