From 32ee76f7d80c681cb3dca68fdb4cef933501fcd2 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 21 Jul 2023 17:57:15 +0200 Subject: [PATCH] Add rustfmt_skip to generated files --- implementations/rust/preserves-schema/Makefile | 1 + .../preserves-schema/src/bin/preserves-schema-rs.rs | 4 ++++ .../rust/preserves-schema/src/compiler/mod.rs | 13 ++++++++++++- .../rust/preserves-schema/src/gen/mod.rs | 2 ++ .../rust/preserves-schema/src/gen/schema.rs | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/implementations/rust/preserves-schema/Makefile b/implementations/rust/preserves-schema/Makefile index 34434b2..4363381 100644 --- a/implementations/rust/preserves-schema/Makefile +++ b/implementations/rust/preserves-schema/Makefile @@ -5,5 +5,6 @@ regenerate: cargo run -- \ --prefix crate::gen \ --support-crate crate \ + --rustfmt-skip \ -o $(CURDIR)/src/gen \ ../../../schema/schema.bin diff --git a/implementations/rust/preserves-schema/src/bin/preserves-schema-rs.rs b/implementations/rust/preserves-schema/src/bin/preserves-schema-rs.rs index fc4cea5..e8f4e5d 100644 --- a/implementations/rust/preserves-schema/src/bin/preserves-schema-rs.rs +++ b/implementations/rust/preserves-schema/src/bin/preserves-schema-rs.rs @@ -22,6 +22,9 @@ struct CommandLine { #[structopt(long)] xref: Vec, + #[structopt(long)] + rustfmt_skip: bool, + input_glob: Vec, } @@ -43,6 +46,7 @@ fn main() -> Result<(), Error> { if let Some(c) = args.support_crate { config.support_crate = c; } + config.rustfmt_skip = args.rustfmt_skip; config.load_schemas_and_bundles( &expand_inputs(&args.input_glob)?, &expand_inputs(&args.xref)?)?; diff --git a/implementations/rust/preserves-schema/src/compiler/mod.rs b/implementations/rust/preserves-schema/src/compiler/mod.rs index 41c41d8..9ca2f0e 100644 --- a/implementations/rust/preserves-schema/src/compiler/mod.rs +++ b/implementations/rust/preserves-schema/src/compiler/mod.rs @@ -104,6 +104,7 @@ pub struct CompilerConfig { pub support_crate: String, pub external_modules: Map, pub plugins: Vec>, + pub rustfmt_skip: bool, } pub fn load_schema_or_bundle_with_purpose( @@ -189,6 +190,7 @@ impl CompilerConfig { Box::new(parsers::ParserPlugin), Box::new(unparsers::UnparserPlugin), ], + rustfmt_skip: false, } } @@ -319,7 +321,11 @@ pub fn compile(config: &CompilerConfig) -> io::Result<()> { lines.push(Formatter::to_string(vertical(false, seq![ "#![allow(unused_parens)]", - "#![allow(unused_imports)]", + "#![allow(unused_imports)]"]))); + if config.rustfmt_skip { + lines.push("#![cfg_attr(rustfmt, rustfmt_skip)]".to_owned()); + } + lines.push(Formatter::to_string(vertical(false, seq![ "", "use std::convert::TryFrom;", format!("use {}::support as _support;", &config.support_crate), @@ -352,6 +358,11 @@ pub fn compile(config: &CompilerConfig) -> io::Result<()> { mod_rs.extend(vec!["mod.rs"]); let mut lines = Vec::new(); + if config.rustfmt_skip { + lines.push("#![cfg_attr(rustfmt, rustfmt_skip)]".to_owned()); + lines.push("".to_owned()); + } + for (modpath, (_, module_purpose)) in config.bundle.iter() { if *module_purpose != Purpose::Codegen { continue; diff --git a/implementations/rust/preserves-schema/src/gen/mod.rs b/implementations/rust/preserves-schema/src/gen/mod.rs index 0c2b114..d60585a 100644 --- a/implementations/rust/preserves-schema/src/gen/mod.rs +++ b/implementations/rust/preserves-schema/src/gen/mod.rs @@ -1,3 +1,5 @@ +#![cfg_attr(rustfmt, rustfmt_skip)] + pub mod schema; use crate::support as _support; diff --git a/implementations/rust/preserves-schema/src/gen/schema.rs b/implementations/rust/preserves-schema/src/gen/schema.rs index c8094fc..97dc60a 100644 --- a/implementations/rust/preserves-schema/src/gen/schema.rs +++ b/implementations/rust/preserves-schema/src/gen/schema.rs @@ -1,5 +1,6 @@ #![allow(unused_parens)] #![allow(unused_imports)] +#![cfg_attr(rustfmt, rustfmt_skip)] use std::convert::TryFrom; use crate::support as _support;