@@ -477,61 +477,6 @@ impl Config {
477477 & get_toml,
478478 ) ;
479479
480- // Set flags.
481- config. paths = std:: mem:: take ( & mut flags_paths) ;
482-
483- #[ cfg( feature = "tracing" ) ]
484- span ! (
485- target: "CONFIG_HANDLING" ,
486- tracing:: Level :: TRACE ,
487- "collecting paths and path exclusions" ,
488- "flags.paths" = ?flags_paths,
489- "flags.skip" = ?flags_skip,
490- "flags.exclude" = ?flags_exclude
491- ) ;
492-
493- #[ cfg( feature = "tracing" ) ]
494- span ! (
495- target: "CONFIG_HANDLING" ,
496- tracing:: Level :: TRACE ,
497- "normalizing and combining `flag.skip`/`flag.exclude` paths" ,
498- "config.skip" = ?config. skip,
499- ) ;
500-
501- config. include_default_paths = flags_include_default_paths;
502- config. rustc_error_format = flags_rustc_error_format;
503- config. json_output = flags_json_output;
504- config. compile_time_deps = flags_compile_time_deps;
505- config. on_fail = flags_on_fail;
506- config. cmd = flags_cmd;
507- config. incremental = flags_incremental;
508- config. set_dry_run ( if flags_dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ) ;
509- config. dump_bootstrap_shims = flags_dump_bootstrap_shims;
510- config. keep_stage = flags_keep_stage;
511- config. keep_stage_std = flags_keep_stage_std;
512- config. color = flags_color;
513- config. free_args = std:: mem:: take ( & mut flags_free_args) ;
514- config. llvm_profile_use = flags_llvm_profile_use;
515- config. llvm_profile_generate = flags_llvm_profile_generate;
516- config. enable_bolt_settings = flags_enable_bolt_settings;
517- config. bypass_bootstrap_lock = flags_bypass_bootstrap_lock;
518- config. is_running_on_ci = flags_ci. unwrap_or ( CiEnv :: is_ci ( ) ) ;
519- config. skip_std_check_if_no_download_rustc = flags_skip_std_check_if_no_download_rustc;
520-
521- // Infer the rest of the configuration.
522-
523- if cfg ! ( test) {
524- // Use the build directory of the original x.py invocation, so that we can set `initial_rustc` properly.
525- config. out = Path :: new (
526- & env:: var_os ( "CARGO_TARGET_DIR" ) . expect ( "cargo test directly is not supported" ) ,
527- )
528- . parent ( )
529- . unwrap ( )
530- . to_path_buf ( ) ;
531- }
532-
533- config. stage0_metadata = build_helper:: stage0_parser:: parse_stage0_file ( ) ;
534-
535480 if cfg ! ( test) {
536481 // When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
537482 // same ones used to call the tests (if custom ones are not defined in the toml). If we
@@ -543,11 +488,11 @@ impl Config {
543488 build. cargo = build. cargo . take ( ) . or ( std:: env:: var_os ( "CARGO" ) . map ( |p| p. into ( ) ) ) ;
544489 }
545490
546- config . change_id = toml . change_id . inner ;
547-
491+ // Now override TOML values with flags, to make sure that we won't later override flags with
492+ // TOML values by accident instead, because flags have higher priority.
548493 let Build {
549494 description,
550- build,
495+ mut build,
551496 host,
552497 target,
553498 build_dir,
@@ -594,14 +539,98 @@ impl Config {
594539 metrics : _,
595540 android_ndk,
596541 optimized_compiler_builtins,
597- jobs,
542+ mut jobs,
598543 compiletest_diff_tool,
599544 compiletest_allow_stage0,
600545 compiletest_use_stage0_libtest,
601546 tidy_extra_checks,
602547 ccache,
603548 exclude,
604549 } = toml. build . unwrap_or_default ( ) ;
550+ jobs = flags_jobs. or ( jobs) ;
551+ build = flags_build. or ( build) ;
552+ let build_dir = flags_build_dir. or ( build_dir. map ( PathBuf :: from) ) ;
553+ let host = if let Some ( TargetSelectionList ( hosts) ) = flags_host {
554+ Some ( hosts)
555+ } else if let Some ( file_host) = host {
556+ Some ( file_host. iter ( ) . map ( |h| TargetSelection :: from_user ( h) ) . collect ( ) )
557+ } else {
558+ None
559+ } ;
560+ let target = if let Some ( TargetSelectionList ( targets) ) = flags_target {
561+ Some ( targets)
562+ } else if let Some ( file_target) = target {
563+ Some ( file_target. iter ( ) . map ( |h| TargetSelection :: from_user ( h) ) . collect ( ) )
564+ } else {
565+ None
566+ } ;
567+
568+ if let Some ( rustc) = & rustc {
569+ if !flags_skip_stage0_validation {
570+ check_stage0_version ( & rustc, "rustc" , & config. src , config. exec_ctx ( ) ) ;
571+ }
572+ }
573+ if let Some ( cargo) = & cargo {
574+ if !flags_skip_stage0_validation {
575+ check_stage0_version ( & cargo, "cargo" , & config. src , config. exec_ctx ( ) ) ;
576+ }
577+ }
578+
579+ #[ cfg( feature = "tracing" ) ]
580+ span ! (
581+ target: "CONFIG_HANDLING" ,
582+ tracing:: Level :: TRACE ,
583+ "collecting paths and path exclusions" ,
584+ "flags.paths" = ?flags_paths,
585+ "flags.skip" = ?flags_skip,
586+ "flags.exclude" = ?flags_exclude
587+ ) ;
588+
589+ #[ cfg( feature = "tracing" ) ]
590+ span ! (
591+ target: "CONFIG_HANDLING" ,
592+ tracing:: Level :: TRACE ,
593+ "normalizing and combining `flag.skip`/`flag.exclude` paths" ,
594+ "config.skip" = ?config. skip,
595+ ) ;
596+
597+ // Set flags.
598+ config. paths = std:: mem:: take ( & mut flags_paths) ;
599+ config. include_default_paths = flags_include_default_paths;
600+ config. rustc_error_format = flags_rustc_error_format;
601+ config. json_output = flags_json_output;
602+ config. compile_time_deps = flags_compile_time_deps;
603+ config. on_fail = flags_on_fail;
604+ config. cmd = flags_cmd;
605+ config. incremental = flags_incremental;
606+ config. set_dry_run ( if flags_dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ) ;
607+ config. dump_bootstrap_shims = flags_dump_bootstrap_shims;
608+ config. keep_stage = flags_keep_stage;
609+ config. keep_stage_std = flags_keep_stage_std;
610+ config. color = flags_color;
611+ config. free_args = std:: mem:: take ( & mut flags_free_args) ;
612+ config. llvm_profile_use = flags_llvm_profile_use;
613+ config. llvm_profile_generate = flags_llvm_profile_generate;
614+ config. enable_bolt_settings = flags_enable_bolt_settings;
615+ config. bypass_bootstrap_lock = flags_bypass_bootstrap_lock;
616+ config. is_running_on_ci = flags_ci. unwrap_or ( CiEnv :: is_ci ( ) ) ;
617+ config. skip_std_check_if_no_download_rustc = flags_skip_std_check_if_no_download_rustc;
618+
619+ // Infer the rest of the configuration.
620+
621+ if cfg ! ( test) {
622+ // Use the build directory of the original x.py invocation, so that we can set `initial_rustc` properly.
623+ config. out = Path :: new (
624+ & env:: var_os ( "CARGO_TARGET_DIR" ) . expect ( "cargo test directly is not supported" ) ,
625+ )
626+ . parent ( )
627+ . unwrap ( )
628+ . to_path_buf ( ) ;
629+ }
630+
631+ config. stage0_metadata = build_helper:: stage0_parser:: parse_stage0_file ( ) ;
632+
633+ config. change_id = toml. change_id . inner ;
605634
606635 let mut paths: Vec < PathBuf > = flags_skip. into_iter ( ) . chain ( flags_exclude) . collect ( ) ;
607636
@@ -623,15 +652,12 @@ impl Config {
623652 } )
624653 . collect ( ) ;
625654
626- config. jobs = Some ( threads_from_config ( flags_jobs. unwrap_or ( jobs. unwrap_or ( 0 ) ) ) ) ;
627-
628- if let Some ( flags_build) = flags_build {
629- config. host_target = TargetSelection :: from_user ( & flags_build) ;
630- } else if let Some ( file_build) = build {
631- config. host_target = TargetSelection :: from_user ( & file_build) ;
632- } ;
655+ config. jobs = Some ( threads_from_config ( jobs. unwrap_or ( 0 ) ) ) ;
656+ if let Some ( build) = build {
657+ config. host_target = TargetSelection :: from_user ( & build) ;
658+ }
633659
634- set ( & mut config. out , flags_build_dir . or_else ( || build_dir. map ( PathBuf :: from ) ) ) ;
660+ set ( & mut config. out , build_dir) ;
635661 // NOTE: Bootstrap spawns various commands with different working directories.
636662 // To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
637663 if !config. out . is_absolute ( ) {
@@ -651,9 +677,6 @@ impl Config {
651677 toml. llvm . as_ref ( ) . is_some_and ( |llvm| llvm. assertions . unwrap_or ( false ) ) ;
652678
653679 config. initial_rustc = if let Some ( rustc) = rustc {
654- if !flags_skip_stage0_validation {
655- config. check_stage0_version ( & rustc, "rustc" ) ;
656- }
657680 rustc
658681 } else {
659682 let dwn_ctx = DownloadContext :: from ( & config) ;
@@ -678,9 +701,6 @@ impl Config {
678701 config. initial_cargo_clippy = cargo_clippy;
679702
680703 config. initial_cargo = if let Some ( cargo) = cargo {
681- if !flags_skip_stage0_validation {
682- config. check_stage0_version ( & cargo, "cargo" ) ;
683- }
684704 cargo
685705 } else {
686706 let dwn_ctx = DownloadContext :: from ( & config) ;
@@ -695,17 +715,9 @@ impl Config {
695715 config. out = dir;
696716 }
697717
698- config. hosts = if let Some ( TargetSelectionList ( arg_host) ) = flags_host {
699- arg_host
700- } else if let Some ( file_host) = host {
701- file_host. iter ( ) . map ( |h| TargetSelection :: from_user ( h) ) . collect ( )
702- } else {
703- vec ! [ config. host_target]
704- } ;
705- config. targets = if let Some ( TargetSelectionList ( arg_target) ) = flags_target {
706- arg_target
707- } else if let Some ( file_target) = target {
708- file_target. iter ( ) . map ( |h| TargetSelection :: from_user ( h) ) . collect ( )
718+ config. hosts = if let Some ( hosts) = host { hosts } else { vec ! [ config. host_target] } ;
719+ config. targets = if let Some ( targets) = target {
720+ targets
709721 } else {
710722 // If target is *not* configured, then default to the host
711723 // toolchains.
@@ -1812,49 +1824,6 @@ impl Config {
18121824 }
18131825 }
18141826
1815- #[ cfg( test) ]
1816- pub fn check_stage0_version ( & self , _program_path : & Path , _component_name : & ' static str ) { }
1817-
1818- /// check rustc/cargo version is same or lower with 1 apart from the building one
1819- #[ cfg( not( test) ) ]
1820- pub fn check_stage0_version ( & self , program_path : & Path , component_name : & ' static str ) {
1821- use build_helper:: util:: fail;
1822-
1823- if self . dry_run ( ) {
1824- return ;
1825- }
1826-
1827- let stage0_output =
1828- command ( program_path) . arg ( "--version" ) . run_capture_stdout ( self ) . stdout ( ) ;
1829- let mut stage0_output = stage0_output. lines ( ) . next ( ) . unwrap ( ) . split ( ' ' ) ;
1830-
1831- let stage0_name = stage0_output. next ( ) . unwrap ( ) ;
1832- if stage0_name != component_name {
1833- fail ( & format ! (
1834- "Expected to find {component_name} at {} but it claims to be {stage0_name}" ,
1835- program_path. display( )
1836- ) ) ;
1837- }
1838-
1839- let stage0_version =
1840- semver:: Version :: parse ( stage0_output. next ( ) . unwrap ( ) . split ( '-' ) . next ( ) . unwrap ( ) . trim ( ) )
1841- . unwrap ( ) ;
1842- let source_version = semver:: Version :: parse (
1843- fs:: read_to_string ( self . src . join ( "src/version" ) ) . unwrap ( ) . trim ( ) ,
1844- )
1845- . unwrap ( ) ;
1846- if !( source_version == stage0_version
1847- || ( source_version. major == stage0_version. major
1848- && ( source_version. minor == stage0_version. minor
1849- || source_version. minor == stage0_version. minor + 1 ) ) )
1850- {
1851- let prev_version = format ! ( "{}.{}.x" , source_version. major, source_version. minor - 1 ) ;
1852- fail ( & format ! (
1853- "Unexpected {component_name} version: {stage0_version}, we should use {prev_version}/{source_version} to build source with {source_version}"
1854- ) ) ;
1855- }
1856- }
1857-
18581827 /// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
18591828 pub fn download_ci_rustc_commit (
18601829 & self ,
@@ -2352,3 +2321,56 @@ fn postprocess_toml(
23522321 }
23532322 toml. merge ( None , & mut Default :: default ( ) , override_toml, ReplaceOpt :: Override ) ;
23542323}
2324+
2325+ #[ cfg( test) ]
2326+ pub fn check_stage0_version (
2327+ _program_path : & Path ,
2328+ _component_name : & ' static str ,
2329+ _src_dir : & Path ,
2330+ _exec_ctx : & ExecutionContext ,
2331+ ) {
2332+ }
2333+
2334+ /// check rustc/cargo version is same or lower with 1 apart from the building one
2335+ #[ cfg( not( test) ) ]
2336+ pub fn check_stage0_version (
2337+ program_path : & Path ,
2338+ component_name : & ' static str ,
2339+ src_dir : & Path ,
2340+ exec_ctx : & ExecutionContext ,
2341+ ) {
2342+ use build_helper:: util:: fail;
2343+
2344+ if exec_ctx. dry_run ( ) {
2345+ return ;
2346+ }
2347+
2348+ let stage0_output =
2349+ command ( program_path) . arg ( "--version" ) . run_capture_stdout ( exec_ctx) . stdout ( ) ;
2350+ let mut stage0_output = stage0_output. lines ( ) . next ( ) . unwrap ( ) . split ( ' ' ) ;
2351+
2352+ let stage0_name = stage0_output. next ( ) . unwrap ( ) ;
2353+ if stage0_name != component_name {
2354+ fail ( & format ! (
2355+ "Expected to find {component_name} at {} but it claims to be {stage0_name}" ,
2356+ program_path. display( )
2357+ ) ) ;
2358+ }
2359+
2360+ let stage0_version =
2361+ semver:: Version :: parse ( stage0_output. next ( ) . unwrap ( ) . split ( '-' ) . next ( ) . unwrap ( ) . trim ( ) )
2362+ . unwrap ( ) ;
2363+ let source_version =
2364+ semver:: Version :: parse ( fs:: read_to_string ( src_dir. join ( "src/version" ) ) . unwrap ( ) . trim ( ) )
2365+ . unwrap ( ) ;
2366+ if !( source_version == stage0_version
2367+ || ( source_version. major == stage0_version. major
2368+ && ( source_version. minor == stage0_version. minor
2369+ || source_version. minor == stage0_version. minor + 1 ) ) )
2370+ {
2371+ let prev_version = format ! ( "{}.{}.x" , source_version. major, source_version. minor - 1 ) ;
2372+ fail ( & format ! (
2373+ "Unexpected {component_name} version: {stage0_version}, we should use {prev_version}/{source_version} to build source with {source_version}"
2374+ ) ) ;
2375+ }
2376+ }
0 commit comments