From cb0acc2462cade3fb763b2f732982ce533c965e1 Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Tue, 9 Apr 2024 09:01:46 +0200 Subject: [PATCH] feat: introduce `expander` for easier debugging --- Cargo.lock | 45 +++++++++++++++++++++++++++++++++++++ progenitor-macro/Cargo.toml | 1 + progenitor-macro/src/lib.rs | 13 +++++++++++ progenitor/Cargo.toml | 1 + 4 files changed, 60 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f50d00a3..9d463a1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -208,6 +208,15 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest", +] + [[package]] name = "block-buffer" version = "0.10.2" @@ -456,6 +465,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -643,6 +653,20 @@ dependencies = [ "wasm-bindgen-test", ] +[[package]] +name = "expander" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00e83c02035136f1592a47964ea60c05a50e4ed8b5892cfac197063850898d4d" +dependencies = [ + "blake2", + "fs-err", + "prettier-please", + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "expectorate" version = "1.1.0" @@ -690,6 +714,15 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs-err" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41" +dependencies = [ + "autocfg", +] + [[package]] name = "futures" version = "0.3.30" @@ -1374,6 +1407,16 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "prettier-please" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22020dfcf177fcc7bf5deaf7440af371400c67c0de14c399938d8ed4fb4645d3" +dependencies = [ + "proc-macro2", + "syn 2.0.66", +] + [[package]] name = "prettyplease" version = "0.2.19" @@ -1399,6 +1442,7 @@ version = "0.7.0" dependencies = [ "base64 0.22.1", "chrono", + "expander", "futures", "percent-encoding", "progenitor-client", @@ -1461,6 +1505,7 @@ dependencies = [ name = "progenitor-macro" version = "0.7.0" dependencies = [ + "expander", "openapiv3", "proc-macro2", "progenitor-impl", diff --git a/progenitor-macro/Cargo.toml b/progenitor-macro/Cargo.toml index c7af7197..469ae0f9 100644 --- a/progenitor-macro/Cargo.toml +++ b/progenitor-macro/Cargo.toml @@ -21,3 +21,4 @@ serde_json = "1.0" serde_yaml = "0.9" serde_tokenstream = "0.2.0" syn = { version = "2.0", features = ["full", "extra-traits"] } +expander = "2" diff --git a/progenitor-macro/src/lib.rs b/progenitor-macro/src/lib.rs index 60111f3b..f25156f7 100644 --- a/progenitor-macro/src/lib.rs +++ b/progenitor-macro/src/lib.rs @@ -405,5 +405,18 @@ fn do_generate_api(item: TokenStream) -> Result { const _: &str = include_str!(#path_str); }; + let output = if let Some(dest) = std::env::var("PROGENITOR_OUTPUT_DEBUG") + .map(std::path::PathBuf::from_str) + { + eprintln!("Writing generated output to {}", path.display()); + expander::Expander::new(dest.filename().expect("Environment var `PROGENITOR_OUTPUT_DEBUG` must contain path with filename")) + .fmt(expander::Edition::_2021) + .verbose(true) + .write_to(output, dest.parent().expect("If path has filename, parent must be root / drive at least. qed")) + .write_to_out_dir(output) + .expect("Writing file works. qed") + } else { + output + }; Ok(output.into()) } diff --git a/progenitor/Cargo.toml b/progenitor/Cargo.toml index 014806a8..2e030397 100644 --- a/progenitor/Cargo.toml +++ b/progenitor/Cargo.toml @@ -14,6 +14,7 @@ progenitor-client = { version = "0.7.0", path = "../progenitor-client" } progenitor-impl = { version = "0.7.0", path = "../progenitor-impl" } progenitor-macro = { version = "0.7.0", path = "../progenitor-macro" } serde_json = "1.0" +expander = "2.1.0" [dev-dependencies] base64 = "0.22"