diff --git a/Cargo.lock b/Cargo.lock index f04b0d6d..f71651fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,7 +127,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cargo-ledger" -version = "1.5.1" +version = "1.6.0" dependencies = [ "cargo_metadata", "clap", diff --git a/cargo-ledger/Cargo.toml b/cargo-ledger/Cargo.toml index 6ab648d0..60634adb 100644 --- a/cargo-ledger/Cargo.toml +++ b/cargo-ledger/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cargo-ledger" -version = "1.5.1" -authors = ["yhql", "agrojean-ledger"] +version = "1.6.0" +authors = ["yhql", "agrojean-ledger", "y333"] description = "Build and sideload Ledger devices apps" categories = ["development-tools::cargo-plugins"] repository = "https://github.com/LedgerHQ/cargo-ledger" diff --git a/cargo-ledger/src/main.rs b/cargo-ledger/src/main.rs index b6b97feb..061319fd 100644 --- a/cargo-ledger/src/main.rs +++ b/cargo-ledger/src/main.rs @@ -16,29 +16,18 @@ use utils::*; mod setup; mod utils; -/// Structure for retrocompatibility, when the cargo manifest file -/// contains a single `[package.metadata.nanos]` section -#[derive(Debug, Deserialize)] -struct NanosMetadata { - curve: Vec, - path: Vec, - flags: String, - icon: String, - icon_small: String, - name: Option, -} - #[derive(Debug, Deserialize)] struct LedgerMetadata { curve: Vec, path: Vec, - flags: String, + flags: Option, name: Option, } #[derive(Debug, Deserialize)] struct DeviceMetadata { icon: String, + flags: Option, } #[derive(Parser, Debug)] @@ -123,7 +112,7 @@ fn main() { fn retrieve_metadata( device: Device, manifest_path: Option<&str>, -) -> (Package, LedgerMetadata, DeviceMetadata) { +) -> Result<(Package, LedgerMetadata, DeviceMetadata), ()> { let mut cmd = cargo_metadata::MetadataCommand::new(); // Only used during tests @@ -154,31 +143,10 @@ fn retrieve_metadata( serde_json::from_value(metadata_device) .expect("Could not deserialize device medatada"); - (this_pkg.clone(), ledger_metadata, device_metadata) + Ok((this_pkg.clone(), ledger_metadata, device_metadata)) } else { - println!("WARNING: 'package.metadata.ledger' section is missing in Cargo.toml, trying 'package.metadata.nanos'"); - let nanos_section = this_pkg.metadata.get("nanos").expect( - "No appropriate [package.metadata.] section found.", - ); - - let nanos_metadata: NanosMetadata = - serde_json::from_value(nanos_section.clone()) - .expect("Could not deserialize medatada.nanos"); - let ledger_metadata = LedgerMetadata { - curve: nanos_metadata.curve, - path: nanos_metadata.path, - flags: nanos_metadata.flags, - name: nanos_metadata.name, - }; - - let device_metadata = DeviceMetadata { - icon: match device { - Device::Nanos => nanos_metadata.icon, - _ => nanos_metadata.icon_small, - }, - }; - - (this_pkg.clone(), ledger_metadata, device_metadata) + println!("No metadata found for device: {}", device); + Err(()) } } @@ -263,7 +231,7 @@ fn build_app( }; let (this_pkg, metadata_ledger, metadata_device) = - retrieve_metadata(device, None); + retrieve_metadata(device, None).unwrap(); let package_path = this_pkg .manifest_path @@ -291,14 +259,21 @@ fn build_app( // Retrieve real data size and SDK infos from ELF let infos = retrieve_infos(&exe_path).unwrap(); - // Modify flags to enable BLE if targeting Nano X - let flags = match device { - Device::Nanos | Device::Nanosplus => metadata_ledger.flags, - Device::Nanox | Device::Stax | Device::Flex => { - let base = u32::from_str_radix(metadata_ledger.flags.as_str(), 16) - .unwrap_or(0); - format!("0x{:x}", base | 0x200) - } + let flags = match metadata_device.flags { + Some(flags) => flags, + None => match metadata_ledger.flags { + Some(flags) => match device { + // Modify flags to enable BLE if targeting Nano X + Device::Nanos | Device::Nanosplus => flags, + Device::Nanox | Device::Stax | Device::Flex => { + let base = + u32::from_str_radix(flags.trim_start_matches("0x"), 16) + .unwrap_or(0); + format!("0x{:x}", base | 0x200) + } + }, + None => String::from("0x000"), + }, }; // Target ID according to target, in case it