7
7
mod tests;
8
8
9
9
use std:: cell:: { Cell , RefCell } ;
10
- use std:: cmp;
11
10
use std:: collections:: { HashMap , HashSet } ;
12
- use std:: env;
13
11
use std:: fs;
14
12
use std:: ops:: { Deref , DerefMut } ;
15
13
use std:: path:: { Path , PathBuf } ;
@@ -21,9 +19,7 @@ use crate::cc_detect::{ndk_compiler, Language};
21
19
use crate :: channel:: { self , GitInfo } ;
22
20
pub use crate :: flags:: Subcommand ;
23
21
use crate :: flags:: { Color , Flags } ;
24
- use crate :: min_config:: {
25
- deserialize_stage0_metadata, get_toml, set_and_return_toml_config, set_config_output_dir,
26
- } ;
22
+ use crate :: min_config:: { get_toml, set_cfg_path_and_return_toml_cfg} ;
27
23
use crate :: util:: { exe, output, t} ;
28
24
use crate :: MinimalConfig ;
29
25
use once_cell:: sync:: OnceCell ;
@@ -387,14 +383,15 @@ impl Target {
387
383
target
388
384
}
389
385
}
386
+
390
387
/// Structure of the `config.toml` file that configuration is read from.
391
388
///
392
389
/// This structure uses `Decodable` to automatically decode a TOML configuration
393
390
/// file into this format, and then this is traversed and written into the above
394
391
/// `Config` structure.
395
392
#[ derive( Deserialize , Default ) ]
396
393
#[ serde( deny_unknown_fields, rename_all = "kebab-case" ) ]
397
- struct TomlConfig {
394
+ pub struct TomlConfig {
398
395
changelog_seen : Option < usize > ,
399
396
build : Option < Build > ,
400
397
install : Option < Install > ,
@@ -439,8 +436,8 @@ macro_rules! define_config {
439
436
$( $field: ident: Option <$field_ty: ty> = $field_key: literal, ) *
440
437
} ) => {
441
438
$( #[ $attr] ) *
442
- struct $name {
443
- $( $field: Option <$field_ty>, ) *
439
+ pub struct $name {
440
+ $( pub ( crate ) $field: Option <$field_ty>, ) *
444
441
}
445
442
446
443
impl Merge for $name {
@@ -522,7 +519,7 @@ macro_rules! define_config {
522
519
523
520
define_config ! {
524
521
/// TOML representation of various global build decisions.
525
- #[ derive( Default ) ]
522
+ #[ derive( Clone , Default ) ]
526
523
struct Build {
527
524
build: Option <String > = "build" ,
528
525
host: Option <Vec <String >> = "host" ,
@@ -628,7 +625,7 @@ define_config! {
628
625
629
626
#[ derive( Debug , Deserialize ) ]
630
627
#[ serde( untagged) ]
631
- enum StringOrBool {
628
+ pub ( crate ) enum StringOrBool {
632
629
String ( String ) ,
633
630
Bool ( bool ) ,
634
631
}
@@ -745,21 +742,22 @@ impl Config {
745
742
config. stdout_is_tty = atty:: is ( atty:: Stream :: Stdout ) ;
746
743
config. stderr_is_tty = atty:: is ( atty:: Stream :: Stderr ) ;
747
744
748
- // set by build.rs
749
- config. build = TargetSelection :: from_user ( & env ! ( "BUILD_TRIPLE" ) ) ;
750
-
751
- let manifest_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
752
- // Undo `src/bootstrap`
753
- config. src = manifest_dir. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_owned ( ) ;
754
- config. out = PathBuf :: from ( "build" ) ;
755
-
756
745
config
757
746
}
758
747
759
- pub fn parse ( args : & [ String ] ) -> Config {
748
+ pub fn parse ( args : & [ String ] , custom_toml_config : Option < TomlConfig > ) -> Config {
760
749
let flags = Flags :: parse ( & args) ;
761
750
let mut config = Config :: default_opts ( ) ;
762
- config. minimal_config = MinimalConfig :: parse ( flags. config . clone ( ) ) ;
751
+
752
+ let mut toml: TomlConfig = custom_toml_config. unwrap_or_else ( || {
753
+ set_cfg_path_and_return_toml_cfg (
754
+ config. src . clone ( ) ,
755
+ flags. config . clone ( ) ,
756
+ & mut config. config ,
757
+ )
758
+ } ) ;
759
+
760
+ config. minimal_config = MinimalConfig :: parse ( & flags, toml. build . clone ( ) ) ;
763
761
764
762
// Set flags.
765
763
config. exclude = flags. exclude . into_iter ( ) . map ( |path| TaskPath :: parse ( path) ) . collect ( ) ;
@@ -770,7 +768,6 @@ impl Config {
770
768
config. jobs = flags. jobs . map ( threads_from_config) ;
771
769
config. cmd = flags. cmd ;
772
770
config. incremental = flags. incremental ;
773
- config. dry_run = if flags. dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ;
774
771
config. keep_stage = flags. keep_stage ;
775
772
config. keep_stage_std = flags. keep_stage_std ;
776
773
config. color = flags. color ;
@@ -790,13 +787,10 @@ impl Config {
790
787
crate :: detail_exit ( 1 ) ;
791
788
}
792
789
793
- // Infer the rest of the configuration.
794
-
795
- set_config_output_dir ( & mut config. out ) ;
796
- config. stage0_metadata = deserialize_stage0_metadata ( & config. src ) ;
797
-
798
- let mut toml: TomlConfig =
799
- set_and_return_toml_config ( config. src . clone ( ) , flags. config , & mut config. config ) ;
790
+ let build = toml. build . clone ( ) . unwrap_or_default ( ) ;
791
+ if let Some ( file_build) = build. build . as_ref ( ) {
792
+ config. build = TargetSelection :: from_user ( file_build) ;
793
+ } ;
800
794
801
795
if let Some ( include) = & toml. profile {
802
796
let mut include_path = config. src . clone ( ) ;
@@ -810,11 +804,6 @@ impl Config {
810
804
811
805
config. changelog_seen = toml. changelog_seen ;
812
806
813
- let build = toml. build . unwrap_or_default ( ) ;
814
- if let Some ( file_build) = build. build {
815
- config. build = TargetSelection :: from_user ( & file_build) ;
816
- } ;
817
-
818
807
set ( & mut config. out , flags. build_dir . or_else ( || build. build_dir . map ( PathBuf :: from) ) ) ;
819
808
// NOTE: Bootstrap spawns various commands with different working directories.
820
809
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -872,17 +861,13 @@ impl Config {
872
861
set ( & mut config. full_bootstrap , build. full_bootstrap ) ;
873
862
set ( & mut config. extended , build. extended ) ;
874
863
config. tools = build. tools ;
875
- set ( & mut config. verbose , build. verbose ) ;
876
864
set ( & mut config. sanitizers , build. sanitizers ) ;
877
865
set ( & mut config. profiler , build. profiler ) ;
878
866
set ( & mut config. cargo_native_static , build. cargo_native_static ) ;
879
867
set ( & mut config. configure_args , build. configure_args ) ;
880
868
set ( & mut config. local_rebuild , build. local_rebuild ) ;
881
869
set ( & mut config. print_step_timings , build. print_step_timings ) ;
882
870
set ( & mut config. print_step_rusage , build. print_step_rusage ) ;
883
- set ( & mut config. patch_binaries_for_nix , build. patch_binaries_for_nix ) ;
884
-
885
- config. verbose = cmp:: max ( config. verbose , flags. verbose ) ;
886
871
887
872
if let Some ( install) = toml. install {
888
873
config. prefix = install. prefix . map ( PathBuf :: from) ;
@@ -1446,7 +1431,7 @@ impl Config {
1446
1431
}
1447
1432
}
1448
1433
1449
- fn set < T > ( field : & mut T , val : Option < T > ) {
1434
+ pub ( crate ) fn set < T > ( field : & mut T , val : Option < T > ) {
1450
1435
if let Some ( v) = val {
1451
1436
* field = v;
1452
1437
}
0 commit comments