feat(build): use prettyplease to format output (#890) (#904)

This commit is contained in:
Matthias Vogelgesang
2022-02-10 13:20:52 -05:00
committed by GitHub
parent 468e4221f0
commit d6c0fc112b
11 changed files with 8 additions and 93 deletions
+4 -23
View File
@@ -22,8 +22,6 @@ pub fn configure() -> Builder {
client_attributes: Attributes::default(),
proto_path: "super".to_string(),
compile_well_known_types: false,
#[cfg(feature = "rustfmt")]
format: true,
emit_package: true,
protoc_args: Vec::new(),
include_file: None,
@@ -184,7 +182,8 @@ impl prost_build::ServiceGenerator for ServiceGenerator {
#clients
};
let code = format!("{}", client_service);
let ast: syn::File = syn::parse2(client_service).expect("not a valid tokenstream");
let code = prettyplease::unparse(&ast);
buf.push_str(&code);
self.clients = TokenStream::default();
@@ -197,7 +196,8 @@ impl prost_build::ServiceGenerator for ServiceGenerator {
#servers
};
let code = format!("{}", server_service);
let ast: syn::File = syn::parse2(server_service).expect("not a valid tokenstream");
let code = prettyplease::unparse(&ast);
buf.push_str(&code);
self.servers = TokenStream::default();
@@ -223,8 +223,6 @@ pub struct Builder {
pub(crate) include_file: Option<PathBuf>,
out_dir: Option<PathBuf>,
#[cfg(feature = "rustfmt")]
format: bool,
}
impl Builder {
@@ -247,13 +245,6 @@ impl Builder {
self
}
/// Enable the output to be formated by rustfmt.
#[cfg(feature = "rustfmt")]
pub fn format(mut self, run: bool) -> Self {
self.format = run;
self
}
/// Set the output directory to generate code to.
///
/// Defaults to the `OUT_DIR` environment variable.
@@ -397,9 +388,6 @@ impl Builder {
PathBuf::from(std::env::var("OUT_DIR").unwrap())
};
#[cfg(feature = "rustfmt")]
let format = self.format;
config.out_dir(out_dir.clone());
if let Some(path) = self.file_descriptor_set_path.as_ref() {
config.file_descriptor_set_path(path);
@@ -428,13 +416,6 @@ impl Builder {
config.compile_protos(protos, includes)?;
#[cfg(feature = "rustfmt")]
{
if format {
super::fmt(out_dir.to_str().expect("Expected utf8 out_dir"));
}
}
Ok(())
}
}