Skip to content

Commit

Permalink
Use the new builder API from protobuf-build (#435)
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <[email protected]>
  • Loading branch information
nrc authored and overvenus committed Aug 6, 2019
1 parent ec9df5f commit c2174ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ raft-proto = { version = "0.6.0-alpha", default-features = false }
lazy_static = { version = "1.3", optional = true }

[build-dependencies]
protobuf-build = { version = "0.8", default-features = false }
protobuf-build = { version = "0.9.1", default-features = false }
55 changes: 5 additions & 50 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use protobuf_build::*;
use std::fs::read_dir;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::Path;

const BLACK_LIST: &[&str] = &["protobuf", "google", "gogoproto", "eraftpb"];
use protobuf_build::Builder;

fn main() {
let out_dir = format!("{}/protos", std::env::var("OUT_DIR").unwrap());
let file_names: Vec<_> = read_dir("proto")
.expect("Couldn't read proto directory")
.map(|e| {
format!(
"proto/{}",
e.expect("Couldn't list file").file_name().to_string_lossy()
)
})
.collect();

generate_files(
&["include".to_owned(), "proto".to_owned()],
&file_names,
&out_dir,
);
let mod_file_path = Path::new(&out_dir).join("mod.rs");
let mod_file = File::open(&mod_file_path).unwrap();
let reader = BufReader::new(mod_file);
let mut content = Vec::new();
let mut lines = reader.lines();
while let Some(l) = lines.next() {
let l = l.unwrap();
if BLACK_LIST.iter().any(|i| l.contains(i)) {
let mut level = 1;
while level > 0 {
let l = lines.next().unwrap().unwrap();
if l.contains('{') {
level += 1;
}
if l.contains('}') {
level -= 1;
}
}
} else {
content.push(l);
}
}
let mut mod_file = File::create(&mod_file_path).unwrap();
for l in content {
writeln!(mod_file, "{}", l).unwrap();
}
Builder::new()
.search_dir_for_protos("proto")
.append_to_black_list("eraftpb")
.generate()
}

0 comments on commit c2174ab

Please sign in to comment.