1111extern crate prost_build;
1212
1313#[ cfg( genproto) ]
14- use std:: { env, fs, path:: Path } ;
14+ use std:: { env, fs, io:: Write , path:: Path } ;
15+
16+ #[ cfg( genproto) ]
17+ const COPYRIGHT_HEADER : & str =
18+ "// This file is Copyright its original authors, visible in version control
19+ // history.
20+ //
21+ // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
22+ // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
23+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
24+ // You may not use this file except in accordance with one or both of these
25+ // licenses.
26+
27+ " ;
1528
1629/// To generate updated proto objects, run `RUSTFLAGS="--cfg genproto" cargo build`
1730fn main ( ) {
@@ -38,13 +51,13 @@ fn generate_protos() {
3851 & [ "src/proto/" ] ,
3952 )
4053 . expect ( "protobuf compilation failed" ) ;
41- println ! ( "OUT_DIR: {}" , & env:: var( "OUT_DIR" ) . unwrap( ) ) ;
42- let from_path = Path :: new ( & env :: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "api.rs" ) ;
43- fs :: copy ( from_path , "src/ api.rs") . unwrap ( ) ;
44- let from_path = Path :: new ( & env :: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "types.rs" ) ;
45- fs:: copy ( from_path, "src/types.rs" ) . unwrap ( ) ;
46- let from_path = Path :: new ( & env :: var ( "OUT_DIR ") . unwrap ( ) ) . join ( "events.rs" ) ;
47- fs :: copy ( from_path , "src/events.rs" ) . unwrap ( ) ;
48- let from_path = Path :: new ( & env :: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "error.rs" ) ;
49- fs :: copy ( from_path , "src/error.rs" ) . unwrap ( ) ;
54+ let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
55+ println ! ( "OUT_DIR: {}" , & out_dir ) ;
56+ for file in & [ " api.rs", "types.rs" , "events.rs" , "error.rs" ] {
57+ let from_path = Path :: new ( & out_dir ) . join ( file ) ;
58+ let content = fs:: read ( & from_path) . unwrap ( ) ;
59+ let mut dest = fs :: File :: create ( Path :: new ( "src ") . join ( file ) ) . unwrap ( ) ;
60+ dest . write_all ( COPYRIGHT_HEADER . as_bytes ( ) ) . unwrap ( ) ;
61+ dest . write_all ( & content ) . unwrap ( ) ;
62+ }
5063}
0 commit comments