-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
162 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/src/generated/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
authors = ["bouzuya <m@bouzuya.net>"] | ||
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::{fs, path::PathBuf}; | ||
|
||
fn main() { | ||
let out_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) | ||
.join("src") | ||
.join("generated"); | ||
fs::create_dir_all(out_dir.as_path()).unwrap(); | ||
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) | ||
.out_dir(format!("{}", out_dir.display())) | ||
.compile_with_config(config, &["proto/test.proto"], &["proto"]) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod pb { | ||
include!("generated/test.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::{fs, path::PathBuf}; | ||
|
||
#[test] | ||
fn test() { | ||
let path = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) | ||
.join("src") | ||
.join("generated") | ||
.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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters