@@ -16,29 +16,18 @@ use utils::*;
16
16
mod setup;
17
17
mod utils;
18
18
19
- /// Structure for retrocompatibility, when the cargo manifest file
20
- /// contains a single `[package.metadata.nanos]` section
21
- #[ derive( Debug , Deserialize ) ]
22
- struct NanosMetadata {
23
- curve : Vec < String > ,
24
- path : Vec < String > ,
25
- flags : String ,
26
- icon : String ,
27
- icon_small : String ,
28
- name : Option < String > ,
29
- }
30
-
31
19
#[ derive( Debug , Deserialize ) ]
32
20
struct LedgerMetadata {
33
21
curve : Vec < String > ,
34
22
path : Vec < String > ,
35
- flags : String ,
23
+ flags : Option < String > ,
36
24
name : Option < String > ,
37
25
}
38
26
39
27
#[ derive( Debug , Deserialize ) ]
40
28
struct DeviceMetadata {
41
29
icon : String ,
30
+ flags : Option < String > ,
42
31
}
43
32
44
33
#[ derive( Parser , Debug ) ]
@@ -123,7 +112,7 @@ fn main() {
123
112
fn retrieve_metadata (
124
113
device : Device ,
125
114
manifest_path : Option < & str > ,
126
- ) -> ( Package , LedgerMetadata , DeviceMetadata ) {
115
+ ) -> Result < ( Package , LedgerMetadata , DeviceMetadata ) , ( ) > {
127
116
let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
128
117
129
118
// Only used during tests
@@ -154,31 +143,10 @@ fn retrieve_metadata(
154
143
serde_json:: from_value ( metadata_device)
155
144
. expect ( "Could not deserialize device medatada" ) ;
156
145
157
- ( this_pkg. clone ( ) , ledger_metadata, device_metadata)
146
+ Ok ( ( this_pkg. clone ( ) , ledger_metadata, device_metadata) )
158
147
} else {
159
- println ! ( "WARNING: 'package.metadata.ledger' section is missing in Cargo.toml, trying 'package.metadata.nanos'" ) ;
160
- let nanos_section = this_pkg. metadata . get ( "nanos" ) . expect (
161
- "No appropriate [package.metadata.<ledger|nanos>] section found." ,
162
- ) ;
163
-
164
- let nanos_metadata: NanosMetadata =
165
- serde_json:: from_value ( nanos_section. clone ( ) )
166
- . expect ( "Could not deserialize medatada.nanos" ) ;
167
- let ledger_metadata = LedgerMetadata {
168
- curve : nanos_metadata. curve ,
169
- path : nanos_metadata. path ,
170
- flags : nanos_metadata. flags ,
171
- name : nanos_metadata. name ,
172
- } ;
173
-
174
- let device_metadata = DeviceMetadata {
175
- icon : match device {
176
- Device :: Nanos => nanos_metadata. icon ,
177
- _ => nanos_metadata. icon_small ,
178
- } ,
179
- } ;
180
-
181
- ( this_pkg. clone ( ) , ledger_metadata, device_metadata)
148
+ println ! ( "No metadata found for device: {}" , device) ;
149
+ Err ( ( ) )
182
150
}
183
151
}
184
152
@@ -263,7 +231,7 @@ fn build_app(
263
231
} ;
264
232
265
233
let ( this_pkg, metadata_ledger, metadata_device) =
266
- retrieve_metadata ( device, None ) ;
234
+ retrieve_metadata ( device, None ) . unwrap ( ) ;
267
235
268
236
let package_path = this_pkg
269
237
. manifest_path
@@ -291,14 +259,21 @@ fn build_app(
291
259
// Retrieve real data size and SDK infos from ELF
292
260
let infos = retrieve_infos ( & exe_path) . unwrap ( ) ;
293
261
294
- // Modify flags to enable BLE if targeting Nano X
295
- let flags = match device {
296
- Device :: Nanos | Device :: Nanosplus => metadata_ledger. flags ,
297
- Device :: Nanox | Device :: Stax | Device :: Flex => {
298
- let base = u32:: from_str_radix ( metadata_ledger. flags . as_str ( ) , 16 )
299
- . unwrap_or ( 0 ) ;
300
- format ! ( "0x{:x}" , base | 0x200 )
301
- }
262
+ let flags = match metadata_device. flags {
263
+ Some ( flags) => flags,
264
+ None => match metadata_ledger. flags {
265
+ Some ( flags) => match device {
266
+ // Modify flags to enable BLE if targeting Nano X
267
+ Device :: Nanos | Device :: Nanosplus => flags,
268
+ Device :: Nanox | Device :: Stax | Device :: Flex => {
269
+ let base =
270
+ u32:: from_str_radix ( flags. trim_start_matches ( "0x" ) , 16 )
271
+ . unwrap_or ( 0 ) ;
272
+ format ! ( "0x{:x}" , base | 0x200 )
273
+ }
274
+ } ,
275
+ None => String :: from ( "0x000" ) ,
276
+ } ,
302
277
} ;
303
278
304
279
// Target ID according to target, in case it
0 commit comments