@@ -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,7 @@ 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 ) ]
870
872
pub struct GitFeatures {
871
873
/// When cloning the index, perform a shallow clone. Maintain shallowness upon subsequent fetches.
872
874
pub shallow_index : bool ,
@@ -875,12 +877,59 @@ pub struct GitFeatures {
875
877
}
876
878
877
879
impl GitFeatures {
878
- fn all ( ) -> Self {
880
+ pub fn all ( ) -> Self {
879
881
GitFeatures {
880
882
shallow_index : true ,
881
883
shallow_deps : true ,
882
884
}
883
885
}
886
+
887
+ fn expecting ( ) -> String {
888
+ let fields = vec ! [ "'all'" , "'shallow-index'" , "'shallow-deps'" ] ;
889
+ format ! (
890
+ "unstable 'git' only takes {} as valid inputs, your can use 'all' to turn out all git features" ,
891
+ fields. join( " and " )
892
+ )
893
+ }
894
+ }
895
+
896
+ fn deserialize_git_features < ' de , D > ( deserializer : D ) -> Result < Option < GitFeatures > , D :: Error >
897
+ where
898
+ D : serde:: de:: Deserializer < ' de > ,
899
+ {
900
+ struct GitFeaturesVisitor ;
901
+
902
+ impl < ' de > serde:: de:: Visitor < ' de > for GitFeaturesVisitor {
903
+ type Value = Option < GitFeatures > ;
904
+
905
+ fn expecting ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
906
+ formatter. write_str ( & GitFeatures :: expecting ( ) )
907
+ }
908
+
909
+ fn visit_str < E > ( self , s : & str ) -> Result < Self :: Value , E >
910
+ where
911
+ E : serde:: de:: Error ,
912
+ {
913
+ Ok ( parse_git ( s. split ( "," ) ) . map_err ( serde:: de:: Error :: custom) ?)
914
+ }
915
+
916
+ fn visit_none < E > ( self ) -> Result < Self :: Value , E >
917
+ where
918
+ E : serde:: de:: Error ,
919
+ {
920
+ Ok ( None )
921
+ }
922
+
923
+ fn visit_map < V > ( self , map : V ) -> Result < Self :: Value , V :: Error >
924
+ where
925
+ V : serde:: de:: MapAccess < ' de > ,
926
+ {
927
+ let mvd = serde:: de:: value:: MapAccessDeserializer :: new ( map) ;
928
+ Ok ( Some ( GitFeatures :: deserialize ( mvd) ?) )
929
+ }
930
+ }
931
+
932
+ deserializer. deserialize_any ( GitFeaturesVisitor )
884
933
}
885
934
886
935
fn parse_git ( it : impl Iterator < Item = impl AsRef < str > > ) -> CargoResult < Option < GitFeatures > > {
@@ -892,19 +941,18 @@ fn parse_git(it: impl Iterator<Item = impl AsRef<str>>) -> CargoResult<Option<Gi
892
941
893
942
for e in it {
894
943
match e. as_ref ( ) {
944
+ "all" => return Ok ( Some ( GitFeatures :: all ( ) ) ) ,
895
945
"shallow-index" => * shallow_index = true ,
896
946
"shallow-deps" => * shallow_deps = true ,
897
947
_ => {
898
- bail ! (
899
- "unstable 'git' only takes 'shallow-index' and 'shallow-deps' as valid inputs"
900
- )
948
+ bail ! ( GitFeatures :: expecting( ) )
901
949
}
902
950
}
903
951
}
904
952
Ok ( Some ( out) )
905
953
}
906
954
907
- #[ derive( Debug , Copy , Clone , Default , Deserialize ) ]
955
+ #[ derive( Debug , Copy , Clone , Default , Deserialize , Ord , PartialOrd , Eq , PartialEq ) ]
908
956
pub struct GitoxideFeatures {
909
957
/// All fetches are done with `gitoxide`, which includes git dependencies as well as the crates index.
910
958
pub fetch : bool ,
@@ -918,7 +966,7 @@ pub struct GitoxideFeatures {
918
966
}
919
967
920
968
impl GitoxideFeatures {
921
- fn all ( ) -> Self {
969
+ pub fn all ( ) -> Self {
922
970
GitoxideFeatures {
923
971
fetch : true ,
924
972
checkout : true ,
@@ -935,6 +983,60 @@ impl GitoxideFeatures {
935
983
internal_use_git2 : false ,
936
984
}
937
985
}
986
+
987
+ fn expecting ( ) -> String {
988
+ let fields = vec ! [
989
+ "'all'" ,
990
+ "'fetch'" ,
991
+ "'checkout'" ,
992
+ "'internal-use-git2'" ,
993
+ ] ;
994
+ format ! (
995
+ "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`" ,
996
+ fields. join( " and " )
997
+ )
998
+ }
999
+ }
1000
+
1001
+ fn deserialize_gitoxide_features < ' de , D > (
1002
+ deserializer : D ,
1003
+ ) -> Result < Option < GitoxideFeatures > , D :: Error >
1004
+ where
1005
+ D : serde:: de:: Deserializer < ' de > ,
1006
+ {
1007
+ struct GitoxideFeaturesVisitor ;
1008
+
1009
+ impl < ' de > serde:: de:: Visitor < ' de > for GitoxideFeaturesVisitor {
1010
+ type Value = Option < GitoxideFeatures > ;
1011
+
1012
+ fn expecting ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1013
+ formatter. write_str ( & GitoxideFeatures :: expecting ( ) )
1014
+ }
1015
+
1016
+ fn visit_str < E > ( self , s : & str ) -> Result < Self :: Value , E >
1017
+ where
1018
+ E : serde:: de:: Error ,
1019
+ {
1020
+ Ok ( parse_gitoxide ( s. split ( "," ) ) . map_err ( serde:: de:: Error :: custom) ?)
1021
+ }
1022
+
1023
+ fn visit_none < E > ( self ) -> Result < Self :: Value , E >
1024
+ where
1025
+ E : serde:: de:: Error ,
1026
+ {
1027
+ Ok ( None )
1028
+ }
1029
+
1030
+ fn visit_map < V > ( self , map : V ) -> Result < Self :: Value , V :: Error >
1031
+ where
1032
+ V : serde:: de:: MapAccess < ' de > ,
1033
+ {
1034
+ let mvd = serde:: de:: value:: MapAccessDeserializer :: new ( map) ;
1035
+ Ok ( Some ( GitoxideFeatures :: deserialize ( mvd) ?) )
1036
+ }
1037
+ }
1038
+
1039
+ deserializer. deserialize_any ( GitoxideFeaturesVisitor )
938
1040
}
939
1041
940
1042
fn parse_gitoxide (
@@ -949,11 +1051,12 @@ fn parse_gitoxide(
949
1051
950
1052
for e in it {
951
1053
match e. as_ref ( ) {
1054
+ "all" => return Ok ( Some ( GitoxideFeatures :: all ( ) ) ) ,
952
1055
"fetch" => * fetch = true ,
953
1056
"checkout" => * checkout = true ,
954
1057
"internal-use-git2" => * internal_use_git2 = true ,
955
1058
_ => {
956
- bail ! ( "unstable 'gitoxide' only takes `fetch` and 'checkout' as valid input, for shallow fetches see `-Zgit=shallow-index,shallow-deps`" )
1059
+ bail ! ( GitoxideFeatures :: expecting ( ) )
957
1060
}
958
1061
}
959
1062
}
0 commit comments