77mod tests;
88
99use std:: cell:: { Cell , RefCell } ;
10- use std:: cmp;
1110use std:: collections:: { HashMap , HashSet } ;
12- use std:: env;
1311use std:: fs;
1412use std:: ops:: { Deref , DerefMut } ;
1513use std:: path:: { Path , PathBuf } ;
@@ -22,9 +20,7 @@ use crate::cc_detect::{ndk_compiler, Language};
2220use crate :: channel:: { self , GitInfo } ;
2321pub use crate :: flags:: Subcommand ;
2422use crate :: flags:: { Color , Flags , Warnings } ;
25- use crate :: min_config:: {
26- deserialize_stage0_metadata, get_toml, set_and_return_toml_config, set_config_output_dir,
27- } ;
23+ use crate :: min_config:: { get_toml, set_cfg_path_and_return_toml_cfg} ;
2824use crate :: util:: { exe, output, t} ;
2925use crate :: MinimalConfig ;
3026use once_cell:: sync:: OnceCell ;
@@ -391,14 +387,15 @@ impl Target {
391387 target
392388 }
393389}
390+
394391/// Structure of the `config.toml` file that configuration is read from.
395392///
396393/// This structure uses `Decodable` to automatically decode a TOML configuration
397394/// file into this format, and then this is traversed and written into the above
398395/// `Config` structure.
399396#[ derive( Deserialize , Default ) ]
400397#[ serde( deny_unknown_fields, rename_all = "kebab-case" ) ]
401- struct TomlConfig {
398+ pub struct TomlConfig {
402399 changelog_seen : Option < usize > ,
403400 build : Option < Build > ,
404401 install : Option < Install > ,
@@ -443,8 +440,8 @@ macro_rules! define_config {
443440 $( $field: ident: Option <$field_ty: ty> = $field_key: literal, ) *
444441 } ) => {
445442 $( #[ $attr] ) *
446- struct $name {
447- $( $field: Option <$field_ty>, ) *
443+ pub struct $name {
444+ $( pub ( crate ) $field: Option <$field_ty>, ) *
448445 }
449446
450447 impl Merge for $name {
@@ -526,7 +523,7 @@ macro_rules! define_config {
526523
527524define_config ! {
528525 /// TOML representation of various global build decisions.
529- #[ derive( Default ) ]
526+ #[ derive( Clone , Default ) ]
530527 struct Build {
531528 build: Option <String > = "build" ,
532529 host: Option <Vec <String >> = "host" ,
@@ -632,7 +629,7 @@ define_config! {
632629
633630#[ derive( Debug , Deserialize ) ]
634631#[ serde( untagged) ]
635- enum StringOrBool {
632+ pub ( crate ) enum StringOrBool {
636633 String ( String ) ,
637634 Bool ( bool ) ,
638635}
@@ -752,14 +749,6 @@ impl Config {
752749 config. stdout_is_tty = std:: io:: stdout ( ) . is_terminal ( ) ;
753750 config. stderr_is_tty = std:: io:: stderr ( ) . is_terminal ( ) ;
754751
755- // set by build.rs
756- config. build = TargetSelection :: from_user ( & env ! ( "BUILD_TRIPLE" ) ) ;
757-
758- let manifest_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
759- // Undo `src/bootstrap`
760- config. src = manifest_dir. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_owned ( ) ;
761- config. out = PathBuf :: from ( "build" ) ;
762-
763752 config
764753 }
765754
@@ -785,10 +774,19 @@ impl Config {
785774 args
786775 }
787776
788- pub fn parse ( args : & [ String ] ) -> Config {
777+ pub fn parse ( args : & [ String ] , custom_toml_config : Option < TomlConfig > ) -> Config {
789778 let mut flags = Flags :: parse ( & args) ;
790779 let mut config = Config :: default_opts ( ) ;
791- config. minimal_config = MinimalConfig :: parse ( flags. config . clone ( ) ) ;
780+
781+ let mut toml: TomlConfig = custom_toml_config. unwrap_or_else ( || {
782+ set_cfg_path_and_return_toml_cfg (
783+ config. src . clone ( ) ,
784+ flags. config . clone ( ) ,
785+ & mut config. config ,
786+ )
787+ } ) ;
788+
789+ config. minimal_config = MinimalConfig :: parse ( & flags, toml. build . clone ( ) ) ;
792790
793791 // Set flags.
794792 config. paths = std:: mem:: take ( & mut flags. paths ) ;
@@ -800,7 +798,6 @@ impl Config {
800798 config. jobs = Some ( threads_from_config ( flags. jobs as u32 ) ) ;
801799 config. cmd = flags. cmd ;
802800 config. incremental = flags. incremental ;
803- config. dry_run = if flags. dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ;
804801 config. keep_stage = flags. keep_stage ;
805802 config. keep_stage_std = flags. keep_stage_std ;
806803 config. color = flags. color ;
@@ -817,13 +814,10 @@ impl Config {
817814 crate :: detail_exit ( 1 ) ;
818815 }
819816
820- // Infer the rest of the configuration.
821-
822- set_config_output_dir ( & mut config. out ) ;
823- config. stage0_metadata = deserialize_stage0_metadata ( & config. src ) ;
824-
825- let mut toml: TomlConfig =
826- set_and_return_toml_config ( config. src . clone ( ) , flags. config , & mut config. config ) ;
817+ let build = toml. build . clone ( ) . unwrap_or_default ( ) ;
818+ if let Some ( file_build) = build. build . as_ref ( ) {
819+ config. build = TargetSelection :: from_user ( file_build) ;
820+ } ;
827821
828822 if let Some ( include) = & toml. profile {
829823 let mut include_path = config. src . clone ( ) ;
@@ -837,11 +831,6 @@ impl Config {
837831
838832 config. changelog_seen = toml. changelog_seen ;
839833
840- let build = toml. build . unwrap_or_default ( ) ;
841- if let Some ( file_build) = build. build {
842- config. build = TargetSelection :: from_user ( & file_build) ;
843- } ;
844-
845834 set ( & mut config. out , flags. build_dir . or_else ( || build. build_dir . map ( PathBuf :: from) ) ) ;
846835 // NOTE: Bootstrap spawns various commands with different working directories.
847836 // To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -902,17 +891,13 @@ impl Config {
902891 set ( & mut config. full_bootstrap , build. full_bootstrap ) ;
903892 set ( & mut config. extended , build. extended ) ;
904893 config. tools = build. tools ;
905- set ( & mut config. verbose , build. verbose ) ;
906894 set ( & mut config. sanitizers , build. sanitizers ) ;
907895 set ( & mut config. profiler , build. profiler ) ;
908896 set ( & mut config. cargo_native_static , build. cargo_native_static ) ;
909897 set ( & mut config. configure_args , build. configure_args ) ;
910898 set ( & mut config. local_rebuild , build. local_rebuild ) ;
911899 set ( & mut config. print_step_timings , build. print_step_timings ) ;
912900 set ( & mut config. print_step_rusage , build. print_step_rusage ) ;
913- set ( & mut config. patch_binaries_for_nix , build. patch_binaries_for_nix ) ;
914-
915- config. verbose = cmp:: max ( config. verbose , flags. verbose as usize ) ;
916901
917902 if let Some ( install) = toml. install {
918903 config. prefix = install. prefix . map ( PathBuf :: from) ;
@@ -1526,7 +1511,7 @@ impl Config {
15261511 }
15271512}
15281513
1529- fn set < T > ( field : & mut T , val : Option < T > ) {
1514+ pub ( crate ) fn set < T > ( field : & mut T , val : Option < T > ) {
15301515 if let Some ( v) = val {
15311516 * field = v;
15321517 }
0 commit comments