Fix rustfmt in tonic-build
This commit is contained in:
@@ -13,6 +13,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
rust-version: ${{ matrix.rust }}
|
rust-version: ${{ matrix.rust }}
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
|
- name: Install rustfmt
|
||||||
|
run: rustup component add rustfmt
|
||||||
- name: Run interop tests
|
- name: Run interop tests
|
||||||
run: ./tonic-interop/test.sh
|
run: ./tonic-interop/test.sh
|
||||||
- name: Run interop tests with tls
|
- name: Run interop tests with tls
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ quote = "1.0"
|
|||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["transport"]
|
default = ["transport", "rustfmt"]
|
||||||
# TODO: reenable this feature
|
rustfmt = []
|
||||||
# rustfmt = []
|
|
||||||
transport = []
|
transport = []
|
||||||
|
|||||||
+19
-28
@@ -68,12 +68,7 @@ impl Builder {
|
|||||||
|
|
||||||
/// Compile the .proto files and execute code generation.
|
/// Compile the .proto files and execute code generation.
|
||||||
#[cfg_attr(not(feature = "rustfmt"), allow(unused_variables))]
|
#[cfg_attr(not(feature = "rustfmt"), allow(unused_variables))]
|
||||||
pub fn compile<P: AsRef<Path>>(
|
pub fn compile<P: AsRef<Path>>(self, protos: &[P], includes: &[P]) -> io::Result<()> {
|
||||||
self,
|
|
||||||
protos: &[P],
|
|
||||||
includes: &[P],
|
|
||||||
package: &str,
|
|
||||||
) -> io::Result<()> {
|
|
||||||
let mut config = Config::new();
|
let mut config = Config::new();
|
||||||
|
|
||||||
let out_dir = self
|
let out_dir = self
|
||||||
@@ -86,10 +81,7 @@ impl Builder {
|
|||||||
config.compile_protos(protos, includes)?;
|
config.compile_protos(protos, includes)?;
|
||||||
|
|
||||||
#[cfg(feature = "rustfmt")]
|
#[cfg(feature = "rustfmt")]
|
||||||
fmt(
|
fmt(out_dir.to_str().expect("Expected utf8 out_dir"));
|
||||||
out_dir.to_str().expect("Expected utf8 out_dir"),
|
|
||||||
&format!("{}.rs", package),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -113,35 +105,34 @@ pub fn configure() -> Builder {
|
|||||||
pub fn compile_protos(proto_path: impl AsRef<Path>) -> io::Result<()> {
|
pub fn compile_protos(proto_path: impl AsRef<Path>) -> io::Result<()> {
|
||||||
let proto_path: &Path = proto_path.as_ref();
|
let proto_path: &Path = proto_path.as_ref();
|
||||||
|
|
||||||
let package = proto_path
|
|
||||||
.file_stem()
|
|
||||||
.expect("file should have a stem if it has an extension")
|
|
||||||
.to_str()
|
|
||||||
.expect("expected valid utf-8 filename");
|
|
||||||
|
|
||||||
// directory the main .proto file resides in
|
// directory the main .proto file resides in
|
||||||
let proto_dir = proto_path
|
let proto_dir = proto_path
|
||||||
.parent()
|
.parent()
|
||||||
.expect("proto file should reside in a directory");
|
.expect("proto file should reside in a directory");
|
||||||
|
|
||||||
self::configure().compile(&[proto_path], &[proto_dir], package)?;
|
self::configure().compile(&[proto_path], &[proto_dir])?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rustfmt")]
|
#[cfg(feature = "rustfmt")]
|
||||||
fn fmt(out_dir: &str, file: &str) {
|
fn fmt(out_dir: &str) {
|
||||||
let out = Command::new("rustfmt")
|
let dir = std::fs::read_dir(out_dir).unwrap();
|
||||||
.arg("--emit")
|
|
||||||
.arg("files")
|
|
||||||
.arg("--edition")
|
|
||||||
.arg("2018")
|
|
||||||
.arg(format!("{}/{}", out_dir, file))
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
println!("out: {:?}", out);
|
for entry in dir {
|
||||||
assert!(out.status.success());
|
let file = entry.unwrap().file_name().into_string().unwrap();
|
||||||
|
let out = Command::new("rustfmt")
|
||||||
|
.arg("--emit")
|
||||||
|
.arg("files")
|
||||||
|
.arg("--edition")
|
||||||
|
.arg("2018")
|
||||||
|
.arg(format!("{}/{}", out_dir, file))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
println!("out: {:?}", out);
|
||||||
|
assert!(out.status.success());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServiceGenerator {
|
pub struct ServiceGenerator {
|
||||||
|
|||||||
Reference in New Issue
Block a user