@@ -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,55 @@ impl GitoxideFeatures {
935
983
internal_use_git2 : false ,
936
984
}
937
985
}
986
+
987
+ fn expecting ( ) -> String {
988
+ let fields = vec ! [ "'all'" , "'fetch'" , "'checkout'" , "'internal-use-git2'" ] ;
989
+ format ! (
990
+ "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`" ,
991
+ fields. join( " and " )
992
+ )
993
+ }
994
+ }
995
+
996
+ fn deserialize_gitoxide_features < ' de , D > (
997
+ deserializer : D ,
998
+ ) -> Result < Option < GitoxideFeatures > , D :: Error >
999
+ where
1000
+ D : serde:: de:: Deserializer < ' de > ,
1001
+ {
1002
+ struct GitoxideFeaturesVisitor ;
1003
+
1004
+ impl < ' de > serde:: de:: Visitor < ' de > for GitoxideFeaturesVisitor {
1005
+ type Value = Option < GitoxideFeatures > ;
1006
+
1007
+ fn expecting ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1008
+ formatter. write_str ( & GitoxideFeatures :: expecting ( ) )
1009
+ }
1010
+
1011
+ fn visit_str < E > ( self , s : & str ) -> Result < Self :: Value , E >
1012
+ where
1013
+ E : serde:: de:: Error ,
1014
+ {
1015
+ Ok ( parse_gitoxide ( s. split ( "," ) ) . map_err ( serde:: de:: Error :: custom) ?)
1016
+ }
1017
+
1018
+ fn visit_none < E > ( self ) -> Result < Self :: Value , E >
1019
+ where
1020
+ E : serde:: de:: Error ,
1021
+ {
1022
+ Ok ( None )
1023
+ }
1024
+
1025
+ fn visit_map < V > ( self , map : V ) -> Result < Self :: Value , V :: Error >
1026
+ where
1027
+ V : serde:: de:: MapAccess < ' de > ,
1028
+ {
1029
+ let mvd = serde:: de:: value:: MapAccessDeserializer :: new ( map) ;
1030
+ Ok ( Some ( GitoxideFeatures :: deserialize ( mvd) ?) )
1031
+ }
1032
+ }
1033
+
1034
+ deserializer. deserialize_any ( GitoxideFeaturesVisitor )
938
1035
}
939
1036
940
1037
fn parse_gitoxide (
@@ -949,11 +1046,12 @@ fn parse_gitoxide(
949
1046
950
1047
for e in it {
951
1048
match e. as_ref ( ) {
1049
+ "all" => return Ok ( Some ( GitoxideFeatures :: all ( ) ) ) ,
952
1050
"fetch" => * fetch = true ,
953
1051
"checkout" => * checkout = true ,
954
1052
"internal-use-git2" => * internal_use_git2 = true ,
955
1053
_ => {
956
- bail ! ( "unstable 'gitoxide' only takes `fetch` and 'checkout' as valid input, for shallow fetches see `-Zgit=shallow-index,shallow-deps`" )
1054
+ bail ! ( GitoxideFeatures :: expecting ( ) )
957
1055
}
958
1056
}
959
1057
}
0 commit comments