@@ -759,7 +759,9 @@ unstable_cli_options!(
759
759
dual_proc_macros: bool = ( "Build proc-macros for both the host and the target" ) ,
760
760
features: Option <Vec <String >>,
761
761
gc: bool = ( "Track cache usage and \" garbage collect\" unused files" ) ,
762
+ #[ serde( deserialize_with = "deserialize_git_features" ) ]
762
763
git: Option <GitFeatures > = ( "Enable support for shallow git fetch operations" ) ,
764
+ #[ serde( deserialize_with = "deserialize_gitoxide_features" ) ]
763
765
gitoxide: Option <GitoxideFeatures > = ( "Use gitoxide for the given git interactions, or all of them if no argument is given" ) ,
764
766
host_config: bool = ( "Enable the `[host]` section in the .cargo/config.toml file" ) ,
765
767
minimal_versions: bool = ( "Resolve minimal dependency versions instead of maximum" ) ,
@@ -866,7 +868,8 @@ where
866
868
) )
867
869
}
868
870
869
- #[ derive( Debug , Copy , Clone , Default , Deserialize ) ]
871
+ #[ derive( Debug , Copy , Clone , Default , Deserialize , Ord , PartialOrd , Eq , PartialEq ) ]
872
+ #[ serde( default ) ]
870
873
pub struct GitFeatures {
871
874
/// When cloning the index, perform a shallow clone. Maintain shallowness upon subsequent fetches.
872
875
pub shallow_index : bool ,
@@ -875,12 +878,71 @@ pub struct GitFeatures {
875
878
}
876
879
877
880
impl GitFeatures {
878
- fn all ( ) -> Self {
881
+ pub fn all ( ) -> Self {
879
882
GitFeatures {
880
883
shallow_index : true ,
881
884
shallow_deps : true ,
882
885
}
883
886
}
887
+
888
+ fn expecting ( ) -> String {
889
+ let fields = vec ! [ "'all'" , "'shallow-index'" , "'shallow-deps'" ] ;
890
+ format ! (
891
+ "unstable 'git' only takes {} as valid inputs, your can use 'all' to turn out all git features" ,
892
+ fields. join( " and " )
893
+ )
894
+ }
895
+ }
896
+
897
+ fn deserialize_git_features < ' de , D > ( deserializer : D ) -> Result < Option < GitFeatures > , D :: Error >
898
+ where
899
+ D : serde:: de:: Deserializer < ' de > ,
900
+ {
901
+ struct GitFeaturesVisitor ;
902
+
903
+ impl < ' de > serde:: de:: Visitor < ' de > for GitFeaturesVisitor {
904
+ type Value = Option < GitFeatures > ;
905
+
906
+ fn expecting ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
907
+ formatter. write_str ( & GitFeatures :: expecting ( ) )
908
+ }
909
+
910
+ fn visit_bool < E > ( self , v : bool ) -> Result < Self :: Value , E >
911
+ where
912
+ E : serde:: de:: Error ,
913
+ {
914
+ if v {
915
+ Ok ( Some ( GitFeatures :: all ( ) ) )
916
+ } else {
917
+ Ok ( None )
918
+ }
919
+ }
920
+
921
+ fn visit_str < E > ( self , s : & str ) -> Result < Self :: Value , E >
922
+ where
923
+ E : serde:: de:: Error ,
924
+ {
925
+ Ok ( parse_git ( s. split ( "," ) ) . map_err ( serde:: de:: Error :: custom) ?)
926
+ }
927
+
928
+ fn visit_some < D > ( self , deserializer : D ) -> Result < Self :: Value , D :: Error >
929
+ where
930
+ D : serde:: de:: Deserializer < ' de > ,
931
+ {
932
+ let git = GitFeatures :: deserialize ( deserializer) ?;
933
+ Ok ( Some ( git) )
934
+ }
935
+
936
+ fn visit_map < V > ( self , map : V ) -> Result < Self :: Value , V :: Error >
937
+ where
938
+ V : serde:: de:: MapAccess < ' de > ,
939
+ {
940
+ let mvd = serde:: de:: value:: MapAccessDeserializer :: new ( map) ;
941
+ Ok ( Some ( GitFeatures :: deserialize ( mvd) ?) )
942
+ }
943
+ }
944
+
945
+ deserializer. deserialize_any ( GitFeaturesVisitor )
884
946
}
885
947
886
948
fn parse_git ( it : impl Iterator < Item = impl AsRef < str > > ) -> CargoResult < Option < GitFeatures > > {
@@ -892,19 +954,19 @@ fn parse_git(it: impl Iterator<Item = impl AsRef<str>>) -> CargoResult<Option<Gi
892
954
893
955
for e in it {
894
956
match e. as_ref ( ) {
957
+ "all" => return Ok ( Some ( GitFeatures :: all ( ) ) ) ,
895
958
"shallow-index" => * shallow_index = true ,
896
959
"shallow-deps" => * shallow_deps = true ,
897
960
_ => {
898
- bail ! (
899
- "unstable 'git' only takes 'shallow-index' and 'shallow-deps' as valid inputs"
900
- )
961
+ bail ! ( GitFeatures :: expecting( ) )
901
962
}
902
963
}
903
964
}
904
965
Ok ( Some ( out) )
905
966
}
906
967
907
- #[ derive( Debug , Copy , Clone , Default , Deserialize ) ]
968
+ #[ derive( Debug , Copy , Clone , Default , Deserialize , Ord , PartialOrd , Eq , PartialEq ) ]
969
+ #[ serde( default ) ]
908
970
pub struct GitoxideFeatures {
909
971
/// All fetches are done with `gitoxide`, which includes git dependencies as well as the crates index.
910
972
pub fetch : bool ,
@@ -918,7 +980,7 @@ pub struct GitoxideFeatures {
918
980
}
919
981
920
982
impl GitoxideFeatures {
921
- fn all ( ) -> Self {
983
+ pub fn all ( ) -> Self {
922
984
GitoxideFeatures {
923
985
fetch : true ,
924
986
checkout : true ,
@@ -935,6 +997,67 @@ impl GitoxideFeatures {
935
997
internal_use_git2 : false ,
936
998
}
937
999
}
1000
+
1001
+ fn expecting ( ) -> String {
1002
+ let fields = vec ! [ "'all'" , "'fetch'" , "'checkout'" , "'internal-use-git2'" ] ;
1003
+ format ! (
1004
+ "unstable 'gitoxide' only takes {} as valid inputs, your can use 'all' to turn out all gitoxide features, for shallow fetches see `shallow-index,shallow-deps`" ,
1005
+ fields. join( " and " )
1006
+ )
1007
+ }
1008
+ }
1009
+
1010
+ fn deserialize_gitoxide_features < ' de , D > (
1011
+ deserializer : D ,
1012
+ ) -> Result < Option < GitoxideFeatures > , D :: Error >
1013
+ where
1014
+ D : serde:: de:: Deserializer < ' de > ,
1015
+ {
1016
+ struct GitoxideFeaturesVisitor ;
1017
+
1018
+ impl < ' de > serde:: de:: Visitor < ' de > for GitoxideFeaturesVisitor {
1019
+ type Value = Option < GitoxideFeatures > ;
1020
+
1021
+ fn expecting ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1022
+ formatter. write_str ( & GitoxideFeatures :: expecting ( ) )
1023
+ }
1024
+
1025
+ fn visit_str < E > ( self , s : & str ) -> Result < Self :: Value , E >
1026
+ where
1027
+ E : serde:: de:: Error ,
1028
+ {
1029
+ Ok ( parse_gitoxide ( s. split ( "," ) ) . map_err ( serde:: de:: Error :: custom) ?)
1030
+ }
1031
+
1032
+ fn visit_bool < E > ( self , v : bool ) -> Result < Self :: Value , E >
1033
+ where
1034
+ E : serde:: de:: Error ,
1035
+ {
1036
+ if v {
1037
+ Ok ( Some ( GitoxideFeatures :: all ( ) ) )
1038
+ } else {
1039
+ Ok ( None )
1040
+ }
1041
+ }
1042
+
1043
+ fn visit_some < D > ( self , deserializer : D ) -> Result < Self :: Value , D :: Error >
1044
+ where
1045
+ D : serde:: de:: Deserializer < ' de > ,
1046
+ {
1047
+ let gitoxide = GitoxideFeatures :: deserialize ( deserializer) ?;
1048
+ Ok ( Some ( gitoxide) )
1049
+ }
1050
+
1051
+ fn visit_map < V > ( self , map : V ) -> Result < Self :: Value , V :: Error >
1052
+ where
1053
+ V : serde:: de:: MapAccess < ' de > ,
1054
+ {
1055
+ let mvd = serde:: de:: value:: MapAccessDeserializer :: new ( map) ;
1056
+ Ok ( Some ( GitoxideFeatures :: deserialize ( mvd) ?) )
1057
+ }
1058
+ }
1059
+
1060
+ deserializer. deserialize_any ( GitoxideFeaturesVisitor )
938
1061
}
939
1062
940
1063
fn parse_gitoxide (
@@ -949,11 +1072,12 @@ fn parse_gitoxide(
949
1072
950
1073
for e in it {
951
1074
match e. as_ref ( ) {
1075
+ "all" => return Ok ( Some ( GitoxideFeatures :: all ( ) ) ) ,
952
1076
"fetch" => * fetch = true ,
953
1077
"checkout" => * checkout = true ,
954
1078
"internal-use-git2" => * internal_use_git2 = true ,
955
1079
_ => {
956
- bail ! ( "unstable 'gitoxide' only takes `fetch` and 'checkout' as valid input, for shallow fetches see `-Zgit=shallow-index,shallow-deps`" )
1080
+ bail ! ( GitoxideFeatures :: expecting ( ) )
957
1081
}
958
1082
}
959
1083
}
0 commit comments