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 ;
@@ -388,14 +384,15 @@ impl Target {
388
384
target
389
385
}
390
386
}
387
+
391
388
/// Structure of the `config.toml` file that configuration is read from.
392
389
///
393
390
/// This structure uses `Decodable` to automatically decode a TOML configuration
394
391
/// file into this format, and then this is traversed and written into the above
395
392
/// `Config` structure.
396
393
#[ derive( Deserialize , Default ) ]
397
394
#[ serde( deny_unknown_fields, rename_all = "kebab-case" ) ]
398
- struct TomlConfig {
395
+ pub struct TomlConfig {
399
396
changelog_seen : Option < usize > ,
400
397
build : Option < Build > ,
401
398
install : Option < Install > ,
@@ -440,8 +437,8 @@ macro_rules! define_config {
440
437
$( $field: ident: Option <$field_ty: ty> = $field_key: literal, ) *
441
438
} ) => {
442
439
$( #[ $attr] ) *
443
- struct $name {
444
- $( $field: Option <$field_ty>, ) *
440
+ pub struct $name {
441
+ $( pub ( crate ) $field: Option <$field_ty>, ) *
445
442
}
446
443
447
444
impl Merge for $name {
@@ -523,7 +520,7 @@ macro_rules! define_config {
523
520
524
521
define_config ! {
525
522
/// TOML representation of various global build decisions.
526
- #[ derive( Default ) ]
523
+ #[ derive( Clone , Default ) ]
527
524
struct Build {
528
525
build: Option <String > = "build" ,
529
526
host: Option <Vec <String >> = "host" ,
@@ -629,7 +626,7 @@ define_config! {
629
626
630
627
#[ derive( Debug , Deserialize ) ]
631
628
#[ serde( untagged) ]
632
- enum StringOrBool {
629
+ pub ( crate ) enum StringOrBool {
633
630
String ( String ) ,
634
631
Bool ( bool ) ,
635
632
}
@@ -748,21 +745,22 @@ impl Config {
748
745
config. stdout_is_tty = std:: io:: stdout ( ) . is_terminal ( ) ;
749
746
config. stderr_is_tty = std:: io:: stderr ( ) . is_terminal ( ) ;
750
747
751
- // set by build.rs
752
- config. build = TargetSelection :: from_user ( & env ! ( "BUILD_TRIPLE" ) ) ;
753
-
754
- let manifest_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
755
- // Undo `src/bootstrap`
756
- config. src = manifest_dir. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_owned ( ) ;
757
- config. out = PathBuf :: from ( "build" ) ;
758
-
759
748
config
760
749
}
761
750
762
- pub fn parse ( args : & [ String ] ) -> Config {
751
+ pub fn parse ( args : & [ String ] , custom_toml_config : Option < TomlConfig > ) -> Config {
763
752
let flags = Flags :: parse ( & args) ;
764
753
let mut config = Config :: default_opts ( ) ;
765
- config. minimal_config = MinimalConfig :: parse ( flags. config . clone ( ) ) ;
754
+
755
+ let mut toml: TomlConfig = custom_toml_config. unwrap_or_else ( || {
756
+ set_cfg_path_and_return_toml_cfg (
757
+ config. src . clone ( ) ,
758
+ flags. config . clone ( ) ,
759
+ & mut config. config ,
760
+ )
761
+ } ) ;
762
+
763
+ config. minimal_config = MinimalConfig :: parse ( & flags, toml. build . clone ( ) ) ;
766
764
767
765
// Set flags.
768
766
config. exclude = flags. exclude . into_iter ( ) . map ( |path| TaskPath :: parse ( path) ) . collect ( ) ;
@@ -773,7 +771,6 @@ impl Config {
773
771
config. jobs = flags. jobs . map ( threads_from_config) ;
774
772
config. cmd = flags. cmd ;
775
773
config. incremental = flags. incremental ;
776
- config. dry_run = if flags. dry_run { DryRun :: UserSelected } else { DryRun :: Disabled } ;
777
774
config. keep_stage = flags. keep_stage ;
778
775
config. keep_stage_std = flags. keep_stage_std ;
779
776
config. color = flags. color ;
@@ -793,13 +790,10 @@ impl Config {
793
790
crate :: detail_exit ( 1 ) ;
794
791
}
795
792
796
- // Infer the rest of the configuration.
797
-
798
- set_config_output_dir ( & mut config. out ) ;
799
- config. stage0_metadata = deserialize_stage0_metadata ( & config. src ) ;
800
-
801
- let mut toml: TomlConfig =
802
- set_and_return_toml_config ( config. src . clone ( ) , flags. config , & mut config. config ) ;
793
+ let build = toml. build . clone ( ) . unwrap_or_default ( ) ;
794
+ if let Some ( file_build) = build. build . as_ref ( ) {
795
+ config. build = TargetSelection :: from_user ( file_build) ;
796
+ } ;
803
797
804
798
if let Some ( include) = & toml. profile {
805
799
let mut include_path = config. src . clone ( ) ;
@@ -813,11 +807,6 @@ impl Config {
813
807
814
808
config. changelog_seen = toml. changelog_seen ;
815
809
816
- let build = toml. build . unwrap_or_default ( ) ;
817
- if let Some ( file_build) = build. build {
818
- config. build = TargetSelection :: from_user ( & file_build) ;
819
- } ;
820
-
821
810
set ( & mut config. out , flags. build_dir . or_else ( || build. build_dir . map ( PathBuf :: from) ) ) ;
822
811
// NOTE: Bootstrap spawns various commands with different working directories.
823
812
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -875,17 +864,13 @@ impl Config {
875
864
set ( & mut config. full_bootstrap , build. full_bootstrap ) ;
876
865
set ( & mut config. extended , build. extended ) ;
877
866
config. tools = build. tools ;
878
- set ( & mut config. verbose , build. verbose ) ;
879
867
set ( & mut config. sanitizers , build. sanitizers ) ;
880
868
set ( & mut config. profiler , build. profiler ) ;
881
869
set ( & mut config. cargo_native_static , build. cargo_native_static ) ;
882
870
set ( & mut config. configure_args , build. configure_args ) ;
883
871
set ( & mut config. local_rebuild , build. local_rebuild ) ;
884
872
set ( & mut config. print_step_timings , build. print_step_timings ) ;
885
873
set ( & mut config. print_step_rusage , build. print_step_rusage ) ;
886
- set ( & mut config. patch_binaries_for_nix , build. patch_binaries_for_nix ) ;
887
-
888
- config. verbose = cmp:: max ( config. verbose , flags. verbose ) ;
889
874
890
875
if let Some ( install) = toml. install {
891
876
config. prefix = install. prefix . map ( PathBuf :: from) ;
@@ -1449,7 +1434,7 @@ impl Config {
1449
1434
}
1450
1435
}
1451
1436
1452
- fn set < T > ( field : & mut T , val : Option < T > ) {
1437
+ pub ( crate ) fn set < T > ( field : & mut T , val : Option < T > ) {
1453
1438
if let Some ( v) = val {
1454
1439
* field = v;
1455
1440
}
0 commit comments