github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-supply-chain-master/processor/build.rs (about) 1 /* 2 * Copyright 2017 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ------------------------------------------------------------------------------ 16 */ 17 18 extern crate glob; 19 extern crate protoc_rust; 20 21 use std::fs; 22 use std::io::Write; 23 use protoc_rust::Customize; 24 25 fn main() { 26 // Generate protobuf files 27 let proto_src_files = glob_simple("../protos/*.proto"); 28 println!("{:?}", proto_src_files); 29 30 fs::create_dir_all("src/messages").unwrap(); 31 32 protoc_rust::run(protoc_rust::Args { 33 out_dir: "src/messages", 34 input: &proto_src_files 35 .iter() 36 .map(|a| a.as_ref()) 37 .collect::<Vec<&str>>(), 38 includes: &["src", "../protos"], 39 customize: Customize { 40 ..Default::default() 41 }, 42 }).expect("unable to run protoc"); 43 44 let mut file = fs::File::create("src/messages/mod.rs").unwrap(); 45 for filename in proto_src_files.iter() { 46 file.write_all(path_to_mod(&filename).as_bytes()).unwrap(); 47 } 48 } 49 50 fn path_to_mod(filename: &String) -> String { 51 filename.replace("../protos/", "pub mod ").replace(".proto", ";\n") 52 } 53 54 fn glob_simple(pattern: &str) -> Vec<String> { 55 glob::glob(pattern) 56 .expect("glob") 57 .map(|g| { 58 g.expect("item") 59 .as_path() 60 .to_str() 61 .expect("utf-8") 62 .to_owned() 63 }) 64 .collect() 65 }