@@ -392,27 +392,69 @@ impl Config {
392
392
)
393
393
) ]
394
394
pub ( crate ) fn parse_inner (
395
- mut flags : Flags ,
395
+ flags : Flags ,
396
396
get_toml : impl Fn ( & Path ) -> Result < TomlConfig , toml:: de:: Error > ,
397
397
) -> Config {
398
+ // Destructure flags to ensure that we use all its fields
399
+ // The field variables are prefixed with `flags_` to avoid clashes
400
+ // with values from TOML config files with same names.
401
+ let Flags {
402
+ cmd : flags_cmd,
403
+ verbose : flags_verbose,
404
+ incremental : flags_incremental,
405
+ config : flags_config,
406
+ build_dir : flags_build_dir,
407
+ build : flags_build,
408
+ host : flags_host,
409
+ target : flags_target,
410
+ exclude : flags_exclude,
411
+ skip : flags_skip,
412
+ include_default_paths : flags_include_default_paths,
413
+ rustc_error_format : flags_rustc_error_format,
414
+ on_fail : flags_on_fail,
415
+ dry_run : flags_dry_run,
416
+ dump_bootstrap_shims : flags_dump_bootstrap_shims,
417
+ stage : flags_stage,
418
+ keep_stage : flags_keep_stage,
419
+ keep_stage_std : flags_keep_stage_std,
420
+ src : flags_src,
421
+ jobs : flags_jobs,
422
+ warnings : flags_warnings,
423
+ json_output : flags_json_output,
424
+ color : flags_color,
425
+ bypass_bootstrap_lock : flags_bypass_bootstrap_lock,
426
+ rust_profile_generate : flags_rust_profile_generate,
427
+ rust_profile_use : flags_rust_profile_use,
428
+ llvm_profile_use : flags_llvm_profile_use,
429
+ llvm_profile_generate : flags_llvm_profile_generate,
430
+ enable_bolt_settings : flags_enable_bolt_settings,
431
+ skip_stage0_validation : flags_skip_stage0_validation,
432
+ reproducible_artifact : flags_reproducible_artifact,
433
+ paths : mut flags_paths,
434
+ set : flags_set,
435
+ free_args : mut flags_free_args,
436
+ ci : flags_ci,
437
+ skip_std_check_if_no_download_rustc : flags_skip_std_check_if_no_download_rustc,
438
+ } = flags;
439
+
398
440
let mut config = Config :: default_opts ( ) ;
399
441
let mut exec_ctx = ExecutionContext :: new ( ) ;
400
- exec_ctx. set_verbose ( flags . verbose ) ;
401
- exec_ctx. set_fail_fast ( flags . cmd . fail_fast ( ) ) ;
442
+ exec_ctx. set_verbose ( flags_verbose ) ;
443
+ exec_ctx. set_fail_fast ( flags_cmd . fail_fast ( ) ) ;
402
444
403
445
config. exec_ctx = exec_ctx;
404
446
405
447
// Set flags.
406
- config. paths = std:: mem:: take ( & mut flags . paths ) ;
448
+ config. paths = std:: mem:: take ( & mut flags_paths ) ;
407
449
408
450
#[ cfg( feature = "tracing" ) ]
409
451
span ! (
410
452
target: "CONFIG_HANDLING" ,
411
453
tracing:: Level :: TRACE ,
412
454
"collecting paths and path exclusions" ,
413
- "flags.paths" = ?flags . paths ,
414
- "flags.skip" = ?flags . skip ,
415
- "flags.exclude" = ?flags . exclude
455
+ "flags.paths" = ?flags_paths ,
456
+ "flags.skip" = ?flags_skip ,
457
+ "flags.exclude" = ?flags_exclude
416
458
) ;
417
459
418
460
#[ cfg( feature = "tracing" ) ]
@@ -423,28 +465,28 @@ impl Config {
423
465
"config.skip" = ?config. skip,
424
466
) ;
425
467
426
- config. include_default_paths = flags . include_default_paths ;
427
- config. rustc_error_format = flags . rustc_error_format ;
428
- config. json_output = flags . json_output ;
429
- config. on_fail = flags . on_fail ;
430
- config. cmd = flags . cmd ;
431
- config. incremental = flags . incremental ;
432
- config. set_dry_run ( if flags . dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ) ;
433
- config. dump_bootstrap_shims = flags . dump_bootstrap_shims ;
434
- config. keep_stage = flags . keep_stage ;
435
- config. keep_stage_std = flags . keep_stage_std ;
436
- config. color = flags . color ;
437
- config. free_args = std:: mem:: take ( & mut flags . free_args ) ;
438
- config. llvm_profile_use = flags . llvm_profile_use ;
439
- config. llvm_profile_generate = flags . llvm_profile_generate ;
440
- config. enable_bolt_settings = flags . enable_bolt_settings ;
441
- config. bypass_bootstrap_lock = flags . bypass_bootstrap_lock ;
442
- config. is_running_on_ci = flags . ci . unwrap_or ( CiEnv :: is_ci ( ) ) ;
443
- config. skip_std_check_if_no_download_rustc = flags . skip_std_check_if_no_download_rustc ;
468
+ config. include_default_paths = flags_include_default_paths ;
469
+ config. rustc_error_format = flags_rustc_error_format ;
470
+ config. json_output = flags_json_output ;
471
+ config. on_fail = flags_on_fail ;
472
+ config. cmd = flags_cmd ;
473
+ config. incremental = flags_incremental ;
474
+ config. set_dry_run ( if flags_dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ) ;
475
+ config. dump_bootstrap_shims = flags_dump_bootstrap_shims ;
476
+ config. keep_stage = flags_keep_stage ;
477
+ config. keep_stage_std = flags_keep_stage_std ;
478
+ config. color = flags_color ;
479
+ config. free_args = std:: mem:: take ( & mut flags_free_args ) ;
480
+ config. llvm_profile_use = flags_llvm_profile_use ;
481
+ config. llvm_profile_generate = flags_llvm_profile_generate ;
482
+ config. enable_bolt_settings = flags_enable_bolt_settings ;
483
+ config. bypass_bootstrap_lock = flags_bypass_bootstrap_lock ;
484
+ config. is_running_on_ci = flags_ci . unwrap_or ( CiEnv :: is_ci ( ) ) ;
485
+ config. skip_std_check_if_no_download_rustc = flags_skip_std_check_if_no_download_rustc ;
444
486
445
487
// Infer the rest of the configuration.
446
488
447
- if let Some ( src) = flags . src {
489
+ if let Some ( src) = flags_src {
448
490
config. src = src
449
491
} else {
450
492
// Infer the source directory. This is non-trivial because we want to support a downloaded bootstrap binary,
@@ -510,8 +552,7 @@ impl Config {
510
552
// 4. `<root>/bootstrap.toml`
511
553
// 5. `./config.toml` (fallback for backward compatibility)
512
554
// 6. `<root>/config.toml`
513
- let toml_path = flags
514
- . config
555
+ let toml_path = flags_config
515
556
. clone ( )
516
557
. or_else ( || env:: var_os ( "RUST_BOOTSTRAP_CONFIG" ) . map ( PathBuf :: from) ) ;
517
558
let using_default_path = toml_path. is_none ( ) ;
@@ -610,7 +651,7 @@ impl Config {
610
651
}
611
652
612
653
let mut override_toml = TomlConfig :: default ( ) ;
613
- for option in flags . set . iter ( ) {
654
+ for option in flags_set . iter ( ) {
614
655
fn get_table ( option : & str ) -> Result < TomlConfig , toml:: de:: Error > {
615
656
toml:: from_str ( option) . and_then ( |table : toml:: Value | TomlConfig :: deserialize ( table) )
616
657
}
@@ -708,7 +749,7 @@ impl Config {
708
749
exclude,
709
750
} = toml. build . unwrap_or_default ( ) ;
710
751
711
- let mut paths: Vec < PathBuf > = flags . skip . into_iter ( ) . chain ( flags . exclude ) . collect ( ) ;
752
+ let mut paths: Vec < PathBuf > = flags_skip . into_iter ( ) . chain ( flags_exclude ) . collect ( ) ;
712
753
713
754
if let Some ( exclude) = exclude {
714
755
paths. extend ( exclude) ;
@@ -728,13 +769,15 @@ impl Config {
728
769
} )
729
770
. collect ( ) ;
730
771
731
- config. jobs = Some ( threads_from_config ( flags . jobs . unwrap_or ( jobs. unwrap_or ( 0 ) ) ) ) ;
772
+ config. jobs = Some ( threads_from_config ( flags_jobs . unwrap_or ( jobs. unwrap_or ( 0 ) ) ) ) ;
732
773
733
- if let Some ( file_build) = build {
774
+ if let Some ( flags_build) = flags_build {
775
+ config. host_target = TargetSelection :: from_user ( & flags_build) ;
776
+ } else if let Some ( file_build) = build {
734
777
config. host_target = TargetSelection :: from_user ( & file_build) ;
735
778
} ;
736
779
737
- set ( & mut config. out , flags . build_dir . or_else ( || build_dir. map ( PathBuf :: from) ) ) ;
780
+ set ( & mut config. out , flags_build_dir . or_else ( || build_dir. map ( PathBuf :: from) ) ) ;
738
781
// NOTE: Bootstrap spawns various commands with different working directories.
739
782
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
740
783
if !config. out . is_absolute ( ) {
@@ -749,7 +792,7 @@ impl Config {
749
792
}
750
793
751
794
config. initial_rustc = if let Some ( rustc) = rustc {
752
- if !flags . skip_stage0_validation {
795
+ if !flags_skip_stage0_validation {
753
796
config. check_stage0_version ( & rustc, "rustc" ) ;
754
797
}
755
798
rustc
@@ -775,7 +818,7 @@ impl Config {
775
818
config. initial_cargo_clippy = cargo_clippy;
776
819
777
820
config. initial_cargo = if let Some ( cargo) = cargo {
778
- if !flags . skip_stage0_validation {
821
+ if !flags_skip_stage0_validation {
779
822
config. check_stage0_version ( & cargo, "cargo" ) ;
780
823
}
781
824
cargo
@@ -791,14 +834,14 @@ impl Config {
791
834
config. out = dir;
792
835
}
793
836
794
- config. hosts = if let Some ( TargetSelectionList ( arg_host) ) = flags . host {
837
+ config. hosts = if let Some ( TargetSelectionList ( arg_host) ) = flags_host {
795
838
arg_host
796
839
} else if let Some ( file_host) = host {
797
840
file_host. iter ( ) . map ( |h| TargetSelection :: from_user ( h) ) . collect ( )
798
841
} else {
799
842
vec ! [ config. host_target]
800
843
} ;
801
- config. targets = if let Some ( TargetSelectionList ( arg_target) ) = flags . target {
844
+ config. targets = if let Some ( TargetSelectionList ( arg_target) ) = flags_target {
802
845
arg_target
803
846
} else if let Some ( file_target) = target {
804
847
file_target. iter ( ) . map ( |h| TargetSelection :: from_user ( h) ) . collect ( )
@@ -837,7 +880,7 @@ impl Config {
837
880
set ( & mut config. print_step_rusage , print_step_rusage) ;
838
881
config. patch_binaries_for_nix = patch_binaries_for_nix;
839
882
840
- config. verbose = cmp:: max ( config. verbose , flags . verbose as usize ) ;
883
+ config. verbose = cmp:: max ( config. verbose , flags_verbose as usize ) ;
841
884
842
885
// Verbose flag is a good default for `rust.verbose-tests`.
843
886
config. verbose_tests = config. is_verbose ( ) ;
@@ -892,12 +935,12 @@ impl Config {
892
935
config. channel = ci_channel. into ( ) ;
893
936
}
894
937
895
- config. rust_profile_use = flags . rust_profile_use ;
896
- config. rust_profile_generate = flags . rust_profile_generate ;
938
+ config. rust_profile_use = flags_rust_profile_use ;
939
+ config. rust_profile_generate = flags_rust_profile_generate ;
897
940
898
- config. apply_rust_config ( toml. rust , flags . warnings , & mut description) ;
941
+ config. apply_rust_config ( toml. rust , flags_warnings , & mut description) ;
899
942
900
- config. reproducible_artifacts = flags . reproducible_artifact ;
943
+ config. reproducible_artifacts = flags_reproducible_artifact ;
901
944
config. description = description;
902
945
903
946
// We need to override `rust.channel` if it's manually specified when using the CI rustc.
@@ -953,7 +996,7 @@ impl Config {
953
996
954
997
if matches ! ( config. lld_mode, LldMode :: SelfContained )
955
998
&& !config. lld_enabled
956
- && flags . stage . unwrap_or ( 0 ) > 0
999
+ && flags_stage . unwrap_or ( 0 ) > 0
957
1000
{
958
1001
panic ! (
959
1002
"Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
@@ -972,7 +1015,7 @@ impl Config {
972
1015
config. compiletest_use_stage0_libtest = compiletest_use_stage0_libtest. unwrap_or ( true ) ;
973
1016
974
1017
let download_rustc = config. download_rustc_commit . is_some ( ) ;
975
- config. explicit_stage_from_cli = flags . stage . is_some ( ) ;
1018
+ config. explicit_stage_from_cli = flags_stage . is_some ( ) ;
976
1019
config. explicit_stage_from_config = test_stage. is_some ( )
977
1020
|| build_stage. is_some ( )
978
1021
|| doc_stage. is_some ( )
@@ -982,35 +1025,35 @@ impl Config {
982
1025
|| bench_stage. is_some ( ) ;
983
1026
// See https://github.com/rust-lang/compiler-team/issues/326
984
1027
config. stage = match config. cmd {
985
- Subcommand :: Check { .. } => flags . stage . or ( check_stage) . unwrap_or ( 0 ) ,
986
- Subcommand :: Clippy { .. } | Subcommand :: Fix => flags . stage . or ( check_stage) . unwrap_or ( 1 ) ,
1028
+ Subcommand :: Check { .. } => flags_stage . or ( check_stage) . unwrap_or ( 0 ) ,
1029
+ Subcommand :: Clippy { .. } | Subcommand :: Fix => flags_stage . or ( check_stage) . unwrap_or ( 1 ) ,
987
1030
// `download-rustc` only has a speed-up for stage2 builds. Default to stage2 unless explicitly overridden.
988
1031
Subcommand :: Doc { .. } => {
989
- flags . stage . or ( doc_stage) . unwrap_or ( if download_rustc { 2 } else { 1 } )
1032
+ flags_stage . or ( doc_stage) . unwrap_or ( if download_rustc { 2 } else { 1 } )
990
1033
}
991
1034
Subcommand :: Build => {
992
- flags . stage . or ( build_stage) . unwrap_or ( if download_rustc { 2 } else { 1 } )
1035
+ flags_stage . or ( build_stage) . unwrap_or ( if download_rustc { 2 } else { 1 } )
993
1036
}
994
1037
Subcommand :: Test { .. } | Subcommand :: Miri { .. } => {
995
- flags . stage . or ( test_stage) . unwrap_or ( if download_rustc { 2 } else { 1 } )
1038
+ flags_stage . or ( test_stage) . unwrap_or ( if download_rustc { 2 } else { 1 } )
996
1039
}
997
- Subcommand :: Bench { .. } => flags . stage . or ( bench_stage) . unwrap_or ( 2 ) ,
998
- Subcommand :: Dist => flags . stage . or ( dist_stage) . unwrap_or ( 2 ) ,
999
- Subcommand :: Install => flags . stage . or ( install_stage) . unwrap_or ( 2 ) ,
1000
- Subcommand :: Perf { .. } => flags . stage . unwrap_or ( 1 ) ,
1040
+ Subcommand :: Bench { .. } => flags_stage . or ( bench_stage) . unwrap_or ( 2 ) ,
1041
+ Subcommand :: Dist => flags_stage . or ( dist_stage) . unwrap_or ( 2 ) ,
1042
+ Subcommand :: Install => flags_stage . or ( install_stage) . unwrap_or ( 2 ) ,
1043
+ Subcommand :: Perf { .. } => flags_stage . unwrap_or ( 1 ) ,
1001
1044
// These are all bootstrap tools, which don't depend on the compiler.
1002
1045
// The stage we pass shouldn't matter, but use 0 just in case.
1003
1046
Subcommand :: Clean { .. }
1004
1047
| Subcommand :: Run { .. }
1005
1048
| Subcommand :: Setup { .. }
1006
1049
| Subcommand :: Format { .. }
1007
1050
| Subcommand :: Suggest { .. }
1008
- | Subcommand :: Vendor { .. } => flags . stage . unwrap_or ( 0 ) ,
1051
+ | Subcommand :: Vendor { .. } => flags_stage . unwrap_or ( 0 ) ,
1009
1052
} ;
1010
1053
1011
1054
// CI should always run stage 2 builds, unless it specifically states otherwise
1012
1055
#[ cfg( not( test) ) ]
1013
- if flags . stage . is_none ( ) && config. is_running_on_ci {
1056
+ if flags_stage . is_none ( ) && config. is_running_on_ci {
1014
1057
match config. cmd {
1015
1058
Subcommand :: Test { .. }
1016
1059
| Subcommand :: Miri { .. }
0 commit comments