From 79b9b4edbfe25bfa6b8bdd139d9100b88c648b3d Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 11 Aug 2022 16:32:13 +0000 Subject: [PATCH] Improve param parsing --- Cargo.lock | 783 +++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/config.rs | 24 +- src/idf.rs | 376 +++++++++++++++--------- src/main.rs | 115 ++++++-- 5 files changed, 1131 insertions(+), 168 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cfe91b1..f1fe1ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,41 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "CoreFoundation-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0e9889e6db118d49d88d84728d0e964d973a5680befb5f85f55141beea5c20b" +dependencies = [ + "libc", + "mach 0.1.2", +] + +[[package]] +name = "IOKit-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99696c398cbaf669d2368076bdb3d627fb0ce51a26899d7c61228c5c0af3bf4a" +dependencies = [ + "CoreFoundation-sys", + "libc", + "mach 0.1.2", +] + +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "cpp_demangle", + "fallible-iterator", + "gimli", + "object 0.27.1", + "rustc-demangle", + "smallvec 1.9.0", +] + [[package]] name = "adler" version = "1.0.2" @@ -20,6 +55,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + [[package]] name = "android_system_properties" version = "0.1.4" @@ -44,6 +88,15 @@ version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "508b352bb5c066aac251f6daf6b36eccd03e8a88e8081cd44959ea277a3af9a8" +[[package]] +name = "array-init" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72" +dependencies = [ + "nodrop", +] + [[package]] name = "atty" version = "0.2.14" @@ -61,6 +114,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object 0.29.0", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.0" @@ -73,6 +141,28 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" +[[package]] +name = "binread" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16598dfc8e6578e9b597d9910ba2e73618385dc9f4b1d43dd92c349d6be6418f" +dependencies = [ + "binread_derive", + "rustversion", +] + +[[package]] +name = "binread_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d9672209df1714ee804b1f4d4f68c8eb2a90b1f7a07acf472f88ce198ef1fed" +dependencies = [ + "either", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -88,12 +178,44 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5377c8865e74a160d21f29c2d40669f53286db6eab59b88540cbb12ffc8b835" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfd2f4180c5721da6335cc9e9061cce522b87a35e51cc57636d28d22a9863c80" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "byteorder" version = "1.4.3" @@ -273,6 +395,32 @@ dependencies = [ "syn", ] +[[package]] +name = "comfy-table" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121d8a5b0346092c18a4b2fd6f620d7a06f0eb7ac0a45860939a0884bc579c56" +dependencies = [ + "crossterm 0.23.2", + "strum", + "strum_macros", + "unicode-width", +] + +[[package]] +name = "console" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89eab4d20ce20cea182308bca13088fecea9c05f6776cf287205d41a0ed3c847" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "terminal_size", + "unicode-width", + "winapi 0.3.9", +] + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -295,6 +443,15 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "cpp_demangle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "cpufeatures" version = "0.2.2" @@ -323,6 +480,47 @@ dependencies = [ "once_cell", ] +[[package]] +name = "crossterm" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2102ea4f781910f8a5b98dd061f4c2023f479ce7bb1236330099ceb5a93cf17" +dependencies = [ + "bitflags", + "crossterm_winapi", + "libc", + "mio 0.8.4", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi 0.3.9", +] + +[[package]] +name = "crossterm" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9f7409c70a38a56216480fba371ee460207dd8926ccf5b4160591759559170" +dependencies = [ + "bitflags", + "crossterm_winapi", + "libc", + "mio 0.8.4", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi 0.3.9", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -333,6 +531,39 @@ dependencies = [ "typenum", ] +[[package]] +name = "csv" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" +dependencies = [ + "bstr", + "csv-core", + "itoa 0.4.8", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + +[[package]] +name = "dialoguer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92e7e37ecef6857fdc0c0c5d42fd5b0938e46590c2183cc92dd310a6d078eb1" +dependencies = [ + "console", + "tempfile", + "zeroize", +] + [[package]] name = "digest" version = "0.10.3" @@ -344,6 +575,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "directories-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + [[package]] name = "dirs" version = "4.0.0" @@ -364,6 +605,29 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi 0.3.9", +] + +[[package]] +name = "either" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.31" @@ -402,6 +666,7 @@ dependencies = [ "clap 3.2.16", "clap-nested", "dirs", + "espflash", "flate2", "git2", "guess_host_triple", @@ -420,6 +685,64 @@ dependencies = [ "zip", ] +[[package]] +name = "espflash" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e53813f2e332902487ddd35f6c2b325cea2756ea5377ae939dd689a2212509ad" +dependencies = [ + "binread", + "bytemuck", + "clap 3.2.16", + "comfy-table", + "crossterm 0.24.0", + "csv", + "dialoguer", + "directories-next", + "espmonitor", + "flate2", + "indicatif", + "maplit", + "md5", + "miette", + "parse_int", + "regex", + "serde", + "serde-hex", + "serde_plain", + "serialport", + "sha2", + "slip-codec", + "strum", + "strum_macros", + "thiserror", + "toml", + "xmas-elf", +] + +[[package]] +name = "espmonitor" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d8108f9eddda1613b8c558a3bf0a363187e743f9b4825613dd924b9f422e6d" +dependencies = [ + "addr2line", + "clap 3.2.16", + "crossterm 0.23.2", + "gimli", + "lazy_static", + "nix", + "object 0.27.1", + "regex", + "serial", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fastrand" version = "1.8.0" @@ -608,6 +931,17 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + [[package]] name = "git2" version = "0.15.0" @@ -789,6 +1123,18 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indicatif" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d207dc617c7a380ab07ff572a6e52fa202a2a8f355860ac9c38e23f8196be1b" +dependencies = [ + "console", + "lazy_static", + "number_prefix", + "regex", +] + [[package]] name = "instant" version = "0.1.12" @@ -798,6 +1144,15 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "ioctl-rs" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7970510895cee30b3e9128319f2cefd4bde883a39f38baa279567ba3a7eb97d" +dependencies = [ + "libc", +] + [[package]] name = "iovec" version = "0.1.4" @@ -813,6 +1168,12 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +[[package]] +name = "is_ci" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" + [[package]] name = "itoa" version = "0.4.8" @@ -899,6 +1260,26 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libudev" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b324152da65df7bb95acfcaab55e3097ceaab02fb19b228a9eb74d55f135e0" +dependencies = [ + "libc", + "libudev-sys", +] + +[[package]] +name = "libudev-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "libz-sys" version = "1.1.8" @@ -941,12 +1322,42 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "mach" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd13ee2dd61cc82833ba05ade5a30bb3d63f7ced605ef827063c63078302de9" +dependencies = [ + "libc", +] + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "maplit" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + [[package]] name = "md5" version = "0.7.0" @@ -959,6 +1370,46 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miette" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28d6092d7e94a90bb9ea8e6c26c99d5d112d49dda2afdb4f7ea8cf09e1a5a6d" +dependencies = [ + "atty", + "backtrace", + "miette-derive", + "once_cell", + "owo-colors", + "supports-color", + "supports-hyperlinks", + "supports-unicode", + "terminal_size", + "textwrap 0.15.0", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2485ed7d1fe80704928e3eb86387439609bd0c6bb96db8208daa364cfd1e09" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "mime" version = "0.3.16" @@ -1056,6 +1507,24 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nix" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "libc", + "memoffset", +] + +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + [[package]] name = "num-integer" version = "0.1.45" @@ -1094,6 +1563,31 @@ dependencies = [ "libc", ] +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] +name = "object" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" +dependencies = [ + "flate2", + "memchr", +] + +[[package]] +name = "object" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.13.0" @@ -1157,6 +1651,12 @@ version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +[[package]] +name = "owo-colors" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1176,10 +1676,19 @@ dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall", - "smallvec", + "smallvec 1.9.0", "windows-sys", ] +[[package]] +name = "parse_int" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d695b79916a2c08bcff7be7647ab60d1402885265005a6658ffe6d763553c5a" +dependencies = [ + "num-traits", +] + [[package]] name = "password-hash" version = "0.3.2" @@ -1321,6 +1830,29 @@ dependencies = [ "thiserror", ] +[[package]] +name = "regex" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + +[[package]] +name = "regex-syntax" +version = "0.6.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -1365,6 +1897,18 @@ dependencies = [ "winreg 0.7.0", ] +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + +[[package]] +name = "rustversion" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" + [[package]] name = "ryu" version = "1.0.11" @@ -1428,6 +1972,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-hex" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca37e3e4d1b39afd7ff11ee4e947efae85adfddf4841787bfa47c470e96dc26d" +dependencies = [ + "array-init", + "serde", + "smallvec 0.6.14", +] + [[package]] name = "serde_derive" version = "1.0.143" @@ -1450,6 +2005,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_plain" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95455e7e29fada2052e72170af226fbe368a4ca33dee847875325d9fdb133858" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1462,6 +2026,65 @@ dependencies = [ "serde", ] +[[package]] +name = "serial" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1237a96570fc377c13baa1b88c7589ab66edced652e43ffb17088f003db3e86" +dependencies = [ + "serial-core", + "serial-unix", + "serial-windows", +] + +[[package]] +name = "serial-core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f46209b345401737ae2125fe5b19a77acce90cd53e1658cda928e4fe9a64581" +dependencies = [ + "libc", +] + +[[package]] +name = "serial-unix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f03fbca4c9d866e24a459cbca71283f545a37f8e3e002ad8c70593871453cab7" +dependencies = [ + "ioctl-rs", + "libc", + "serial-core", + "termios", +] + +[[package]] +name = "serial-windows" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15c6d3b776267a75d31bbdfd5d36c0ca051251caafc285827052bc53bcdc8162" +dependencies = [ + "libc", + "serial-core", +] + +[[package]] +name = "serialport" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aab92efb5cf60ad310548bc3f16fa6b0d950019cb7ed8ff41968c3d03721cf12" +dependencies = [ + "CoreFoundation-sys", + "IOKit-sys", + "bitflags", + "cfg-if 1.0.0", + "libudev", + "mach 0.3.2", + "nix", + "regex", + "winapi 0.3.9", +] + [[package]] name = "sha1" version = "0.10.1" @@ -1484,6 +2107,27 @@ dependencies = [ "digest", ] +[[package]] +name = "signal-hook" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio 0.8.4", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1502,12 +2146,33 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slip-codec" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f79a64a7c3cf9c25da0e0ef422db7ba3694b58b2e218692cb9f5c47fbaaff4" + +[[package]] +name = "smallvec" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" +dependencies = [ + "maybe-uninit", +] + [[package]] name = "smallvec" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +[[package]] +name = "smawk" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" + [[package]] name = "socket2" version = "0.3.19" @@ -1529,6 +2194,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "strsim" version = "0.8.0" @@ -1541,12 +2212,59 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "subtle" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +[[package]] +name = "supports-color" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4872ced36b91d47bae8a214a683fe54e7078875b399dfa251df346c9b547d1f9" +dependencies = [ + "atty", + "is_ci", +] + +[[package]] +name = "supports-hyperlinks" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "590b34f7c5f01ecc9d78dba4b3f445f31df750a67621cf31626f3b7441ce6406" +dependencies = [ + "atty", +] + +[[package]] +name = "supports-unicode" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8b945e45b417b125a8ec51f1b7df2f8df7920367700d1f98aedd21e5735f8b2" +dependencies = [ + "atty", +] + [[package]] name = "syn" version = "1.0.99" @@ -1592,6 +2310,25 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "termios" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5d9cf598a6d7ce700a4e6a9199da127e6819a61e64b68609683cc9a01b5683a" +dependencies = [ + "libc", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -1606,6 +2343,11 @@ name = "textwrap" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +dependencies = [ + "smawk", + "unicode-linebreak", + "unicode-width", +] [[package]] name = "thiserror" @@ -1745,6 +2487,15 @@ dependencies = [ "tokio 0.2.25", ] +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] + [[package]] name = "tower-service" version = "0.3.2" @@ -1815,6 +2566,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +[[package]] +name = "unicode-linebreak" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a52dcaab0c48d931f7cc8ef826fa51690a08e1ea55117ef26f89864f532383f" +dependencies = [ + "regex", +] + [[package]] name = "unicode-normalization" version = "0.1.21" @@ -2116,6 +2876,15 @@ dependencies = [ "libc", ] +[[package]] +name = "xmas-elf" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d29b4d8e7beaceb4e77447ba941a7600d23d0319ab52da0461abea214832d5a" +dependencies = [ + "zero", +] + [[package]] name = "xz2" version = "0.1.7" @@ -2125,6 +2894,18 @@ dependencies = [ "lzma-sys", ] +[[package]] +name = "zero" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5" + +[[package]] +name = "zeroize" +version = "1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" + [[package]] name = "zip" version = "0.6.2" diff --git a/Cargo.toml b/Cargo.toml index 95fdad1..0eafead 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ widestring = "1.0.2" winapi = { version = "*", features = ["setupapi", "handleapi", "processthreadsapi", "winnt", "securitybaseapi", "impl-default", "shellapi", "winuser"] } zip = "*" xz2 = "0.1.6" +espflash = "1.6.0" [target.'cfg(windows)'.dependencies] winreg = "0.10.1" diff --git a/src/config.rs b/src/config.rs index b9b4523..7bce212 100644 --- a/src/config.rs +++ b/src/config.rs @@ -113,20 +113,20 @@ pub fn update_property(property_name: String, property_value: String) { fs::write(get_json_path(), format!("{:#}", parsed_json)).unwrap(); } -pub fn add_idf_config(idf_path: String, version: String, python_path: String) { - let idf_id = get_idf_id(&idf_path); - let _data = json::object! { - version: version, - python: python_path, - path: idf_path - }; +// pub fn add_idf_config(idf_path: String, version: String, python_path: String) { +// let idf_id = get_idf_id(&idf_path); +// let _data = json::object! { +// version: version, +// python: python_path, +// path: idf_path +// }; - let mut parsed_json = load_json(); - parsed_json["idfInstalled"].insert(&idf_id, _data).unwrap(); - parsed_json["idfSelectedId"] = JsonValue::String(idf_id); +// let mut parsed_json = load_json(); +// parsed_json["idfInstalled"].insert(&idf_id, _data).unwrap(); +// parsed_json["idfSelectedId"] = JsonValue::String(idf_id); - fs::write(get_json_path(), format!("{:#}", parsed_json)).unwrap(); -} +// fs::write(get_json_path(), format!("{:#}", parsed_json)).unwrap(); +// } // pub fn get_cmd<'a>() -> Command<'a, str> { // Command::new("get") diff --git a/src/idf.rs b/src/idf.rs index 717c859..97f42d3 100644 --- a/src/idf.rs +++ b/src/idf.rs @@ -1,25 +1,27 @@ use clap::Arg; use clap_nested::{Command, Commander, MultiCommand}; -use git2::{Repository}; +use git2::Repository; use std::path::Path; -use tokio::{runtime::Handle}; +use tokio::runtime::Handle; type Result = std::result::Result>; use std::env; -use std::process::Stdio; use std::io::Read; +use std::process::Stdio; -use std::time::{Instant}; +use std::time::Instant; -use crate::config::{add_idf_config, get_git_path, get_tool_path, get_dist_path, get_python_env_path, update_property}; -use crate::config::get_tools_path; use crate::config::get_selected_idf_path; +use crate::config::get_tools_path; +use crate::config::{ + get_dist_path, get_git_path, get_python_env_path, get_tool_path, update_property, +}; use crate::package::prepare_package; use crate::shell::run_command; use dirs::home_dir; -async fn excecute_async(command: String, arguments:Vec){ +async fn excecute_async(command: String, arguments: Vec) { let _child_process = tokio::process::Command::new(command) .args(arguments) .status() @@ -27,12 +29,14 @@ async fn excecute_async(command: String, arguments:Vec){ } fn execute_command(command: String, arguments: Vec) -> Result<()> { - let argument_string = arguments.clone().into_iter().map(|i| format!("{} ", i.to_string())).collect::(); + let argument_string = arguments + .clone() + .into_iter() + .map(|i| format!("{} ", i.to_string())) + .collect::(); println!("Executing: {} {}", command, argument_string); let handle = Handle::current().clone(); - let th = std::thread::spawn(move || { - handle.block_on(excecute_async(command, arguments)) - }); + let th = std::thread::spawn(move || handle.block_on(excecute_async(command, arguments))); th.join().unwrap(); Ok(()) } @@ -69,7 +73,12 @@ fn reset_repository(repository_path: String) -> Result<()> { Ok(()) } -fn update_submodule(idf_path: String, submodule: String, depth: String, progress: bool) -> Result<()> { +fn update_submodule( + idf_path: String, + submodule: String, + depth: String, + progress: bool, +) -> Result<()> { let mut arguments_submodule: Vec = [].to_vec(); arguments_submodule.push("-C".to_string()); arguments_submodule.push(idf_path); @@ -114,34 +123,47 @@ fn get_idf_base_directory() -> String { } #[cfg(windows)] -fn get_esp_idf_directory(idf_name:String) -> String { +fn get_esp_idf_directory(idf_name: String) -> String { format!("{}/{}", get_idf_base_directory(), idf_name).replace("/", "\\") } #[cfg(unix)] -fn get_esp_idf_directory(idf_name:String) -> String { +fn get_esp_idf_directory(idf_name: String) -> String { format!("{}/{}", get_idf_base_directory(), idf_name) } -fn get_install_runner(_args: &str, _matches: &clap::ArgMatches) -> std::result::Result<(), clap::Error> { +fn get_install_runner( + _args: &str, + _matches: &clap::ArgMatches, +) -> std::result::Result<(), clap::Error> { let esp_idf = get_esp_idf_directory("esp-idf-master/".to_string()); println!("ESP-IDF Path: {}", esp_idf); #[cfg(windows)] - match prepare_package("https://dl.espressif.com/dl/idf-git/idf-git-2.30.1-win64.zip".to_string(), + match prepare_package( + "https://dl.espressif.com/dl/idf-git/idf-git-2.30.1-win64.zip".to_string(), get_dist_path("idf-git-2.30.1-win64.zip").as_str(), - get_tool_path("idf-git/2.30.1".to_string()) + get_tool_path("idf-git/2.30.1".to_string()), ) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } #[cfg(windows)] - match prepare_package("https://dl.espressif.com/dl/idf-python/idf-python-3.8.7-embed-win64.zip".to_string(), + match prepare_package( + "https://dl.espressif.com/dl/idf-python/idf-python-3.8.7-embed-win64.zip".to_string(), get_dist_path("idf-python-3.8.7-embed-win64.zip").as_str(), - get_tool_path("idf-python/3.8.7".to_string()) + get_tool_path("idf-python/3.8.7".to_string()), ) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } #[cfg(windows)] @@ -171,8 +193,12 @@ fn get_install_runner(_args: &str, _matches: &clap::ArgMatches) -> std::result:: arguments.push(esp_idf.clone()); println!("Cloning: {} {:?}", git_path, arguments); match run_command(git_path, arguments, "".to_string()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } } @@ -183,8 +209,12 @@ fn get_install_runner(_args: &str, _matches: &clap::ArgMatches) -> std::result:: arguments.push("virtualenv".to_string()); arguments.push(virtual_env_path.clone()); match run_command(python_path, arguments, "".to_string()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } } #[cfg(windows)] @@ -198,41 +228,59 @@ fn get_install_runner(_args: &str, _matches: &clap::ArgMatches) -> std::result:: arguments.push(idf_tools.clone()); arguments.push("install".to_string()); match run_command(python_path.clone(), arguments, "".to_string()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } let mut arguments: Vec = [].to_vec(); arguments.push(idf_tools); arguments.push("install-python-env".to_string()); match run_command(python_path.clone(), arguments, "".to_string()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } - add_idf_config(esp_idf, "4.4".to_string(), python_path); + // add_idf_config(esp_idf, "4.4".to_string(), python_path); Ok(()) } -pub fn install_espidf() -> Result<()> { - let esp_idf = get_esp_idf_directory("esp-idf/".to_string()); - println!("ESP-IDF Path: {}", esp_idf); +pub fn install_espidf(targets: String, version: String) -> Result<()> { + let espidf_path = get_esp_idf_directory("frameworks/esp-idf".to_string()); + println!("ESP-IDF Path: {}", espidf_path); #[cfg(windows)] - match prepare_package("https://dl.espressif.com/dl/idf-git/idf-git-2.30.1-win64.zip".to_string(), + match prepare_package( + "https://dl.espressif.com/dl/idf-git/idf-git-2.30.1-win64.zip".to_string(), get_dist_path("idf-git-2.30.1-win64.zip").as_str(), - get_tool_path("idf-git/2.30.1".to_string()) + get_tool_path("idf-git/2.30.1".to_string()), ) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } #[cfg(windows)] - match prepare_package("https://dl.espressif.com/dl/idf-python/idf-python-3.8.7-embed-win64.zip".to_string(), + match prepare_package( + "https://dl.espressif.com/dl/idf-python/idf-python-3.8.7-embed-win64.zip".to_string(), get_dist_path("idf-python-3.8.7-embed-win64.zip").as_str(), - get_tool_path("idf-python/3.8.7".to_string()) + get_tool_path("idf-python/3.8.7".to_string()), ) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } #[cfg(windows)] @@ -245,63 +293,76 @@ pub fn install_espidf() -> Result<()> { #[cfg(windows)] let python_path = get_tool_path("idf-python/3.8.7/python.exe".to_string()); #[cfg(unix)] - let python_path = "/usr/bin/python".to_string(); + let python_path = "/usr/bin/python3".to_string(); let virtual_env_path = get_python_env_path("4.4".to_string(), "3.8".to_string()); - - if !Path::new(&esp_idf).exists() { + // TODO: Use any git crate? + if !Path::new(&espidf_path).exists() { // let clone_command = format!("git clone --shallow-since=2020-01-01 --jobs 8 --recursive git@github.com:espressif/esp-idf.git "); let mut arguments: Vec = [].to_vec(); arguments.push("clone".to_string()); - arguments.push("--shallow-since=2020-01-01".to_string()); arguments.push("--jobs".to_string()); arguments.push("8".to_string()); + arguments.push("--branch".to_string()); + arguments.push(version); + arguments.push("--depth".to_string()); + arguments.push("1".to_string()); + arguments.push("--shallow-submodules".to_string()); arguments.push("--recursive".to_string()); arguments.push("https://github.com/espressif/esp-idf.git".to_string()); // arguments.push("git@github.com:espressif/esp-idf.git".to_string()); - arguments.push(esp_idf.clone()); + arguments.push(espidf_path.clone()); println!("Cloning: {} {:?}", git_path, arguments); match run_command(git_path, arguments, "".to_string()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Cloned esp-idf suscessfuly"); + } + Err(_e) => { + println!("Cloned esp-idf failed"); + } } } - - if !Path::new(&virtual_env_path).exists() { - println!("Creating virtual environment: {}", virtual_env_path); - let mut arguments: Vec = [].to_vec(); - arguments.push("-m".to_string()); - arguments.push("virtualenv".to_string()); - arguments.push(virtual_env_path.clone()); - match run_command(python_path, arguments, "".to_string()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} - } - } - #[cfg(windows)] - let python_path = format!("{}/Scripts/python.exe", virtual_env_path); - #[cfg(unix)] - let python_path = format!("{}/bin/python", virtual_env_path); - - let idf_tools = format!("{}/tools/idf_tools.py", esp_idf); - + println!("Installing esp-idf for {} with {}/install.sh", targets, espidf_path); + let install_script_path = format!("{}/install.sh", espidf_path); let mut arguments: Vec = [].to_vec(); - arguments.push(idf_tools.clone()); + arguments.push(targets); + match run_command(install_script_path, arguments, "".to_string()) { + Ok(_) => { + println!("ESP-IDF installation succeeded"); + } + Err(_e) => { + println!("ESP-IDF installation failed"); + } + } + // match std::process::Command::new(install_script_path) + // .arg("esp32 esp32s2") + // .stdout(Stdio::piped()) + // .output() + // { + // Ok(child_output) => { + // let result = String::from_utf8_lossy(&child_output.stdout); + // println!("ESP-IDF installation succeeded: {}", result); + // } + // Err(e) => { + // println!("ESP-IDF installation failed: {}", e); + // } + // } + + println!("Installing CMake"); + let mut arguments: Vec = [].to_vec(); + let mut idf_tools_scritp_path = format!("{}/tools/idf_tools.py", espidf_path); + arguments.push(idf_tools_scritp_path); arguments.push("install".to_string()); - match run_command(python_path.clone(), arguments, "".to_string()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + arguments.push("cmake".to_string()); + match run_command(python_path, arguments, "".to_string()) { + Ok(_) => { + println!("CMake installation succeeded"); + } + Err(_e) => { + println!("CMake installation failed"); + } } - let mut arguments: Vec = [].to_vec(); - arguments.push(idf_tools); - arguments.push("install-python-env".to_string()); - match run_command(python_path.clone(), arguments, "".to_string()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} - } - - add_idf_config(esp_idf, "4.4".to_string(), python_path); Ok(()) } @@ -365,7 +426,9 @@ fn get_initializer() -> String { fn get_initializer_arguments() -> Vec { let mut arguments: Vec = [].to_vec(); arguments.push("-c".to_string()); - arguments.push(". ./export.sh;cd examples/get-started/blink;idf.py fullclean; idf.py build".to_string()); + arguments.push( + ". ./export.sh;cd examples/get-started/blink;idf.py fullclean; idf.py build".to_string(), + ); arguments } @@ -390,18 +453,21 @@ fn get_initializer_arguments() -> Vec { arguments } -fn get_shell_runner(_args: &str, _matches: &clap::ArgMatches) -> std::result::Result<(), clap::Error> { +fn get_shell_runner( + _args: &str, + _matches: &clap::ArgMatches, +) -> std::result::Result<(), clap::Error> { println!("Starting process"); // let root = Path::new("C:\\esp"); // assert!(env::set_current_dir(&root).is_ok()); // println!("Successfully changed working directory to {}!", root.display()); - let process = std::process::Command::new(get_shell()) .args(get_initializer_arguments()) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) - .spawn().unwrap(); + .spawn() + .unwrap(); let mut s = String::new(); match process.stdout.unwrap().read_to_string(&mut s) { @@ -428,7 +494,10 @@ fn get_shell_runner(_args: &str, _matches: &clap::ArgMatches) -> std::result::Re // } #[cfg(unix)] -fn run_build(idf_path: &String, shell_initializer: &String) -> std::result::Result<(), clap::Error> { +fn run_build( + idf_path: &String, + shell_initializer: &String, +) -> std::result::Result<(), clap::Error> { // println!("Starting process"); let root = Path::new(&idf_path); assert!(env::set_current_dir(&root).is_ok()); @@ -441,13 +510,20 @@ fn run_build(idf_path: &String, shell_initializer: &String) -> std::result::Resu fn run_idf_command(command: String) { match run_command(get_shell(), get_initializer_arguments(), command) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } } #[cfg(windows)] -fn run_build(idf_path: &String, _shell_initializer: &String) -> std::result::Result<(), clap::Error> { +fn run_build( + idf_path: &String, + _shell_initializer: &String, +) -> std::result::Result<(), clap::Error> { // println!("Starting process"); let root = Path::new(&idf_path); assert!(env::set_current_dir(&root).is_ok()); @@ -457,10 +533,20 @@ fn run_build(idf_path: &String, _shell_initializer: &String) -> std::result::Res Ok(()) } -fn get_build_runner(_args: &str, matches: &clap::ArgMatches) -> std::result::Result<(), clap::Error> { - let build_repetitions:i32 = matches.value_of("repeat").unwrap().to_string().parse().unwrap(); - let idf_path = matches.value_of("idf-path") - .unwrap_or(&*get_selected_idf_path()).to_string(); +fn get_build_runner( + _args: &str, + matches: &clap::ArgMatches, +) -> std::result::Result<(), clap::Error> { + let build_repetitions: i32 = matches + .value_of("repeat") + .unwrap() + .to_string() + .parse() + .unwrap(); + let idf_path = matches + .value_of("idf-path") + .unwrap_or(&*get_selected_idf_path()) + .to_string(); let initializer = get_initializer(); println!("Number of CPU cores: {}", num_cpus::get()); @@ -469,8 +555,12 @@ fn get_build_runner(_args: &str, matches: &clap::ArgMatches) -> std::result::Res for _build_number in 0..build_repetitions { let start = Instant::now(); match run_build(&idf_path, &initializer) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } let duration = start.elapsed(); println!("Time elapsed in build: {:?}", duration); @@ -484,9 +574,7 @@ fn change_submodules_mirror(mut repo: Repository, submodule_url: String) { let repo_name = submodule.name().unwrap().to_string(); let original_url = submodule.url().unwrap(); - if !( original_url.starts_with("../../") || - original_url.starts_with("https://github.com") - ) { + if !(original_url.starts_with("../../") || original_url.starts_with("https://github.com")) { println!("Submodule: {}, URL: {} - skip", repo_name, original_url); continue; } @@ -503,26 +591,31 @@ fn change_submodules_mirror(mut repo: Repository, submodule_url: String) { let new_url = format!("{}{}", submodule_url, old_repo); change_set.push((repo_name, new_url)); - } for submodule in change_set { println!("Submodule: {}, new URL: {}", submodule.0, submodule.1); match repo.submodule_set_url(&*submodule.0, &*submodule.1) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } } - } -fn get_mirror_switch_runner(_args: &str, matches: &clap::ArgMatches) -> std::result::Result<(), clap::Error> { - let idf_path = matches.value_of("idf-path") - .unwrap_or(&*get_selected_idf_path()).to_string(); - let url = matches.value_of("url") - .unwrap().to_string(); - let submodule_url = matches.value_of("submodule-url") - .unwrap().to_string(); +fn get_mirror_switch_runner( + _args: &str, + matches: &clap::ArgMatches, +) -> std::result::Result<(), clap::Error> { + let idf_path = matches + .value_of("idf-path") + .unwrap_or(&*get_selected_idf_path()) + .to_string(); + let url = matches.value_of("url").unwrap().to_string(); + let submodule_url = matches.value_of("submodule-url").unwrap().to_string(); println!("Processing main repository..."); match Repository::open(idf_path.clone()) { @@ -530,18 +623,21 @@ fn get_mirror_switch_runner(_args: &str, matches: &clap::ArgMatches) -> std::res //repo.find_remote("origin")?.url() if matches.is_present("url") { match repo.remote_set_url("origin", url.as_str()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } } change_submodules_mirror(repo, submodule_url.clone()); - - }, + } Err(e) => { println!("failed to open: {}", e.to_string()); std::process::exit(1); - }, + } }; println!("Processing submodules..."); @@ -550,47 +646,66 @@ fn get_mirror_switch_runner(_args: &str, matches: &clap::ArgMatches) -> std::res //repo.find_remote("origin")?.url() if matches.is_present("url") { match repo.remote_set_url("origin", url.as_str()) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } } for mut submodule_repo_reference in repo.submodules().unwrap() { match submodule_repo_reference.init(false) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } let progress = matches.is_present("progress"); if matches.is_present("depth") { // git2 crate does not support depth for submodules, we need to call git instead - let depth = matches.value_of("depth") - .unwrap().to_string(); - match update_submodule(idf_path.clone(), submodule_repo_reference.name().unwrap().to_string(), depth, progress) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + let depth = matches.value_of("depth").unwrap().to_string(); + match update_submodule( + idf_path.clone(), + submodule_repo_reference.name().unwrap().to_string(), + depth, + progress, + ) { + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } } else { match submodule_repo_reference.update(true, None) { - Ok(_) => { println!("Ok"); }, - Err(_e) => { println!("Failed");} + Ok(_) => { + println!("Ok"); + } + Err(_e) => { + println!("Failed"); + } } } match submodule_repo_reference.open() { Ok(sub_repo) => { println!("Processing submodule: {:?}", sub_repo.workdir().unwrap()); change_submodules_mirror(sub_repo, submodule_url.clone()); - }, + } Err(_e) => { println!("Unable to update submodule"); } } } - - }, + } Err(e) => { println!("failed to open: {}", e.to_string()); std::process::exit(1); - }, + } }; Ok(()) @@ -674,7 +789,6 @@ fn get_mirror_switch_runner(_args: &str, matches: &clap::ArgMatches) -> std::res // ) // } - // pub fn get_multi_cmd<'a>() -> MultiCommand<'a, str, str> { // let multi_cmd: MultiCommand = Commander::new() // .add_cmd(get_build_cmd()) diff --git a/src/main.rs b/src/main.rs index ac82f87..92e629e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,15 +2,18 @@ extern crate clap; extern crate json; use clap::Parser; use clap_nested::Commander; +// use std::error::Error; use std::path::{Path, PathBuf}; type Result = std::result::Result>; use crate::config::get_tool_path; use crate::idf::install_espidf; use crate::package::{prepare_package_strip_prefix, prepare_single_binary}; use crate::shell::{run_command, update_env_path}; -use std::process::Stdio; +use espflash::Chip; use std::env; - +use std::io::{Error, ErrorKind}; +use std::process::Stdio; +use std::str::FromStr; mod config; mod idf; mod package; @@ -24,6 +27,7 @@ mod shell; // - Do a Tauri App so we can install it with gui // - Add tests // - Clean unused code +// - Add progress bar #[derive(Parser)] struct Opts { @@ -47,7 +51,7 @@ pub enum SubCommand { pub struct InstallOpts { /// Comma or space separated list of targets [esp32,esp32s2,esp32s3,esp32c3,all]. // Make it vector and have splliter =" " - #[clap(short = 'b', long, default_value = "esp32, esp32s2, esp32s3")] + #[clap(short = 'b', long, default_value = "esp32, es32s2, esp32s3")] pub build_target: String, /// Path to .cargo. // TODO: Use home_dir to make it diferent in every OS: #[clap(short = 'c', long, default_value_t: &'a Path = Path::new(format!("{}/.cargo",home_dir())))] @@ -63,7 +67,7 @@ pub struct InstallOpts { /// Destination of the export file generated. #[clap(short = 'f', long)] pub export_file: Option, - /// LLVM version. + /// LLVM version. [13, 14, 15] // TODO: Use Enum with 13, 14 and, when released, 15 #[clap(short = 'l', long, default_value = "esp-14.0.0-20220415")] pub llvm_version: String, @@ -139,6 +143,9 @@ fn install(args: InstallOpts) -> Result<()> { println!("{:?}", args); println!("{}", arch); + let targets: Vec = parse_targets(args.build_target).unwrap(); + println!("{:?}", targets); + return Ok(()); // TODO: Move to a function match std::process::Command::new("rustup") @@ -255,32 +262,38 @@ fn install(args: InstallOpts) -> Result<()> { // install_llvm_clang if Path::new(idf_tool_xtensa_elf_clang.as_str()).exists() { - println!("Previous installation of LLVM exist in: {}", idf_tool_xtensa_elf_clang); + println!( + "Previous installation of LLVM exist in: {}", + idf_tool_xtensa_elf_clang + ); println!("Please, remove the directory before new installation."); } else { println!("Downloading xtensa-esp32-elf-clang"); match prepare_package_strip_prefix( - &llvm_url, - get_tool_path(format!("xtensa-esp32-elf-clang-{}-{}",&llvm_release,llvm_arch).to_string()), - "", - ) { - Ok(_) => { - println!("Package xtensa-esp32-elf-clang ready"); - } - Err(_e) => { - println!("Unable to prepare xtensa-esp32-elf-clang"); - } + &llvm_url, + get_tool_path( + format!("xtensa-esp32-elf-clang-{}-{}", &llvm_release, llvm_arch).to_string(), + ), + "", + ) { + Ok(_) => { + println!("Package xtensa-esp32-elf-clang ready"); } + Err(_e) => { + println!("Unable to prepare xtensa-esp32-elf-clang"); + } + } } // TODO: Insall riscv target in nigthly if installing esp32c3 - // if args.espidf_version.is_some() { - // idf::install_espidf(); + if args.espidf_version.is_some() { + idf::install_espidf(args.build_target, args.espidf_version.unwrap())?; // TODO: Install esp-idf - // } else { - // TODO: Install gcc for targets - // } + } else { + install_gcc(args.build_target)?; + // TODO: Install gcc for targets + } // TODO: Install extra crates match args.extra_crates { @@ -305,11 +318,12 @@ fn install(args: InstallOpts) -> Result<()> { // TODO: Set environment println!("Updating environment variables:"); - let libclang_path = format!("{}/lib", get_tool_path("xtensa-esp32-elf-clang".to_string())); + let libclang_path = format!( + "{}/lib", + get_tool_path("xtensa-esp32-elf-clang".to_string()) + ); println!("export LIBCLANG_PATH=\"{}\"", &libclang_path); - - // #[cfg(windows)] // println!("PATH+=\";{}\"", libclang_bin); // #[cfg(unix)] @@ -317,7 +331,6 @@ fn install(args: InstallOpts) -> Result<()> { // update_env_path(&libclang_bin); - return Ok(()); } @@ -438,3 +451,57 @@ fn get_gcc_arch(arch: &str) -> &str { _ => arch, } } + +fn install_gcc(targets: String) -> Result<()> { + Ok(()) +} + +// TODO: Create test for this function +fn parse_targets(build_target: String) -> Result> { + let mut targets: Vec<&str>; + let mut chips: Vec = Vec::new(); + if build_target.contains("all") { + chips.push(Chip::Esp32); + chips.push(Chip::Esp32s2); + chips.push(Chip::Esp32s3); + chips.push(Chip::Esp32c3); + return Ok(chips); + } + if build_target.contains(' ') || build_target.contains(',') { + targets = build_target.split([',', ' ']).collect(); + } else { + targets = vec![&build_target]; + } + for target in targets { + match target { + "esp32" => chips.push(Chip::Esp32), + "esp32s2" => chips.push(Chip::Esp32s2), + "esp32s3" => chips.push(Chip::Esp32s3), + "esp32c3" => chips.push(Chip::Esp32c3), + _ => { + return Err(Box::new(Error::new( + ErrorKind::Other, + format!("Unknown target: {}", target), + ))); + } + }; + } + + Ok((chips)) +} + +fn parse_llvm_version(llvm_version: &str) -> Result { + let parsed_version = match llvm_version { + "13" => "esp-13.0.0-20211203", + "14" => "esp-14.0.0-20220415", + "15" => "", // TODO: Fill when released + _ => { + return Err(Box::new(Error::new( + ErrorKind::Other, + format!("Unknown LLVM Version: {}", llvm_version), + ))); + } + }; + + Ok((parsed_version.to_string())) +}