@@ -13,6 +13,19 @@ extern crate prost_build;
1313#[ cfg( genproto) ]
1414use std:: { env, fs, path:: Path } ;
1515
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+ " ;
28+
1629/// To generate updated proto objects, run `RUSTFLAGS="--cfg genproto" cargo build`
1730fn main ( ) {
1831 #[ cfg( genproto) ]
@@ -38,13 +51,12 @@ 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_to_string ( & from_path) . unwrap ( ) ;
59+ let with_header = format ! ( "{}{}" , COPYRIGHT_HEADER , content) ;
60+ fs:: write ( Path :: new ( "src" ) . join ( file) , with_header) . unwrap ( ) ;
61+ }
5062}
0 commit comments