From e6eb484021d6ce37fc8a4f1023355dfe572a2e38 Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Tue, 9 Apr 2024 09:01:46 +0200 Subject: [PATCH] introduce expander for easier debugging --- Cargo.lock | 45 +++++++++++++++++++++++++++++++++++++ progenitor-macro/Cargo.toml | 1 + progenitor-macro/src/lib.rs | 4 ++++ progenitor/Cargo.toml | 1 + 4 files changed, 51 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 8f2dc39b..d84bcf48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,6 +197,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[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.4" @@ -412,6 +421,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -561,6 +571,20 @@ dependencies = [ "uuid", ] +[[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.58", +] + [[package]] name = "expectorate" version = "1.1.0" @@ -608,6 +632,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" @@ -1367,6 +1400,16 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[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.58", +] + [[package]] name = "proc-macro2" version = "1.0.79" @@ -1385,6 +1428,7 @@ dependencies = [ "built", "chrono", "clap", + "expander", "futures", "openapiv3 1.0.4", "percent-encoding", @@ -1446,6 +1490,7 @@ dependencies = [ name = "progenitor-macro" version = "0.2.1-dev" dependencies = [ + "expander", "openapiv3 1.0.4", "proc-macro2", "progenitor-impl", diff --git a/progenitor-macro/Cargo.toml b/progenitor-macro/Cargo.toml index 813c7a53..f62508e3 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 5231d819..247e2c76 100644 --- a/progenitor-macro/src/lib.rs +++ b/progenitor-macro/src/lib.rs @@ -271,5 +271,9 @@ fn do_generate_api(item: TokenStream) -> Result { const _: &str = include_str!(#path_str); }; + let output = expander::Expander::new(format!("{}", std::path::PathBuf::from(spec.value()).file_name().unwrap().to_string_lossy())) + .fmt(expander::Edition::_2021) + .verbose(true) + .write_to_out_dir(output).expect("Writing file works. qed"); Ok(output.into()) } diff --git a/progenitor/Cargo.toml b/progenitor/Cargo.toml index 6fbbbe98..6a1d5d16 100644 --- a/progenitor/Cargo.toml +++ b/progenitor/Cargo.toml @@ -20,6 +20,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.9" clap = { version = "4.1.14", features = ["derive"] } +expander = "2.1.0" [build-dependencies] built = { version = "0.6", features = ["git2"] }