feat(build): Add disable_comments option (#1127)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
authors = ["bouzuya <[email protected]>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "disable-comments"
|
||||
publish = false
|
||||
version = "0.1.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
prost = "0.11"
|
||||
tonic = { path = "../../tonic" }
|
||||
|
||||
[build-dependencies]
|
||||
prost-build = "0.11"
|
||||
tonic-build = { path = "../../tonic-build" }
|
||||
@@ -0,0 +1,11 @@
|
||||
fn main() {
|
||||
let mut config = prost_build::Config::default();
|
||||
config.disable_comments(&["test.Input1", "test.Output1"]);
|
||||
tonic_build::configure()
|
||||
.disable_comments("test.Service1")
|
||||
.disable_comments("test.Service1.Rpc1")
|
||||
.build_client(true)
|
||||
.build_server(true)
|
||||
.compile_with_config(config, &["proto/test.proto"], &["proto"])
|
||||
.unwrap();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package test;
|
||||
|
||||
// This comment will be removed.
|
||||
service Service1 {
|
||||
// This comment will be removed.
|
||||
rpc Rpc1(Input1) returns (Output1);
|
||||
// This comment will not be removed.
|
||||
rpc Rpc2(Input2) returns (Output2);
|
||||
}
|
||||
|
||||
// This comment will not be removed.
|
||||
service Service2 {
|
||||
// This comment will not be removed.
|
||||
rpc Rpc(Input1) returns (Output1);
|
||||
}
|
||||
|
||||
// This comment will be removed.
|
||||
message Input1 {}
|
||||
|
||||
// This comment will not be removed.
|
||||
message Input2 {}
|
||||
|
||||
// This comment will be removed.
|
||||
message Output1 {}
|
||||
|
||||
// This comment will not be removed.
|
||||
message Output2 {}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod pb {
|
||||
tonic::include_proto!("test");
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
let path = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("test.rs");
|
||||
let s = fs::read_to_string(path).unwrap();
|
||||
assert!(!s.contains("This comment will be removed."));
|
||||
let mut count = 0_usize;
|
||||
let mut index = 0_usize;
|
||||
while let Some(found) = s[index..].find("This comment will not be removed.") {
|
||||
index += found + 1;
|
||||
count += 1;
|
||||
}
|
||||
assert_eq!(count, 2 + 3 + 3); // message: 2, client: 3, server: 3
|
||||
}
|
||||
Reference in New Issue
Block a user