From 321ac6ccdac11477c9b0f80f0a71f7d8f802e0c9 Mon Sep 17 00:00:00 2001 From: Alexander Koz Date: Thu, 9 May 2024 17:55:44 +0400 Subject: [PATCH] Improvements & tests --- Cargo.lock | 298 ++++++++++++++++----------- cargo/Cargo.toml | 6 +- cargo/src/assets/mod.rs | 4 +- cargo/src/assets/plan.rs | 2 +- cargo/src/init/mod.rs | 2 +- cargo/src/package/mod.rs | 2 +- support/bindgen-cfg/Cargo.toml | 2 +- support/bindgen-cfg/src/lib.rs | 22 +- support/build/Cargo.toml | 2 +- support/build/src/assets/mod.rs | 6 +- support/build/src/assets/plan.rs | 19 +- support/build/src/assets/resolver.rs | 14 +- support/build/src/assets/tests.rs | 103 +++++++-- support/build/src/config.rs | 7 +- support/build/src/io.rs | 2 + support/build/src/manifest.rs | 4 +- support/device/Cargo.toml | 2 +- support/device/src/mount/mod.rs | 17 +- support/device/src/mount/win.rs | 10 +- support/device/src/serial/mod.rs | 4 +- support/device/src/usb/io.rs | 2 +- support/device/src/usb/mod.rs | 31 +-- support/tool/Cargo.toml | 2 +- support/tool/src/cli.rs | 6 +- support/tool/src/main.rs | 2 +- support/utils/Cargo.toml | 2 +- support/utils/src/compile.rs | 4 +- 27 files changed, 370 insertions(+), 207 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27069576..f5dbfec5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,47 +68,48 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -116,9 +117,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" [[package]] name = "arbitrary" @@ -334,7 +335,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -351,7 +352,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -371,9 +372,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "axum" @@ -487,7 +488,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.60", + "syn 2.0.61", "which 4.4.2", ] @@ -701,9 +702,9 @@ dependencies = [ [[package]] name = "cargo-credential-libsecret" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62d3e1abe5f85f1bb475901441daf4fbce5e6415c1b1ce7f40be92fd8cf678d5" +checksum = "7d73108520871d1ce2f3ba723f24cf13f89fcbab33424b408fc03f31fdc9a7f0" dependencies = [ "anyhow", "cargo-credential", @@ -712,9 +713,9 @@ dependencies = [ [[package]] name = "cargo-credential-macos-keychain" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "361100e0a3f7e5a3f3745bcda27637fce0e81dfa1deb00098085cbdacf5441d3" +checksum = "a58a3a28c131a750309387c3a05d25b992cf7d2648463ac70bd9e22c705e0868" dependencies = [ "cargo-credential", "security-framework", @@ -722,9 +723,9 @@ dependencies = [ [[package]] name = "cargo-credential-wincred" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4888956ebe36160e341031845a2db838d1e1be24ac6c20b2a02a8f593ff3692d" +checksum = "a15e5fee4548ab1b6b5459ab91fed7d79170a4dda38232d2b6263de28becf9f3" dependencies = [ "cargo-credential", "windows-sys 0.52.0", @@ -741,7 +742,7 @@ dependencies = [ [[package]] name = "cargo-playdate" -version = "0.4.11" +version = "0.4.12" dependencies = [ "anstyle", "anyhow", @@ -773,14 +774,14 @@ dependencies = [ "toml_edit 0.22.12", "try-lazy-init", "walkdir", - "zip 1.1.3", + "zip 1.2.1", ] [[package]] name = "cargo-util" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f2d9a9a8d3e0b61b1110c49ab8f6ed7a76ce4f2b1d53ae48a83152d3d5e8f5b" +checksum = "f6e977de2867ec90a1654882ff95ca5849a526e893bab588f84664cfcdb11c0a" dependencies = [ "anyhow", "core-foundation", @@ -817,9 +818,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.96" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" dependencies = [ "jobserver", "libc", @@ -908,7 +909,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -919,9 +920,9 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "clru" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8191fa7302e03607ff0e237d4246cc043ff5b3cb9409d995172ba3bea16b807" +checksum = "cbd0f76e066e64fdc5631e3bb46381254deab9ef1158292f27c8c57e3bf3fe59" [[package]] name = "cmake" @@ -950,14 +951,14 @@ dependencies = [ "nom", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "combine" @@ -1112,9 +1113,9 @@ dependencies = [ [[package]] name = "crates-io" -version = "0.40.0" +version = "0.40.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19958b4dfc8889cf78606e5e2fe64e7e0170a9ab853157192608f3a3253c8ef8" +checksum = "1768fc088f5ad5a83a2860626b2b2ba71f31cdbe1295284980ceb191a7ae86d8" dependencies = [ "curl", "percent-encoding", @@ -1295,7 +1296,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -1331,6 +1332,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "displaydoc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.61", +] + [[package]] name = "dmsort" version = "1.0.2" @@ -1493,9 +1505,9 @@ checksum = "a02a5d186d7bf1cb21f1f95e1a9cfa5c1f2dcd803a47aad454423ceec13525c5" [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", @@ -1776,7 +1788,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -1822,9 +1834,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -2230,7 +2242,7 @@ checksum = "1dff438f14e67e7713ab9332f5fd18c8f20eb7eb249494f6c2bf170522224032" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3008,6 +3020,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "itertools" version = "0.11.0" @@ -3114,7 +3132,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3380,7 +3398,7 @@ checksum = "5cf92c10c7e361d6b99666ec1c6f9805b0bea2c3bd8c78dc6fe98ac5bd78db11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3450,7 +3468,7 @@ checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3612,9 +3630,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm", @@ -3630,6 +3648,27 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.61", +] + [[package]] name = "num_threads" version = "0.1.7" @@ -3847,9 +3886,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pathdiff" @@ -4000,7 +4039,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -4081,20 +4120,20 @@ dependencies = [ "proc-macro2", "quote", "semver", - "syn 2.0.60", + "syn 2.0.61", "which 6.0.1", ] [[package]] name = "playdate-bindgen-cfg" -version = "0.1.5" +version = "0.1.6" dependencies = [ "clap", ] [[package]] name = "playdate-build" -version = "0.2.8" +version = "0.2.9" dependencies = [ "crate-metadata", "dirs", @@ -4111,7 +4150,7 @@ dependencies = [ [[package]] name = "playdate-build-utils" -version = "0.3.1" +version = "0.3.2" dependencies = [ "dirs", "log", @@ -4137,7 +4176,7 @@ dependencies = [ [[package]] name = "playdate-device" -version = "0.2.8" +version = "0.2.9" dependencies = [ "async-std", "clap", @@ -4286,7 +4325,7 @@ dependencies = [ [[package]] name = "playdate-tool" -version = "0.3.3" +version = "0.3.4" dependencies = [ "clap", "console-subscriber", @@ -4392,12 +4431,12 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ac2cf0f2e4f42b49f5ffd07dae8d746508ef7526c13940e5f524012ae6c6550" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -4409,11 +4448,20 @@ dependencies = [ "elliptic-curve", ] +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit 0.21.1", +] + [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -4455,15 +4503,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" +checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" dependencies = [ "anyhow", "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -4660,9 +4708,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" @@ -4672,9 +4720,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustfix" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81864b097046da5df3758fdc6e4822bbb70afa06317e8ca45ea1b51cb8c5e5a4" +checksum = "5b338d50bbf36e891c7e40337c8d4cf654094a14d50c3583c6022793c01a259c" dependencies = [ "serde", "serde_json", @@ -4711,15 +4759,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" +checksum = "092474d1a01ea8278f69e6a358998405fae5b8b963ddaeb2b0b04a128bf1dfb0" [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -4762,7 +4810,7 @@ checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -4781,11 +4829,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -4794,9 +4842,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -4804,18 +4852,18 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.199" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" dependencies = [ "serde_derive", ] @@ -4842,13 +4890,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.199" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -4862,9 +4910,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -5380,9 +5428,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" dependencies = [ "proc-macro2", "quote", @@ -5457,22 +5505,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -5571,7 +5619,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -5600,16 +5648,15 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -5656,7 +5703,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.7", + "winnow 0.6.8", ] [[package]] @@ -5738,7 +5785,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -6021,7 +6068,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "wasm-bindgen-shared", ] @@ -6055,7 +6102,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6209,7 +6256,7 @@ checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -6220,7 +6267,7 @@ checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -6422,9 +6469,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" dependencies = [ "memchr", ] @@ -6448,22 +6495,22 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -6471,6 +6518,20 @@ name = "zeroize" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.61", +] [[package]] name = "zip" @@ -6486,24 +6547,29 @@ dependencies = [ [[package]] name = "zip" -version = "1.1.3" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e6cb8909b2e8e6733c9ef67d35be1a27105644d362aafb5f8b2ba395727adf6" +checksum = "006d078b7b6fc587bb25e022ad39e7086f44e5c4fef6076964ea601533241beb" dependencies = [ "aes", "arbitrary", - "byteorder", "bzip2", "constant_time_eq", "crc32fast", "crossbeam-utils", "deflate64", + "displaydoc", "flate2", "hmac", + "indexmap 2.2.6", "lzma-rs", + "num_enum", "pbkdf2", + "rand", "sha1", + "thiserror", "time", + "zeroize", "zopfli", "zstd", ] diff --git a/cargo/Cargo.toml b/cargo/Cargo.toml index e12ddf5b..673c6b28 100644 --- a/cargo/Cargo.toml +++ b/cargo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-playdate" -version = "0.4.11" +version = "0.4.12" readme = "README.md" description = "Build tool for neat yellow console." keywords = ["playdate", "build", "cargo", "plugin", "cargo-subcommand"] @@ -31,8 +31,8 @@ clap_lex = "0.7" dirs.workspace = true fs_extra.workspace = true -cargo = "0.78.1" -cargo-util = "0.2.10" +cargo = "0.78" +cargo-util = "0.2.11" cargo-platform = "0.1.8" cargo-util-schemas = "0.2.0" diff --git a/cargo/src/assets/mod.rs b/cargo/src/assets/mod.rs index d1b8a502..712e08ed 100644 --- a/cargo/src/assets/mod.rs +++ b/cargo/src/assets/mod.rs @@ -166,7 +166,7 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult> { config.log().error(message); } else { - targets.insert(target.to_owned(), (package.package_id(), target_kind)); + targets.insert(target, (package.package_id(), target_kind)); } } }; @@ -224,7 +224,7 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult> { log.status("", dest); let src = format!("root {}", dep_root.as_relative_to_root(config).display()); log.status("", src); - if dep_root != &plan.path { + if dep_root != plan.path { let path = plan.plan.crate_root(); let src = format!("root (plan) {}", path.as_relative_to_root(config).display()); log.status("", src); diff --git a/cargo/src/assets/plan.rs b/cargo/src/assets/plan.rs index e2e11f33..d8be5198 100644 --- a/cargo/src/assets/plan.rs +++ b/cargo/src/assets/plan.rs @@ -43,7 +43,7 @@ impl<'a, 'cfg> LazyEnvBuilder<'a, 'cfg> { ("CARGO_MANIFEST_DIR", root.to_string()), ]; - let mut env = Env::from_iter(vars.into_iter()).map_err(|err| anyhow::anyhow!("{err}"))?; + let mut env = Env::try_from_iter(vars.into_iter()).map_err(|err| anyhow::anyhow!("{err}"))?; // add global environment: for (k, v) in std::env::vars() { diff --git a/cargo/src/init/mod.rs b/cargo/src/init/mod.rs index 0bc1f726..aa7e7dd1 100644 --- a/cargo/src/init/mod.rs +++ b/cargo/src/init/mod.rs @@ -316,7 +316,7 @@ fn add_dependencies<'cfg>(config: &'cfg Config<'_>, let others = config.create_deps.iter().filter_map(|d| { if let Name::Other(dep) = &d.name { - Some(dep.to_owned()) + Some(dep.clone()) } else { None } diff --git a/cargo/src/package/mod.rs b/cargo/src/package/mod.rs index 4f4019af..0d1ad432 100644 --- a/cargo/src/package/mod.rs +++ b/cargo/src/package/mod.rs @@ -288,7 +288,7 @@ fn build_manifest(config: &Config, Manifest::try_from_source(ManifestSource { package, metadata: metadata.as_ref() }) }.map_err(|err| anyhow!(err))?; - std::fs::write(layout.manifest(), manifest.to_string())?; + std::fs::write(layout.manifest(), manifest.to_manifest_string())?; Ok(()) } diff --git a/support/bindgen-cfg/Cargo.toml b/support/bindgen-cfg/Cargo.toml index 10bd8dc5..41693e05 100644 --- a/support/bindgen-cfg/Cargo.toml +++ b/support/bindgen-cfg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-bindgen-cfg" -version = "0.1.5" +version = "0.1.6" readme = "README.md" description = "Minimal configuration for playdate-bindgen." keywords = ["playdate", "bindings", "ffi", "code-generation"] diff --git a/support/bindgen-cfg/src/lib.rs b/support/bindgen-cfg/src/lib.rs index 26020625..7f881408 100644 --- a/support/bindgen-cfg/src/lib.rs +++ b/support/bindgen-cfg/src/lib.rs @@ -197,7 +197,7 @@ impl Derive { } pub fn to_cli_args(&self) -> Vec { - let words = self.to_string(); + let words = self.to_feature_list(); if words.is_empty() { vec!["--derive=".to_string()] } else { @@ -236,9 +236,9 @@ impl FromStr for Derive { } } -impl ToString for Derive { +impl Derive { #[rustfmt::skip] - fn to_string(&self) -> String { + fn to_feature_list(&self) -> String { let mut out = Vec::new(); if self.default { out.push("default") } if self.eq {out.push("eq")} @@ -253,6 +253,11 @@ impl ToString for Derive { } } +impl std::fmt::Display for Derive { + #[inline] + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.to_feature_list().fmt(f) } +} + impl Default for Derive { fn default() -> Self { Self { debug: true, @@ -277,7 +282,7 @@ impl Features { pub const fn empty() -> Self { Self { documentation: false } } pub fn to_cli_args(&self) -> Vec { - let words = self.to_string(); + let words = self.to_feature_list(); if words.is_empty() { vec!["--features=".to_string()] } else { @@ -308,15 +313,20 @@ impl FromStr for Features { } } -impl ToString for Features { +impl Features { #[rustfmt::skip] - fn to_string(&self) -> String { + fn to_feature_list(&self) -> String { let mut out = Vec::new(); if self.documentation { out.push("documentation") } out.join(",") } } +impl std::fmt::Display for Features { + #[inline] + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.to_feature_list().fmt(f) } +} + impl Default for Features { fn default() -> Self { Self { documentation: true } } } diff --git a/support/build/Cargo.toml b/support/build/Cargo.toml index 7ea023fc..4547c717 100644 --- a/support/build/Cargo.toml +++ b/support/build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-build" -version = "0.2.8" +version = "0.2.9" readme = "README.md" description = "Utils that help to build package for Playdate" keywords = ["playdate", "package", "encoding", "manifest", "assets"] diff --git a/support/build/src/assets/mod.rs b/support/build/src/assets/mod.rs index 45401fa5..c5a17a3a 100644 --- a/support/build/src/assets/mod.rs +++ b/support/build/src/assets/mod.rs @@ -125,16 +125,16 @@ pub fn apply_build_plan<'l, 'r, P: AsRef>(plan: BuildPlan<'l, 'r>, for entry in plan.drain(..) { let current: Vec<_> = match &entry { Mapping::AsIs(inc, ..) => { - let source = abs_or_rel_crate_any(inc.source(), crate_root); + let source = abs_if_existing_any(inc.source(), crate_root); vec![method(&source, &inc.target(), false)] }, Mapping::Into(inc, ..) => { - let source = abs_or_rel_crate_any(inc.source(), crate_root); + let source = abs_if_existing_any(inc.source(), crate_root); vec![method(&source, &inc.target(), true)] }, Mapping::ManyInto { sources, target, .. } => { sources.iter() - .map(|inc| (abs_or_rel_crate_any(inc.source(), crate_root), target.join(inc.target()))) + .map(|inc| (abs_if_existing_any(inc.source(), crate_root), target.join(inc.target()))) .map(|(ref source, ref target)| method(source, target, false)) .collect() }, diff --git a/support/build/src/assets/plan.rs b/support/build/src/assets/plan.rs index 86522c9b..424835e2 100644 --- a/support/build/src/assets/plan.rs +++ b/support/build/src/assets/plan.rs @@ -47,7 +47,7 @@ pub fn build_plan<'l, 'r, 'c: 'l, V>(env: &'c Env, if trailing_sep && !s.ends_with(PATH_SEPARATOR) { s.push(MAIN_SEPARATOR); } - unixish_path_pattern(&s).into_owned() + sanitize_path_pattern(&s).into_owned() } else { s.to_owned() } @@ -97,7 +97,7 @@ pub fn build_plan<'l, 'r, 'c: 'l, V>(env: &'c Env, let key = PathBuf::from(k.as_str()); let value = Cow::Borrowed(v.as_str()); let into_dir = k.as_str().ends_with(PATH_SEPARATOR); - let source_exists = abs_or_rel_crate_existing(Path::new(value.as_ref()), crate_root)?.is_some(); + let source_exists = abs_if_existing(Path::new(value.as_ref()), crate_root)?.is_some(); let mapping = match (source_exists, into_dir) { (true, true) => Mapping::Into(Match::new(value.as_ref(), key), (k, v)), @@ -200,10 +200,11 @@ pub fn build_plan<'l, 'r, 'c: 'l, V>(env: &'c Env, } -// TODO: tests for `abs_or_rel_crate_existing` /// Make path relative to `crate_root` if it isn't absolute, checking existence. /// Returns `None` if path doesn't exist. -pub fn abs_or_rel_crate_existing<'t, P1, P2>(path: P1, root: P2) -> std::io::Result>> +/// +/// Input `path` must be absolute or relative to the `root`. +pub fn abs_if_existing<'t, P1, P2>(path: P1, root: P2) -> std::io::Result>> where P1: 't + AsRef + Into>, P2: AsRef { let p = if path.as_ref().is_absolute() && path.as_ref().try_exists()? { @@ -221,12 +222,12 @@ pub fn abs_or_rel_crate_existing<'t, P1, P2>(path: P1, root: P2) -> std::io::Res /// Same as [`abs_or_rel_crate_existing`], but returns given `path` as fallback. #[inline] -pub fn abs_or_rel_crate_any<'t, P1, P2>(path: P1, root: P2) -> Cow<'t, Path> +pub fn abs_if_existing_any<'t, P1, P2>(path: P1, root: P2) -> Cow<'t, Path> where P1: 't + AsRef + Into> + Clone, P2: AsRef { - abs_or_rel_crate_existing(path.clone(), root).ok() - .flatten() - .unwrap_or(path.into()) + abs_if_existing(path.clone(), root).ok() + .flatten() + .unwrap_or(path.into()) } @@ -342,7 +343,7 @@ impl BuildPlan<'_, '_> { &self) -> impl Iterator))> + '_ { let pair = |inc: &Match| { - (inc.target().to_path_buf(), abs_or_rel_crate_any(inc.source(), self.crate_root).to_path_buf()) + (inc.target().to_path_buf(), abs_if_existing_any(inc.source(), self.crate_root).to_path_buf()) }; self.as_inner() diff --git a/support/build/src/assets/resolver.rs b/support/build/src/assets/resolver.rs index e9c8014c..48174c45 100644 --- a/support/build/src/assets/resolver.rs +++ b/support/build/src/assets/resolver.rs @@ -17,7 +17,7 @@ pub fn resolve_includes, Excl: AsRef>(expr: S, exclude: &[Excl], links: LinkBehavior) -> Result, Error> { - let expr = unixish_path_pattern(expr.as_ref()); + let expr = sanitize_path_pattern(expr.as_ref()); // let crate_root = crate_root.to_string_lossy(); // #[cfg(windows)] @@ -86,6 +86,9 @@ pub fn resolve_includes, Excl: AsRef>(expr: S, } +// TODO: Tests for `sanitize_path_pattern` +/// Adapt path to wax walker, so kind of "patternize" or "unixish". +/// /// On Windows makes given absolute path to look like POSIX or UNC: /// `C:/foo/bar/**` or `//./C:/foo/bar/**`. /// @@ -94,7 +97,8 @@ pub fn resolve_includes, Excl: AsRef>(expr: S, /// - if pattern starts with `:`, escape it as `\`: /// /// On unix does nothing. -pub fn unixish_path_pattern(path: &str) -> Cow<'_, str> { +pub fn sanitize_path_pattern(path: &str) -> Cow<'_, str> { + // TODO: Before patternize use normalize/canonicalize, crates: dunce, normpath, or path-slash if cfg!(windows) { path.replace('\\', "/") .replace(':', "\\:") @@ -167,7 +171,7 @@ impl EnvResolver { pub fn expr<'a, 'e, 'c: 'e, Ex: AsMut>>(&self, mut expr: Ex, env: &'c Env) -> Ex { let editable = expr.as_mut(); let replaced = self.str(editable.actual(), env); - if &replaced != editable.actual() { + if replaced != editable.actual() { editable.set(replaced); } expr @@ -509,7 +513,7 @@ mod tests { let resolver = EnvResolver::new(); let env = { - let mut env = Env::default().unwrap(); + let mut env = Env::try_default().unwrap(); env.vars.insert("FOO".into(), "foo".into()); env.vars.insert("BAR".into(), "bar".into()); env @@ -534,7 +538,7 @@ mod tests { #[should_panic] fn resolver_missed() { let resolver = EnvResolver::new(); - let env = Env::default().unwrap(); + let env = Env::try_default().unwrap(); let expr = Expr::from("${MISSED}/file.txt"); resolver.expr(expr, &env); } diff --git a/support/build/src/assets/tests.rs b/support/build/src/assets/tests.rs index 9e43b6e9..d293c6e1 100644 --- a/support/build/src/assets/tests.rs +++ b/support/build/src/assets/tests.rs @@ -1,24 +1,99 @@ #![cfg(test)] use std::collections::HashMap; use std::collections::HashSet; -use std::path::PathBuf; +use std::path::{PathBuf, Path}; use crate::config::Env; use crate::assets::resolver::Expr; use crate::metadata::format::PlayDateMetadataAssets; use super::*; -use resolver::unixish_path_pattern; +use resolver::sanitize_path_pattern; use resolver::Match; use toml::Value; -mod plan { +fn crate_root() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")) } + + +mod abs_if_existing { + use std::borrow::Cow; + use super::*; - use std::env::temp_dir; + use super::abs_if_existing; + + + #[test] + fn local() { + let roots = [ + Cow::from(Path::new(env!("CARGO_MANIFEST_DIR"))), + crate_root().into(), + ]; + let paths = ["Cargo.toml", "src/lib.rs"]; + + for root in roots { + for test in paths { + let path = Path::new(test); + let crated = abs_if_existing(path, &root).unwrap(); + assert!(crated.is_some(), "{crated:?} should be exist (src: {path:?})"); - fn crate_root() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")) } + let crated = crated.unwrap(); + let expected = root.join(path); + assert_eq!(expected, crated); + } + } + } + + #[test] + fn external_rel() { + let roots = [ + Cow::from(Path::new(env!("CARGO_MANIFEST_DIR"))), + crate_root().into(), + ]; + let paths = ["../utils/Cargo.toml", "./../utils/src/lib.rs"]; + + for root in roots { + for test in paths { + let path = Path::new(test); + + let crated = abs_if_existing(path, &root).unwrap(); + assert!(crated.is_some(), "{crated:?} should be exist (src: {path:?})"); + + let crated = crated.unwrap(); + let expected = root.join(path); + assert_eq!(expected, crated); + } + } + } + + #[test] + fn external_abs() { + let roots = [ + Cow::from(Path::new(env!("CARGO_MANIFEST_DIR"))), + crate_root().into(), + ]; + let paths = ["utils", "utils/Cargo.toml"]; + + for root in roots { + for test in paths { + let path = root.parent().unwrap().join(test); + + let crated = abs_if_existing(&path, &root).unwrap(); + assert!(crated.is_some(), "{crated:?} should be exist (src: {path:?})"); + + let crated = crated.unwrap(); + let expected = path.as_path(); + assert_eq!(expected, crated); + } + } + } +} + + +mod plan { + use super::*; + use std::env::temp_dir; fn prepared_tmp(test_name: &str) -> (PathBuf, PathBuf, [&'static str; 4], Env) { @@ -43,7 +118,7 @@ mod plan { } let env = { - let mut env = Env::default().unwrap(); + let mut env = Env::try_default().unwrap(); env.vars.insert("TMP".into(), temp.to_string_lossy().into_owned()); env.vars.insert("SUB".into(), sub.to_string_lossy().into_owned()); env @@ -63,7 +138,7 @@ mod plan { #[test] fn local_exact() { - let env = Env::default().unwrap(); + let env = Env::try_default().unwrap(); let opts = AssetsOptions::default(); let root = crate_root(); @@ -89,7 +164,7 @@ mod plan { #[test] fn resolve_local_abs() { let env = { - let mut env = Env::default().unwrap(); + let mut env = Env::try_default().unwrap(); env.vars.insert( "SRC_ABS".into(), concat!(env!("CARGO_MANIFEST_DIR"), "/src").into(), @@ -138,7 +213,7 @@ mod plan { #[test] fn resolve_local() { let env = { - let mut env = Env::default().unwrap(); + let mut env = Env::try_default().unwrap(); env.vars.insert("SRC".into(), "src".into()); env }; @@ -279,7 +354,7 @@ mod plan { #[test] fn local_exact() { - let env = Env::default().unwrap(); + let env = Env::try_default().unwrap(); let opts = AssetsOptions::default(); let root = crate_root(); @@ -300,7 +375,7 @@ mod plan { assert!(tests.contains(left.as_str())); assert_eq!( left.as_str(), - unixish_path_pattern(matched.target().to_string_lossy().as_ref()) + sanitize_path_pattern(matched.target().to_string_lossy().as_ref()) ); } else { panic!("pair is not matching: {pair:#?}"); @@ -311,7 +386,7 @@ mod plan { #[test] fn local_exact_target() { - let env = Env::default().unwrap(); + let env = Env::try_default().unwrap(); let opts = AssetsOptions::default(); let root = crate_root(); @@ -358,7 +433,7 @@ mod plan { #[test] fn local_exact_target() { - let env = Env::default().unwrap(); + let env = Env::try_default().unwrap(); let opts = AssetsOptions::default(); let root = crate_root(); @@ -403,7 +478,7 @@ mod plan { #[test] #[cfg_attr(windows, should_panic)] fn glob_local_target() { - let env = Env::default().unwrap(); + let env = Env::try_default().unwrap(); let opts = AssetsOptions::default(); let root = crate_root(); diff --git a/support/build/src/config.rs b/support/build/src/config.rs index abdc8752..0bed6374 100644 --- a/support/build/src/config.rs +++ b/support/build/src/config.rs @@ -24,12 +24,15 @@ impl Env { pub fn cargo_manifest_dir(&self) -> &Path { Path::new(&self.vars["CARGO_MANIFEST_DIR"]) } /// Creates a new environment with values by real env by default. - pub fn default() -> Result { + pub fn try_default() -> Result { Ok(Self { vars: env::vars().collect(), cargo_manifest_filename: CARGO_MANIFEST_FILENAME.to_string() }) } - pub fn from_iter(iter: impl Iterator) -> Result { + // TODO: Proper error for `Env::try_from_iter` + pub fn try_from_iter(iter: impl Iterator) -> Result + where K: ToString, + V: ToString { let mut env = BTreeMap::new(); env.extend(iter.map(|(k, v)| (k.to_string(), v.to_string()))); diff --git a/support/build/src/io.rs b/support/build/src/io.rs index 2ce5815b..fee02ba8 100644 --- a/support/build/src/io.rs +++ b/support/build/src/io.rs @@ -31,6 +31,8 @@ pub fn ensure_dir_exists>(path: P, boundary: impl AsRef) -> } +// TODO: Win-only: add `junction_point` as fallback method +// https://github.com/rust-lang/rust/issues/121709 /// Creates symlink. pub fn soft_link_checked, Pl: AsRef>(origin: Po, link: Pl, diff --git a/support/build/src/manifest.rs b/support/build/src/manifest.rs index bc8c940e..3728c1ff 100644 --- a/support/build/src/manifest.rs +++ b/support/build/src/manifest.rs @@ -35,8 +35,8 @@ pub mod format { } - impl ToString for Manifest { - fn to_string(&self) -> String { + impl Manifest { + pub fn to_manifest_string(&self) -> String { let mut result = String::new(); fn to_row, V: AsRef>(key: K, value: V) -> String { diff --git a/support/device/Cargo.toml b/support/device/Cargo.toml index 3089be14..d8bd5100 100644 --- a/support/device/Cargo.toml +++ b/support/device/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-device" -version = "0.2.8" +version = "0.2.9" readme = "README.md" description = "Cross-platform interface Playdate device, async & blocking." keywords = ["playdate", "usb", "serial"] diff --git a/support/device/src/mount/mod.rs b/support/device/src/mount/mod.rs index cba30b5c..21926589 100644 --- a/support/device/src/mount/mod.rs +++ b/support/device/src/mount/mod.rs @@ -6,15 +6,14 @@ use std::path::Path; use crate::device::Device; use crate::error::Error; - -#[cfg(target_os = "macos")] -#[path = "mac.rs"] -pub mod volume; -#[cfg(target_os = "windows")] -#[path = "win.rs"] -pub mod volume; -#[cfg(target_os = "linux")] -#[path = "linux.rs"] +#[cfg(any(all(target_os = "macos", target_os = "linux"), + all(target_os = "linux", target_os = "windows"), + all(target_os = "windows", target_os = "macos")))] +compile_error!("cfg.target_os conflict"); + +#[cfg_attr(target_os = "macos", path = "mac.rs")] +#[cfg_attr(target_os = "linux", path = "linux.rs")] +#[cfg_attr(target_os = "windows", path = "win.rs")] pub mod volume; mod methods; diff --git a/support/device/src/mount/win.rs b/support/device/src/mount/win.rs index 03950afb..03006674 100644 --- a/support/device/src/mount/win.rs +++ b/support/device/src/mount/win.rs @@ -297,8 +297,12 @@ mod winapi { let drive_name = std::str::from_utf8(&name_buf)?.trim(); - let temp_drive_name = (!drive_name.is_empty()).then_some(drive_name) - .unwrap_or("unnamed"); + let temp_drive_name = if drive_name.is_empty() { + "" + } else { + drive_name + }; + trace!("found drive: {letter} '{temp_drive_name}' ({serial})"); Ok(drive_name.to_string()) @@ -376,7 +380,7 @@ mod winapi { } - struct FileHandle(pub HANDLE, Pin); + pub struct FileHandle(pub HANDLE, #[allow(dead_code)] Pin); impl Drop for FileHandle { fn drop(&mut self) { diff --git a/support/device/src/serial/mod.rs b/support/device/src/serial/mod.rs index dbca5121..1392a673 100644 --- a/support/device/src/serial/mod.rs +++ b/support/device/src/serial/mod.rs @@ -87,8 +87,8 @@ impl Interface { #[cfg_attr(feature = "tracing", tracing::instrument)] -pub fn open<'a, S: Into>>(port_name: S) -> Result - where S: std::fmt::Debug { +pub fn open<'a, S>(port_name: S) -> Result + where S: Into> + std::fmt::Debug { trace!("opening port {port_name:?}"); let builder = port_builder(port_name); diff --git a/support/device/src/usb/io.rs b/support/device/src/usb/io.rs index 5e3526e8..cdb4336b 100644 --- a/support/device/src/usb/io.rs +++ b/support/device/src/usb/io.rs @@ -133,7 +133,7 @@ pub async fn redirect_interface_to_stdout(interface: &mut crate::interface::Inte let mut stdout = std::io::stdout(); let to_stdout = move |data: &[u8]| stdout.write_all(data).inspect_err(|err| error!("{err}")).ok(); let stream = read_while_map(&interface.inner, 256, 2, to_stdout)?; - if let Some(_) = stream.last().await { + if stream.last().await.is_some() { trace!("Read stream complete."); } }, diff --git a/support/device/src/usb/mod.rs b/support/device/src/usb/mod.rs index 9601fe39..630a6303 100644 --- a/support/device/src/usb/mod.rs +++ b/support/device/src/usb/mod.rs @@ -143,11 +143,10 @@ impl Device { trace!("opening device"); // Special case: if we already have an interface, mostly possible serial: - if self.interface.is_some() { - match self.interface_mut()? { - crate::interface::Interface::Serial(i) => i.open()?, - _ => {}, - }; + if let Some(interface) = self.interface.as_mut() { + if let crate::interface::Interface::Serial(serial) = interface { + serial.open()? + } return Ok(()); } @@ -233,19 +232,21 @@ impl Device { } #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] - pub fn close(&mut self) { - self.info.serial_number().map(|s| debug!("closing {s}")); - self.interface.take(); - self.inner.take(); - } + pub fn close(&mut self) { self.close_inner(); } #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] - pub fn close_with_reset(&mut self) { - self.info.serial_number().map(|s| debug!("closing* {s}")); - self.interface.take(); - if let Some(dev) = self.inner.take() { - dev.reset().map_err(|err| error!("{err}")).ok(); + pub fn close_with_reset(&mut self) -> Result<(), Error> { + if let Some(dev) = self.close_inner() { + dev.reset()?; } + Ok(()) + } + + #[inline] + fn close_inner(&mut self) -> Option { + self.info.serial_number().inspect(|sn| debug!("closing {sn}")); + self.interface.take(); + self.inner.take() } } diff --git a/support/tool/Cargo.toml b/support/tool/Cargo.toml index 4de1ba3e..fac2a0db 100644 --- a/support/tool/Cargo.toml +++ b/support/tool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-tool" -version = "0.3.3" +version = "0.3.4" readme = "README.md" description = "Tool for interaction with Playdate device and sim." keywords = ["playdate", "usb", "utility"] diff --git a/support/tool/src/cli.rs b/support/tool/src/cli.rs index b595f36c..e55a9736 100644 --- a/support/tool/src/cli.rs +++ b/support/tool/src/cli.rs @@ -122,13 +122,13 @@ pub enum DeviceKind { Storage, } -impl ToString for DeviceKind { - fn to_string(&self) -> String { +impl std::fmt::Display for DeviceKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { DeviceKind::Any => "any", DeviceKind::Data => "data", DeviceKind::Storage => "storage", - }.to_owned() + }.fmt(f) } } diff --git a/support/tool/src/main.rs b/support/tool/src/main.rs index 19bb7cd2..a91642d8 100644 --- a/support/tool/src/main.rs +++ b/support/tool/src/main.rs @@ -346,7 +346,7 @@ async fn send(query: Query, #[cfg_attr(feature = "tracing", tracing::instrument())] async fn read(query: Query) -> Result<(), error::Error> { let by_dev = |mut device: device::Device| -> Result<_, Error> { - device.info().serial_number().map(|s| trace!("reading {s}")); + trace!("reading {}", device.info().serial_number().unwrap_or("")); let fut = async move { usb::io::redirect_to_stdout(&mut device).await }; Ok(fut) }; diff --git a/support/utils/Cargo.toml b/support/utils/Cargo.toml index 27f28193..4e9ebaf5 100644 --- a/support/utils/Cargo.toml +++ b/support/utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-build-utils" -version = "0.3.1" +version = "0.3.2" readme = "README.md" description = "Utils that help to build program with Rust and Playdate API" keywords = ["playdate", "utility"] diff --git a/support/utils/src/compile.rs b/support/utils/src/compile.rs index d5963b2a..c0bb456a 100644 --- a/support/utils/src/compile.rs +++ b/support/utils/src/compile.rs @@ -1,6 +1,4 @@ -/*! - Utils for compilation binaries. -*/ +//! Utils for compilation binaries. /// Do not forget