@@ -31,13 +31,15 @@ struct TomlCrate {
31
31
versions : Option < Vec < String > > ,
32
32
git_url : Option < String > ,
33
33
git_hash : Option < String > ,
34
+ path : Option < String > ,
34
35
}
35
36
36
- // represents an archive we download from crates.io
37
+ // represents an archive we download from crates.io, or a git repo, or a local repo
37
38
#[ derive( Debug , Serialize , Deserialize , Eq , Hash , PartialEq ) ]
38
39
enum CrateSource {
39
40
CratesIo { name : String , version : String } ,
40
41
Git { name : String , url : String , commit : String } ,
42
+ Path { name : String , path : PathBuf } ,
41
43
}
42
44
43
45
// represents the extracted sourcecode of a crate
@@ -111,7 +113,7 @@ impl CrateSource {
111
113
} ,
112
114
CrateSource :: Git { name, url, commit } => {
113
115
let repo_path = {
114
- let mut repo_path = PathBuf :: from ( "target/lintcheck/downloads " ) ;
116
+ let mut repo_path = PathBuf :: from ( "target/lintcheck/crates " ) ;
115
117
// add a -git suffix in case we have the same crate from crates.io and a git repo
116
118
repo_path. push ( format ! ( "{}-git" , name) ) ;
117
119
repo_path
@@ -139,6 +141,37 @@ impl CrateSource {
139
141
path : repo_path,
140
142
}
141
143
} ,
144
+ CrateSource :: Path { name, path } => {
145
+ use fs_extra:: dir;
146
+
147
+ // simply copy the entire directory into our target dir
148
+ let copy_dest = PathBuf :: from ( "target/lintcheck/crates/" ) ;
149
+
150
+ // the source path of the crate we copied, ${copy_dest}/crate_name
151
+ let crate_root = copy_dest. join ( name) ; // .../crates/local_crate
152
+
153
+ if !crate_root. exists ( ) {
154
+ println ! ( "Copying {} to {}" , path. display( ) , copy_dest. display( ) ) ;
155
+
156
+ dir:: copy ( path, & copy_dest, & dir:: CopyOptions :: new ( ) ) . expect ( & format ! (
157
+ "Failed to copy from {}, to {}" ,
158
+ path. display( ) ,
159
+ crate_root. display( )
160
+ ) ) ;
161
+ } else {
162
+ println ! (
163
+ "Not copying {} to {}, destination already exists" ,
164
+ path. display( ) ,
165
+ crate_root. display( )
166
+ ) ;
167
+ }
168
+
169
+ Crate {
170
+ version : String :: from ( "local" ) ,
171
+ name : name. clone ( ) ,
172
+ path : crate_root,
173
+ }
174
+ } ,
142
175
}
143
176
}
144
177
}
@@ -211,6 +244,13 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
211
244
// multiple Cratesources)
212
245
let mut crate_sources = Vec :: new ( ) ;
213
246
tomlcrates. into_iter ( ) . for_each ( |tk| {
247
+ if let Some ( ref path) = tk. path {
248
+ crate_sources. push ( CrateSource :: Path {
249
+ name : tk. name . clone ( ) ,
250
+ path : PathBuf :: from ( path) ,
251
+ } ) ;
252
+ }
253
+
214
254
// if we have multiple versions, save each one
215
255
if let Some ( ref versions) = tk. versions {
216
256
versions. iter ( ) . for_each ( |ver| {
@@ -234,7 +274,10 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
234
274
{
235
275
eprintln ! ( "tomlkrate: {:?}" , tk) ;
236
276
if tk. git_hash . is_some ( ) != tk. git_url . is_some ( ) {
237
- panic ! ( "Encountered TomlCrate with only one of git_hash and git_url!" )
277
+ panic ! ( "Error: Encountered TomlCrate with only one of git_hash and git_url!" ) ;
278
+ }
279
+ if tk. path . is_some ( ) && ( tk. git_hash . is_some ( ) || tk. versions . is_some ( ) ) {
280
+ panic ! ( "Error: TomlCrate can only have one of 'git_.*', 'version' or 'path' fields" ) ;
238
281
}
239
282
unreachable ! ( "Failed to translate TomlCrate into CrateSource!" ) ;
240
283
}
@@ -298,6 +341,7 @@ pub fn run(clap_config: &ArgMatches) {
298
341
let name = match krate {
299
342
CrateSource :: CratesIo { name, .. } => name,
300
343
CrateSource :: Git { name, .. } => name,
344
+ CrateSource :: Path { name, .. } => name,
301
345
} ;
302
346
name == only_one_crate
303
347
} ) {
0 commit comments