Skip to content

Commit 8f2b7b4

Browse files
authored
Merge pull request #172 from LedgerHQ/y333/update_cargo_ledger
Put json file used to sideload an app in target/ folder
2 parents f8afb3b + db41fb0 commit 8f2b7b4

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-ledger/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-ledger"
3-
version = "1.4.1"
3+
version = "1.5.0"
44
authors = ["yhql", "agrojean-ledger"]
55
description = "Build and sideload Ledger devices apps"
66
categories = ["development-tools::cargo-plugins"]

cargo-ledger/src/main.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ struct CliArgs {
5757
#[clap(value_name = "prebuilt ELF exe")]
5858
use_prebuilt: Option<PathBuf>,
5959

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-
6860
#[clap(subcommand)]
6961
command: MainCommand,
7062
}
@@ -123,7 +115,7 @@ fn main() {
123115
load: a,
124116
remaining_args: r,
125117
} => {
126-
build_app(d, a, cli.use_prebuilt, cli.hex_next_to_json, r);
118+
build_app(d, a, cli.use_prebuilt, r);
127119
}
128120
}
129121
}
@@ -194,7 +186,6 @@ fn build_app(
194186
device: Device,
195187
is_load: bool,
196188
use_prebuilt: Option<PathBuf>,
197-
hex_next_to_json: bool,
198189
remaining_args: Vec<String>,
199190
) {
200191
let exe_path = match use_prebuilt {
@@ -273,26 +264,29 @@ fn build_app(
273264

274265
let (this_pkg, metadata_ledger, metadata_device) =
275266
retrieve_metadata(device, None);
276-
let current_dir = this_pkg
267+
268+
let package_path = this_pkg
277269
.manifest_path
278270
.parent()
279271
.expect("Could not find package's parent path");
280272

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();
287284

288285
export_binary(&exe_path, &hex_file_abs);
289286

290-
// app.json will be placed in the app's root directory
287+
// app.json will be placed next to hex file
291288
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);
296290

297291
// Retrieve real data size and SDK infos from ELF
298292
let infos = retrieve_infos(&exe_path).unwrap();
@@ -341,6 +335,11 @@ fn build_app(
341335
}
342336
serde_json::to_writer_pretty(file, &json).unwrap();
343337

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+
344343
// Use ledgerctl to dump the APDU installation file.
345344
// Either dump to the location provided by the --out-dir cargo
346345
// argument if provided or use the default binary path.
@@ -366,13 +365,13 @@ fn build_app(
366365
.join(exe_filename.unwrap())
367366
.with_extension("apdu");
368367
dump_with_ledgerctl(
369-
current_dir,
368+
package_path,
370369
&app_json,
371370
apdu_file_path.to_str().unwrap(),
372371
);
373372

374373
if is_load {
375-
install_with_ledgerctl(current_dir, &app_json);
374+
install_with_ledgerctl(package_path, &app_json);
376375
}
377376
}
378377

0 commit comments

Comments
 (0)