rslib: auto-format protobuf code

prost-build doesn't generate rustfmt-safe code, so we had to add it to
the ignore list for rustfmt on "make check". However, the ignore list
isn't supported by stable rustfmt, so we have to work around this some
other way -- in this case, just do "rustfmt" on the generated file in
"build.rs" (this way, formatting errors in checked-in source code are
still caught but generated code doesn't cause spurrious errors).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai 2020-09-03 14:45:18 +10:00
parent 0455e760c6
commit 70339e07f9
No known key found for this signature in database
GPG key ID: 9D94B96321B9D012
2 changed files with 10 additions and 5 deletions

View file

@ -1,6 +1,7 @@
use std::fmt::Write; use std::fmt::Write;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::process::Command;
use fluent_syntax::ast::{Entry::Message, ResourceEntry}; use fluent_syntax::ast::{Entry::Message, ResourceEntry};
use fluent_syntax::parser::parse; use fluent_syntax::parser::parse;
@ -200,15 +201,20 @@ fn main() -> std::io::Result<()> {
fs::write(rust_string_path, rust_string_vec(&idents))?; fs::write(rust_string_path, rust_string_vec(&idents))?;
// output protobuf generated code // output protobuf generated code
// we avoid default OUT_DIR for now, as it breaks code completion
std::env::set_var("OUT_DIR", "src");
println!("cargo:rerun-if-changed=../proto/backend.proto"); println!("cargo:rerun-if-changed=../proto/backend.proto");
let mut config = prost_build::Config::new(); let mut config = prost_build::Config::new();
config.service_generator(service_generator());
config config
// we avoid default OUT_DIR for now, as it breaks code completion
.out_dir("src")
.service_generator(service_generator())
.compile_protos(&["../proto/backend.proto"], &["../proto"]) .compile_protos(&["../proto/backend.proto"], &["../proto"])
.unwrap(); .unwrap();
// rustfmt the protobuf code
let rustfmt = Command::new("rustfmt")
.arg(Path::new("src/backend_proto.rs"))
.status()
.unwrap();
assert!(rustfmt.success(), "rustfmt backend_proto.rs failed");
// write the other language ftl files // write the other language ftl files
let mut ftl_lang_dirs = vec!["./ftl/repo/core".to_string()]; let mut ftl_lang_dirs = vec!["./ftl/repo/core".to_string()];

View file

@ -1 +0,0 @@
ignore = ["backend_proto.rs"]