@@ -15,7 +15,6 @@ use curl::multi::{EasyHandle, Multi};
15
15
use lazycell:: LazyCell ;
16
16
use log:: { debug, warn} ;
17
17
use semver:: Version ;
18
- use serde:: ser;
19
18
use serde:: Serialize ;
20
19
21
20
use crate :: core:: compiler:: { CompileKind , RustcTargetData } ;
@@ -77,94 +76,31 @@ impl PartialOrd for Package {
77
76
78
77
/// A Package in a form where `Serialize` can be derived.
79
78
#[ derive( Serialize ) ]
80
- struct SerializedPackage < ' a > {
81
- name : & ' a str ,
82
- version : & ' a Version ,
79
+ pub struct SerializedPackage {
80
+ name : InternedString ,
81
+ version : Version ,
83
82
id : PackageId ,
84
- license : Option < & ' a str > ,
85
- license_file : Option < & ' a str > ,
86
- description : Option < & ' a str > ,
83
+ license : Option < String > ,
84
+ license_file : Option < String > ,
85
+ description : Option < String > ,
87
86
source : SourceId ,
88
- dependencies : & ' a [ Dependency ] ,
89
- targets : Vec < & ' a Target > ,
90
- features : & ' a BTreeMap < InternedString , Vec < InternedString > > ,
91
- manifest_path : & ' a Path ,
92
- metadata : Option < & ' a toml:: Value > ,
93
- publish : Option < & ' a Vec < String > > ,
94
- authors : & ' a [ String ] ,
95
- categories : & ' a [ String ] ,
96
- keywords : & ' a [ String ] ,
97
- readme : Option < & ' a str > ,
98
- repository : Option < & ' a str > ,
99
- homepage : Option < & ' a str > ,
100
- documentation : Option < & ' a str > ,
101
- edition : & ' a str ,
102
- links : Option < & ' a str > ,
87
+ dependencies : Vec < Dependency > ,
88
+ targets : Vec < Target > ,
89
+ features : BTreeMap < InternedString , Vec < InternedString > > ,
90
+ manifest_path : PathBuf ,
91
+ metadata : Option < toml:: Value > ,
92
+ publish : Option < Vec < String > > ,
93
+ authors : Vec < String > ,
94
+ categories : Vec < String > ,
95
+ keywords : Vec < String > ,
96
+ readme : Option < String > ,
97
+ repository : Option < String > ,
98
+ homepage : Option < String > ,
99
+ documentation : Option < String > ,
100
+ edition : String ,
101
+ links : Option < String > ,
103
102
#[ serde( skip_serializing_if = "Option::is_none" ) ]
104
- metabuild : Option < & ' a Vec < String > > ,
105
- }
106
-
107
- impl ser:: Serialize for Package {
108
- fn serialize < S > ( & self , s : S ) -> Result < S :: Ok , S :: Error >
109
- where
110
- S : ser:: Serializer ,
111
- {
112
- let summary = self . manifest ( ) . summary ( ) ;
113
- let package_id = summary. package_id ( ) ;
114
- let manmeta = self . manifest ( ) . metadata ( ) ;
115
- let license = manmeta. license . as_deref ( ) ;
116
- let license_file = manmeta. license_file . as_deref ( ) ;
117
- let description = manmeta. description . as_deref ( ) ;
118
- let authors = manmeta. authors . as_ref ( ) ;
119
- let categories = manmeta. categories . as_ref ( ) ;
120
- let keywords = manmeta. keywords . as_ref ( ) ;
121
- let readme = manmeta. readme . as_deref ( ) ;
122
- let repository = manmeta. repository . as_deref ( ) ;
123
- let homepage = manmeta. homepage . as_ref ( ) . map ( String :: as_ref) ;
124
- let documentation = manmeta. documentation . as_ref ( ) . map ( String :: as_ref) ;
125
- // Filter out metabuild targets. They are an internal implementation
126
- // detail that is probably not relevant externally. There's also not a
127
- // real path to show in `src_path`, and this avoids changing the format.
128
- let targets: Vec < & Target > = self
129
- . manifest ( )
130
- . targets ( )
131
- . iter ( )
132
- . filter ( |t| t. src_path ( ) . is_path ( ) )
133
- . collect ( ) ;
134
- let empty_feats = BTreeMap :: new ( ) ;
135
- let features = self
136
- . manifest ( )
137
- . original ( )
138
- . features ( )
139
- . unwrap_or ( & empty_feats) ;
140
-
141
- SerializedPackage {
142
- name : & * package_id. name ( ) ,
143
- version : package_id. version ( ) ,
144
- id : package_id,
145
- license,
146
- license_file,
147
- description,
148
- source : summary. source_id ( ) ,
149
- dependencies : summary. dependencies ( ) ,
150
- targets,
151
- features,
152
- manifest_path : self . manifest_path ( ) ,
153
- metadata : self . manifest ( ) . custom_metadata ( ) ,
154
- authors,
155
- categories,
156
- keywords,
157
- readme,
158
- repository,
159
- homepage,
160
- documentation,
161
- edition : & self . manifest ( ) . edition ( ) . to_string ( ) ,
162
- links : self . manifest ( ) . links ( ) ,
163
- metabuild : self . manifest ( ) . metabuild ( ) ,
164
- publish : self . publish ( ) . as_ref ( ) ,
165
- }
166
- . serialize ( s)
167
- }
103
+ metabuild : Option < Vec < String > > ,
168
104
}
169
105
170
106
impl Package {
@@ -261,6 +197,69 @@ impl Package {
261
197
pub fn include_lockfile ( & self ) -> bool {
262
198
self . targets ( ) . iter ( ) . any ( |t| t. is_example ( ) || t. is_bin ( ) )
263
199
}
200
+
201
+ pub fn serialized ( & self , config : & Config ) -> SerializedPackage {
202
+ let summary = self . manifest ( ) . summary ( ) ;
203
+ let package_id = summary. package_id ( ) ;
204
+ let manmeta = self . manifest ( ) . metadata ( ) ;
205
+ // Filter out metabuild targets. They are an internal implementation
206
+ // detail that is probably not relevant externally. There's also not a
207
+ // real path to show in `src_path`, and this avoids changing the format.
208
+ let targets: Vec < Target > = self
209
+ . manifest ( )
210
+ . targets ( )
211
+ . iter ( )
212
+ . filter ( |t| t. src_path ( ) . is_path ( ) )
213
+ . cloned ( )
214
+ . collect ( ) ;
215
+ let features = if config. cli_unstable ( ) . namespaced_features {
216
+ // Convert Vec<FeatureValue> to Vec<InternedString>
217
+ summary
218
+ . features ( )
219
+ . iter ( )
220
+ . map ( |( k, v) | {
221
+ (
222
+ * k,
223
+ v. iter ( )
224
+ . map ( |fv| InternedString :: new ( & fv. to_string ( ) ) )
225
+ . collect ( ) ,
226
+ )
227
+ } )
228
+ . collect ( )
229
+ } else {
230
+ self . manifest ( )
231
+ . original ( )
232
+ . features ( )
233
+ . cloned ( )
234
+ . unwrap_or_default ( )
235
+ } ;
236
+
237
+ SerializedPackage {
238
+ name : package_id. name ( ) ,
239
+ version : package_id. version ( ) . clone ( ) ,
240
+ id : package_id,
241
+ license : manmeta. license . clone ( ) ,
242
+ license_file : manmeta. license_file . clone ( ) ,
243
+ description : manmeta. description . clone ( ) ,
244
+ source : summary. source_id ( ) ,
245
+ dependencies : summary. dependencies ( ) . to_vec ( ) ,
246
+ targets,
247
+ features,
248
+ manifest_path : self . manifest_path ( ) . to_path_buf ( ) ,
249
+ metadata : self . manifest ( ) . custom_metadata ( ) . cloned ( ) ,
250
+ authors : manmeta. authors . clone ( ) ,
251
+ categories : manmeta. categories . clone ( ) ,
252
+ keywords : manmeta. keywords . clone ( ) ,
253
+ readme : manmeta. readme . clone ( ) ,
254
+ repository : manmeta. repository . clone ( ) ,
255
+ homepage : manmeta. homepage . clone ( ) ,
256
+ documentation : manmeta. documentation . clone ( ) ,
257
+ edition : self . manifest ( ) . edition ( ) . to_string ( ) ,
258
+ links : self . manifest ( ) . links ( ) . map ( |s| s. to_owned ( ) ) ,
259
+ metabuild : self . manifest ( ) . metabuild ( ) . cloned ( ) ,
260
+ publish : self . publish ( ) . as_ref ( ) . cloned ( ) ,
261
+ }
262
+ }
264
263
}
265
264
266
265
impl fmt:: Display for Package {
0 commit comments