@@ -57,14 +57,6 @@ struct CliArgs {
57
57
#[ clap( value_name = "prebuilt ELF exe" ) ]
58
58
use_prebuilt : Option < PathBuf > ,
59
59
60
- #[ clap( long) ]
61
- #[ clap( help = concat!(
62
- "Should the app.hex be placed next to the app.json, or next to the input exe?" ,
63
- " " ,
64
- "Typically used with --use-prebuilt when the input exe is in a read-only location." ,
65
- ) ) ]
66
- hex_next_to_json : bool ,
67
-
68
60
#[ clap( subcommand) ]
69
61
command : MainCommand ,
70
62
}
@@ -123,7 +115,7 @@ fn main() {
123
115
load : a,
124
116
remaining_args : r,
125
117
} => {
126
- build_app ( d, a, cli. use_prebuilt , cli . hex_next_to_json , r) ;
118
+ build_app ( d, a, cli. use_prebuilt , r) ;
127
119
}
128
120
}
129
121
}
@@ -194,7 +186,6 @@ fn build_app(
194
186
device : Device ,
195
187
is_load : bool ,
196
188
use_prebuilt : Option < PathBuf > ,
197
- hex_next_to_json : bool ,
198
189
remaining_args : Vec < String > ,
199
190
) {
200
191
let exe_path = match use_prebuilt {
@@ -273,26 +264,29 @@ fn build_app(
273
264
274
265
let ( this_pkg, metadata_ledger, metadata_device) =
275
266
retrieve_metadata ( device, None ) ;
276
- let current_dir = this_pkg
267
+
268
+ let package_path = this_pkg
277
269
. manifest_path
278
270
. parent ( )
279
271
. expect ( "Could not find package's parent path" ) ;
280
272
281
- let hex_file_abs = if hex_next_to_json {
282
- current_dir
283
- } else {
284
- exe_path. parent ( ) . unwrap ( )
285
- }
286
- . join ( "app.hex" ) ;
273
+ /* exe_path = "exe_parent" + "exe_name" */
274
+ let exe_name = exe_path. file_name ( ) . unwrap ( ) ;
275
+ let exe_parent = exe_path. parent ( ) . unwrap ( ) ;
276
+
277
+ let hex_file_abs = exe_path
278
+ . parent ( )
279
+ . unwrap ( )
280
+ . join ( exe_name)
281
+ . with_extension ( "hex" ) ;
282
+
283
+ let hex_file = hex_file_abs. strip_prefix ( exe_parent) . unwrap ( ) ;
287
284
288
285
export_binary ( & exe_path, & hex_file_abs) ;
289
286
290
- // app.json will be placed in the app's root directory
287
+ // app.json will be placed next to hex file
291
288
let app_json_name = format ! ( "app_{}.json" , device. as_ref( ) ) ;
292
- let app_json = current_dir. join ( app_json_name) ;
293
-
294
- // Find hex file path relative to 'app.json'
295
- let hex_file = hex_file_abs. strip_prefix ( current_dir) . unwrap ( ) ;
289
+ let app_json = exe_parent. join ( app_json_name) ;
296
290
297
291
// Retrieve real data size and SDK infos from ELF
298
292
let infos = retrieve_infos ( & exe_path) . unwrap ( ) ;
@@ -341,6 +335,11 @@ fn build_app(
341
335
}
342
336
serde_json:: to_writer_pretty ( file, & json) . unwrap ( ) ;
343
337
338
+ // Copy icon to the same directory as the app.json
339
+ let icon_path = package_path. join ( & metadata_device. icon ) ;
340
+ let icon_dest = exe_parent. join ( & metadata_device. icon ) ;
341
+ fs:: copy ( icon_path, icon_dest) . unwrap ( ) ;
342
+
344
343
// Use ledgerctl to dump the APDU installation file.
345
344
// Either dump to the location provided by the --out-dir cargo
346
345
// argument if provided or use the default binary path.
@@ -366,13 +365,13 @@ fn build_app(
366
365
. join ( exe_filename. unwrap ( ) )
367
366
. with_extension ( "apdu" ) ;
368
367
dump_with_ledgerctl (
369
- current_dir ,
368
+ package_path ,
370
369
& app_json,
371
370
apdu_file_path. to_str ( ) . unwrap ( ) ,
372
371
) ;
373
372
374
373
if is_load {
375
- install_with_ledgerctl ( current_dir , & app_json) ;
374
+ install_with_ledgerctl ( package_path , & app_json) ;
376
375
}
377
376
}
378
377
0 commit comments