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 } ;
@@ -22,9 +20,7 @@ use crate::cc_detect::{ndk_compiler, Language};
22
20
use crate :: channel:: { self , GitInfo } ;
23
21
pub use crate :: flags:: Subcommand ;
24
22
use 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} ;
28
24
use crate :: util:: { exe, output, t} ;
29
25
use crate :: MinimalConfig ;
30
26
use once_cell:: sync:: OnceCell ;
@@ -391,14 +387,15 @@ impl Target {
391
387
target
392
388
}
393
389
}
390
+
394
391
/// Structure of the `config.toml` file that configuration is read from.
395
392
///
396
393
/// This structure uses `Decodable` to automatically decode a TOML configuration
397
394
/// file into this format, and then this is traversed and written into the above
398
395
/// `Config` structure.
399
396
#[ derive( Deserialize , Default ) ]
400
397
#[ serde( deny_unknown_fields, rename_all = "kebab-case" ) ]
401
- struct TomlConfig {
398
+ pub struct TomlConfig {
402
399
changelog_seen : Option < usize > ,
403
400
build : Option < Build > ,
404
401
install : Option < Install > ,
@@ -443,8 +440,8 @@ macro_rules! define_config {
443
440
$( $field: ident: Option <$field_ty: ty> = $field_key: literal, ) *
444
441
} ) => {
445
442
$( #[ $attr] ) *
446
- struct $name {
447
- $( $field: Option <$field_ty>, ) *
443
+ pub struct $name {
444
+ $( pub ( crate ) $field: Option <$field_ty>, ) *
448
445
}
449
446
450
447
impl Merge for $name {
@@ -526,7 +523,7 @@ macro_rules! define_config {
526
523
527
524
define_config ! {
528
525
/// TOML representation of various global build decisions.
529
- #[ derive( Default ) ]
526
+ #[ derive( Clone , Default ) ]
530
527
struct Build {
531
528
build: Option <String > = "build" ,
532
529
host: Option <Vec <String >> = "host" ,
@@ -632,7 +629,7 @@ define_config! {
632
629
633
630
#[ derive( Debug , Deserialize ) ]
634
631
#[ serde( untagged) ]
635
- enum StringOrBool {
632
+ pub ( crate ) enum StringOrBool {
636
633
String ( String ) ,
637
634
Bool ( bool ) ,
638
635
}
@@ -752,14 +749,6 @@ impl Config {
752
749
config. stdout_is_tty = std:: io:: stdout ( ) . is_terminal ( ) ;
753
750
config. stderr_is_tty = std:: io:: stderr ( ) . is_terminal ( ) ;
754
751
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
-
763
752
config
764
753
}
765
754
@@ -785,10 +774,19 @@ impl Config {
785
774
args
786
775
}
787
776
788
- pub fn parse ( args : & [ String ] ) -> Config {
777
+ pub fn parse ( args : & [ String ] , custom_toml_config : Option < TomlConfig > ) -> Config {
789
778
let mut flags = Flags :: parse ( & args) ;
790
779
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 ( ) ) ;
792
790
793
791
// Set flags.
794
792
config. paths = std:: mem:: take ( & mut flags. paths ) ;
@@ -800,7 +798,6 @@ impl Config {
800
798
config. jobs = Some ( threads_from_config ( flags. jobs as u32 ) ) ;
801
799
config. cmd = flags. cmd ;
802
800
config. incremental = flags. incremental ;
803
- config. dry_run = if flags. dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ;
804
801
config. keep_stage = flags. keep_stage ;
805
802
config. keep_stage_std = flags. keep_stage_std ;
806
803
config. color = flags. color ;
@@ -817,13 +814,10 @@ impl Config {
817
814
crate :: detail_exit ( 1 ) ;
818
815
}
819
816
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
+ } ;
827
821
828
822
if let Some ( include) = & toml. profile {
829
823
let mut include_path = config. src . clone ( ) ;
@@ -837,11 +831,6 @@ impl Config {
837
831
838
832
config. changelog_seen = toml. changelog_seen ;
839
833
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
-
845
834
set ( & mut config. out , flags. build_dir . or_else ( || build. build_dir . map ( PathBuf :: from) ) ) ;
846
835
// NOTE: Bootstrap spawns various commands with different working directories.
847
836
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -902,17 +891,13 @@ impl Config {
902
891
set ( & mut config. full_bootstrap , build. full_bootstrap ) ;
903
892
set ( & mut config. extended , build. extended ) ;
904
893
config. tools = build. tools ;
905
- set ( & mut config. verbose , build. verbose ) ;
906
894
set ( & mut config. sanitizers , build. sanitizers ) ;
907
895
set ( & mut config. profiler , build. profiler ) ;
908
896
set ( & mut config. cargo_native_static , build. cargo_native_static ) ;
909
897
set ( & mut config. configure_args , build. configure_args ) ;
910
898
set ( & mut config. local_rebuild , build. local_rebuild ) ;
911
899
set ( & mut config. print_step_timings , build. print_step_timings ) ;
912
900
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 ) ;
916
901
917
902
if let Some ( install) = toml. install {
918
903
config. prefix = install. prefix . map ( PathBuf :: from) ;
@@ -1526,7 +1511,7 @@ impl Config {
1526
1511
}
1527
1512
}
1528
1513
1529
- fn set < T > ( field : & mut T , val : Option < T > ) {
1514
+ pub ( crate ) fn set < T > ( field : & mut T , val : Option < T > ) {
1530
1515
if let Some ( v) = val {
1531
1516
* field = v;
1532
1517
}
0 commit comments