@@ -37,28 +37,22 @@ struct TomlCrate {
37
37
38
38
/// Represents an archive we download from crates.io, or a git repo, or a local repo/folder
39
39
/// Once processed (downloaded/extracted/cloned/copied...), this will be translated into a `Crate`
40
+ #[ derive( Debug , Deserialize , Eq , Hash , PartialEq , Ord , PartialOrd ) ]
41
+ pub struct CrateWithSource {
42
+ pub name : String ,
43
+ pub source : CrateSource ,
44
+ pub options : Option < Vec < String > > ,
45
+ }
46
+
40
47
#[ derive( Debug , Deserialize , Eq , Hash , PartialEq , Ord , PartialOrd ) ]
41
48
pub enum CrateSource {
42
- CratesIo {
43
- name : String ,
44
- version : String ,
45
- options : Option < Vec < String > > ,
46
- } ,
47
- Git {
48
- name : String ,
49
- url : String ,
50
- commit : String ,
51
- options : Option < Vec < String > > ,
52
- } ,
53
- Path {
54
- name : String ,
55
- path : PathBuf ,
56
- options : Option < Vec < String > > ,
57
- } ,
49
+ CratesIo { version : String } ,
50
+ Git { url : String , commit : String } ,
51
+ Path { path : PathBuf } ,
58
52
}
59
53
60
54
/// Read a `lintcheck_crates.toml` file
61
- pub fn read_crates ( toml_path : & Path ) -> ( Vec < CrateSource > , RecursiveOptions ) {
55
+ pub fn read_crates ( toml_path : & Path ) -> ( Vec < CrateWithSource > , RecursiveOptions ) {
62
56
let toml_content: String =
63
57
fs:: read_to_string ( toml_path) . unwrap_or_else ( |_| panic ! ( "Failed to read {}" , toml_path. display( ) ) ) ;
64
58
let crate_list: SourceList =
@@ -71,23 +65,29 @@ pub fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
71
65
let mut crate_sources = Vec :: new ( ) ;
72
66
for tk in tomlcrates {
73
67
if let Some ( ref path) = tk. path {
74
- crate_sources. push ( CrateSource :: Path {
68
+ crate_sources. push ( CrateWithSource {
75
69
name : tk. name . clone ( ) ,
76
- path : PathBuf :: from ( path) ,
70
+ source : CrateSource :: Path {
71
+ path : PathBuf :: from ( path) ,
72
+ } ,
77
73
options : tk. options . clone ( ) ,
78
74
} ) ;
79
75
} else if let Some ( ref version) = tk. version {
80
- crate_sources. push ( CrateSource :: CratesIo {
76
+ crate_sources. push ( CrateWithSource {
81
77
name : tk. name . clone ( ) ,
82
- version : version. to_string ( ) ,
78
+ source : CrateSource :: CratesIo {
79
+ version : version. to_string ( ) ,
80
+ } ,
83
81
options : tk. options . clone ( ) ,
84
82
} ) ;
85
83
} else if tk. git_url . is_some ( ) && tk. git_hash . is_some ( ) {
86
84
// otherwise, we should have a git source
87
- crate_sources. push ( CrateSource :: Git {
85
+ crate_sources. push ( CrateWithSource {
88
86
name : tk. name . clone ( ) ,
89
- url : tk. git_url . clone ( ) . unwrap ( ) ,
90
- commit : tk. git_hash . clone ( ) . unwrap ( ) ,
87
+ source : CrateSource :: Git {
88
+ url : tk. git_url . clone ( ) . unwrap ( ) ,
89
+ commit : tk. git_hash . clone ( ) . unwrap ( ) ,
90
+ } ,
91
91
options : tk. options . clone ( ) ,
92
92
} ) ;
93
93
} else {
@@ -117,7 +117,7 @@ pub fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
117
117
( crate_sources, crate_list. recursive )
118
118
}
119
119
120
- impl CrateSource {
120
+ impl CrateWithSource {
121
121
/// Makes the sources available on the disk for clippy to check.
122
122
/// Clones a git repo and checks out the specified commit or downloads a crate from crates.io or
123
123
/// copies a local folder
@@ -139,8 +139,10 @@ impl CrateSource {
139
139
retries += 1 ;
140
140
}
141
141
}
142
- match self {
143
- CrateSource :: CratesIo { name, version, options } => {
142
+ let name = & self . name ;
143
+ let options = & self . options ;
144
+ match & self . source {
145
+ CrateSource :: CratesIo { version } => {
144
146
let extract_dir = PathBuf :: from ( LINTCHECK_SOURCES ) ;
145
147
let krate_download_dir = PathBuf :: from ( LINTCHECK_DOWNLOADS ) ;
146
148
@@ -173,12 +175,7 @@ impl CrateSource {
173
175
options : options. clone ( ) ,
174
176
}
175
177
} ,
176
- CrateSource :: Git {
177
- name,
178
- url,
179
- commit,
180
- options,
181
- } => {
178
+ CrateSource :: Git { url, commit } => {
182
179
let repo_path = {
183
180
let mut repo_path = PathBuf :: from ( LINTCHECK_SOURCES ) ;
184
181
// add a -git suffix in case we have the same crate from crates.io and a git repo
@@ -219,7 +216,7 @@ impl CrateSource {
219
216
options : options. clone ( ) ,
220
217
}
221
218
} ,
222
- CrateSource :: Path { name , path, options } => {
219
+ CrateSource :: Path { path } => {
223
220
fn is_cache_dir ( entry : & DirEntry ) -> bool {
224
221
fs:: read ( entry. path ( ) . join ( "CACHEDIR.TAG" ) )
225
222
. map ( |x| x. starts_with ( b"Signature: 8a477f597d28d172789f06886806bc55" ) )
0 commit comments