@@ -2,7 +2,8 @@ use super::TestDatabase;
2
2
use crate :: docbuilder:: { BuildResult , DocCoverage } ;
3
3
use crate :: index:: api:: { CrateData , CrateOwner , ReleaseData } ;
4
4
use crate :: storage:: Storage ;
5
- use crate :: utils:: { Dependency , MetadataPackage , Target } ;
5
+ use crate :: utils:: { MetadataPackage , PackageExt } ;
6
+ use cargo_metadata:: PackageId ;
6
7
use chrono:: { DateTime , Utc } ;
7
8
use failure:: Error ;
8
9
use postgres:: Client ;
@@ -45,35 +46,35 @@ impl<'a> FakeRelease<'a> {
45
46
FakeRelease {
46
47
db,
47
48
storage,
48
- package : MetadataPackage {
49
- id : "fake-package-id" . into ( ) ,
50
- name : "fake-package" . into ( ) ,
51
- version : "1.0.0" . into ( ) ,
52
- license : Some ( "MIT" . into ( ) ) ,
53
- repository : Some ( "https://git.example.com" . into ( ) ) ,
54
- homepage : Some ( "https://www.example.com" . into ( ) ) ,
55
- description : Some ( "Fake package" . into ( ) ) ,
56
- documentation : Some ( "https://docs.example.com" . into ( ) ) ,
57
- dependencies : vec ! [ Dependency {
58
- name: "fake-dependency" . into ( ) ,
59
- req: "^1.0.0" . into ( ) ,
60
- kind: None ,
61
- rename: None ,
62
- optional: false ,
49
+ package : serde_json :: from_value ( serde_json :: json! ( {
50
+ "id" : "fake-package-id" ,
51
+ " name" : "fake-package" ,
52
+ " version" : "1.0.0" ,
53
+ " license" : "MIT" ,
54
+ " repository" : "https://git.example.com" ,
55
+ " homepage" : "https://www.example.com" ,
56
+ " description" : "Fake package" ,
57
+ " documentation" : "https://docs.example.com" ,
58
+ " dependencies" : [ {
59
+ " name" : "fake-dependency" ,
60
+ " req" : "^1.0.0" ,
61
+ " kind" : null ,
62
+ " rename" : null ,
63
+ " optional" : false
63
64
} ] ,
64
- targets : vec ! [ Target :: dummy_lib ( "fake_package" . into ( ) , None ) ] ,
65
- readme : None ,
66
- keywords : vec ! [ "fake" . into ( ) , "package" . into ( ) ] ,
67
- features : [
68
- ( "default" . into ( ) , vec ! [ "feature1" . into ( ) , "feature3" . into ( ) ] ) ,
69
- ( "feature1" . into ( ) , Vec :: new ( ) ) ,
70
- ( "feature2" . into ( ) , vec ! [ "feature1" . into ( ) ] ) ,
71
- ( "feature3" . into ( ) , Vec :: new ( ) ) ,
72
- ]
73
- . iter ( )
74
- . cloned ( )
75
- . collect :: < HashMap < String , Vec < String > > > ( ) ,
76
- } ,
65
+ " targets" : [ {
66
+ "name" : "fake_package"
67
+ } ] ,
68
+ "readme" : null ,
69
+ "keywords" : [ "fake" , "package" ] ,
70
+ "features" : {
71
+ "default" : [ "feature1" , "feature3" ] ,
72
+ "feature1" : [ ] ,
73
+ "feature2" : [ "feature1" ] ,
74
+ "feature3" : [ ]
75
+ }
76
+ } ) )
77
+ . unwrap ( ) ,
77
78
builds : vec ! [ ] ,
78
79
source_files : Vec :: new ( ) ,
79
80
rustdoc_files : Vec :: new ( ) ,
@@ -110,13 +111,15 @@ impl<'a> FakeRelease<'a> {
110
111
111
112
pub ( crate ) fn name ( mut self , new : & str ) -> Self {
112
113
self . package . name = new. into ( ) ;
113
- self . package . id = format ! ( "{}-id" , new) ;
114
+ self . package . id = PackageId {
115
+ repr : format ! ( "{}-id" , new) ,
116
+ } ;
114
117
self . package . targets [ 0 ] . name = new. into ( ) ;
115
118
self
116
119
}
117
120
118
121
pub ( crate ) fn version ( mut self , new : & str ) -> Self {
119
- self . package . version = new. into ( ) ;
122
+ self . package . version = cargo_metadata :: Version :: parse ( new) . expect ( "invalid semver" ) ;
120
123
self
121
124
}
122
125
@@ -191,7 +194,11 @@ impl<'a> FakeRelease<'a> {
191
194
pub ( crate ) fn add_platform < S : Into < String > > ( mut self , platform : S ) -> Self {
192
195
let platform = platform. into ( ) ;
193
196
let name = self . package . targets [ 0 ] . name . clone ( ) ;
194
- let target = Target :: dummy_lib ( name, Some ( platform. clone ( ) ) ) ;
197
+ let target = serde_json:: from_value ( serde_json:: json!( {
198
+ "name" : name,
199
+ "src_path" : platform. clone( )
200
+ } ) )
201
+ . unwrap ( ) ;
195
202
self . package . targets . push ( target) ;
196
203
self . doc_targets . push ( platform) ;
197
204
self
@@ -256,10 +263,10 @@ impl<'a> FakeRelease<'a> {
256
263
}
257
264
}
258
265
259
- let upload_files = |prefix : & str , files : & [ ( & str , & [ u8 ] ) ] , target : Option < & str > | {
266
+ let upload_files = |prefix : & str , files : & [ ( & str , & [ u8 ] ) ] , target : Option < & Path > | {
260
267
let mut path_prefix = tempdir. path ( ) . join ( prefix) ;
261
268
if let Some ( target) = target {
262
- path_prefix. push ( target) ;
269
+ path_prefix. push ( target. to_owned ( ) ) ;
263
270
}
264
271
fs:: create_dir ( & path_prefix) ?;
265
272
@@ -278,7 +285,7 @@ impl<'a> FakeRelease<'a> {
278
285
prefix,
279
286
package. name,
280
287
package. version,
281
- target. unwrap_or( "" )
288
+ target. unwrap_or( Path :: new ( "" ) ) . display ( )
282
289
) ;
283
290
log:: debug!( "adding directory {} from {}" , prefix, path_prefix. display( ) ) ;
284
291
crate :: db:: add_path_into_database ( & storage, & prefix, path_prefix)
@@ -304,9 +311,9 @@ impl<'a> FakeRelease<'a> {
304
311
log:: debug!( "added rustdoc files {}" , rustdoc_meta) ;
305
312
306
313
for target in & package. targets [ 1 ..] {
307
- let platform = target. src_path . as_ref ( ) . unwrap ( ) ;
314
+ let platform = & target. src_path ;
308
315
upload_files ( "rustdoc" , & rustdoc_files, Some ( platform) ) ?;
309
- log:: debug!( "added platform files for {}" , platform) ;
316
+ log:: debug!( "added platform files for {}" , platform. display ( ) ) ;
310
317
}
311
318
}
312
319
0 commit comments