From 312c115f5505304abeaa55924bc48c114fa6026f Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Wed, 3 Aug 2022 10:11:49 -0700 Subject: [PATCH] Check if a new version if available upon invocation --- Cargo.lock | 287 +++++++++++++++++++++++++++++++++++++ cargo-espflash/src/main.rs | 7 +- espflash/Cargo.toml | 5 +- espflash/src/cli/mod.rs | 12 ++ espflash/src/main.rs | 8 +- 5 files changed, 310 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e23b72de..16660bd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,6 +93,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "binread" version = "2.2.0" @@ -142,6 +148,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bumpalo" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" + [[package]] name = "bytemuck" version = "1.11.0" @@ -231,6 +243,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chunked_transfer" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" + [[package]] name = "clap" version = "3.2.16" @@ -417,6 +435,15 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "directories" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210" +dependencies = [ + "dirs-sys", +] + [[package]] name = "directories-next" version = "2.0.0" @@ -427,6 +454,17 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -480,6 +518,7 @@ dependencies = [ "strum_macros", "thiserror", "toml", + "update-informer", "xmas-elf", ] @@ -525,6 +564,16 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + [[package]] name = "generic-array" version = "0.14.6" @@ -578,6 +627,17 @@ dependencies = [ "libc", ] +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.9.1" @@ -635,6 +695,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +[[package]] +name = "js-sys" +version = "0.3.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -710,6 +779,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + [[package]] name = "maybe-uninit" version = "2.0.0" @@ -891,6 +966,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + [[package]] name = "pkg-config" version = "0.3.25" @@ -991,12 +1072,39 @@ dependencies = [ "winapi", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + [[package]] name = "rustc-demangle" version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +[[package]] +name = "rustls" +version = "0.20.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + [[package]] name = "rustversion" version = "1.0.9" @@ -1015,6 +1123,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "semver" version = "1.0.13" @@ -1202,6 +1320,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -1345,6 +1469,21 @@ dependencies = [ "syn", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "toml" version = "0.5.9" @@ -1360,6 +1499,12 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + [[package]] name = "unicode-ident" version = "1.0.3" @@ -1375,12 +1520,71 @@ dependencies = [ "regex", ] +[[package]] +name = "unicode-normalization" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "update-informer" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f154aee470c0882ea0f3b1cc2a46c5f4d24f282655f7b0cec065614fe24c447f" +dependencies = [ + "directories", + "semver", + "serde", + "serde_json", + "ureq", +] + +[[package]] +name = "ureq" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97acb4c28a254fd7a4aeec976c46a7fa404eac4d7c134b30c75144846d7cb8f" +dependencies = [ + "base64", + "chunked_transfer", + "flate2", + "log", + "once_cell", + "rustls", + "serde", + "serde_json", + "url", + "webpki", + "webpki-roots", +] + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + [[package]] name = "version_check" version = "0.9.4" @@ -1393,6 +1597,89 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" + +[[package]] +name = "web-sys" +version = "0.3.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" +dependencies = [ + "webpki", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/cargo-espflash/src/main.rs b/cargo-espflash/src/main.rs index 56562577..23ca6fd8 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -9,8 +9,9 @@ use cargo_metadata::Message; use clap::Parser; use espflash::{ cli::{ - board_info, connect, flash_elf_image, monitor::monitor, partition_table, save_elf_as_image, - serial_monitor, ConnectOpts, FlashConfigOpts, FlashOpts, PartitionTableOpts, + board_info, check_for_updates, connect, flash_elf_image, monitor::monitor, partition_table, + save_elf_as_image, serial_monitor, ConnectOpts, FlashConfigOpts, FlashOpts, + PartitionTableOpts, }, Chip, Config, ImageFormatId, }; @@ -122,6 +123,8 @@ pub struct SaveImageOpts { fn main() -> Result<()> { miette::set_panic_hook(); + check_for_updates(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + let CargoSubCommand::Espflash(opts) = Opts::parse().subcommand; let config = Config::load()?; diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml index 9f5826cb..0e51fa3e 100644 --- a/espflash/Cargo.toml +++ b/espflash/Cargo.toml @@ -28,10 +28,6 @@ pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ target }.{ archive bin-dir = "{ bin }{ binary-ext }" pkg-fmt = "zip" -[[bin]] -name = "espflash" -path = "src/main.rs" - [dependencies] binread = "2.2" bytemuck = { version = "1.11", features = ["derive"] } @@ -59,4 +55,5 @@ strum = "0.24" strum_macros = "0.24" thiserror = "1.0" toml = "0.5" +update-informer = "0.5" xmas-elf = "0.8" diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index 5b9f7971..5335313c 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -7,6 +7,7 @@ use std::{ io::{Read, Write}, num::ParseIntError, path::{Path, PathBuf}, + time::Duration, }; use clap::Parser; @@ -14,6 +15,7 @@ use config::Config; use miette::{IntoDiagnostic, Result, WrapErr}; use serialport::{FlowControl, SerialPortType, UsbPortInfo}; use strum::VariantNames; +use update_informer::{registry, Check}; use crate::{ cli::monitor::monitor, @@ -364,3 +366,13 @@ pub fn write_bin_to_flash(opts: WriteBinToFlashOpts) -> Result<()> { Ok(()) } + +pub fn check_for_updates(name: &str, version: &str) { + const NO_INTERVAL: Duration = Duration::from_secs(0); + + let informer = update_informer::new(registry::Crates, name, version).interval(NO_INTERVAL); + + if let Some(version) = informer.check_version().ok().flatten() { + println!("New version of {name} is available: {version}\n"); + } +} diff --git a/espflash/src/main.rs b/espflash/src/main.rs index 6b8a8293..ae5c1e22 100644 --- a/espflash/src/main.rs +++ b/espflash/src/main.rs @@ -3,9 +3,9 @@ use std::{fs, mem::swap, path::PathBuf, str::FromStr}; use clap::{IntoApp, Parser}; use espflash::{ cli::{ - board_info, connect, flash_elf_image, monitor::monitor, partition_table, save_elf_as_image, - serial_monitor, write_bin_to_flash, ConnectOpts, FlashConfigOpts, FlashOpts, - PartitionTableOpts, WriteBinToFlashOpts, + board_info, check_for_updates, connect, flash_elf_image, monitor::monitor, partition_table, + save_elf_as_image, serial_monitor, write_bin_to_flash, ConnectOpts, FlashConfigOpts, + FlashOpts, PartitionTableOpts, WriteBinToFlashOpts, }, Chip, Config, ImageFormatId, }; @@ -73,6 +73,8 @@ pub struct SaveImageOpts { fn main() -> Result<()> { miette::set_panic_hook(); + check_for_updates(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + let mut opts = Opts::parse(); let config = Config::load()?;