diff --git a/Cargo.lock b/Cargo.lock index 58cabfc5..141a9053 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,21 @@ dependencies = [ "wasm-bindgen-test", ] +[[package]] +name = "expander" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2c470c71d91ecbd179935b24170459e926382eaaa86b590b78814e180d8a8e2" +dependencies = [ + "blake2", + "file-guard", + "fs-err", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "expectorate" version = "1.1.0" @@ -660,6 +685,16 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "file-guard" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21ef72acf95ec3d7dbf61275be556299490a245f017cf084bd23b4f68cf9407c" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "fnv" version = "1.0.7" @@ -690,6 +725,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" @@ -1390,6 +1434,7 @@ version = "0.7.0" dependencies = [ "base64 0.22.1", "chrono", + "expander", "futures", "percent-encoding", "progenitor-client", @@ -1451,6 +1496,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..ff447442 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.2.1" diff --git a/progenitor-macro/src/lib.rs b/progenitor-macro/src/lib.rs index 60111f3b..419ffe42 100644 --- a/progenitor-macro/src/lib.rs +++ b/progenitor-macro/src/lib.rs @@ -9,6 +9,7 @@ use std::{ fmt::Display, fs::File, path::{Path, PathBuf}, + str::FromStr, }; use openapiv3::OpenAPI; @@ -405,5 +406,17 @@ 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(|ref s| {std::path::PathBuf::from_str(s).expect("Environment var `PROGENITOR_OUTPUT_DEBUG` must contain a valid path")}).ok() + { + eprintln!("Writing generated output to {}", path.display()); + expander::Expander::new(dest.file_name().expect("Environment var `PROGENITOR_OUTPUT_DEBUG` must contain path with filename").to_string_lossy()) + .fmt(expander::Edition::_2021) + .verbose(true) + .write_to(output, dest.parent().expect("If path has filename, parent must be root / drive at least. qed")) + .expect("Writing file works. qed") + } else { + output + }; Ok(output.into()) } diff --git a/progenitor/Cargo.toml b/progenitor/Cargo.toml index 68537f83..96606ffc 100644 --- a/progenitor/Cargo.toml +++ b/progenitor/Cargo.toml @@ -13,6 +13,7 @@ categories = ["api-bindings", "compilers"] progenitor-client = { workspace = true } progenitor-impl = { workspace = true } progenitor-macro = { workspace = true } +expander = "2.1.0" [dev-dependencies] base64 = { workspace = true }