1- use std:: {
2- env, fs,
3- io:: Read ,
4- path:: PathBuf ,
5- process:: { Command , Stdio } ,
6- } ;
1+ use std:: { env, fs, path:: PathBuf } ;
72
83fn main ( ) -> std:: io:: Result < ( ) > {
94 let config = std:: fs:: read_to_string ( "Cargo.toml" ) ?;
@@ -22,39 +17,9 @@ fn main() -> std::io::Result<()> {
2217 let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
2318 let dest_path = PathBuf :: from ( out_dir) . join ( "version_file" ) ;
2419
25- // Input buffers
26- let mut branch_buf = String :: new ( ) ;
27- let mut head_buf = String :: new ( ) ;
28-
29- let _ = Command :: new ( "git" )
30- . arg ( "branch" )
31- . arg ( "--show-current" )
32- . stdout ( Stdio :: piped ( ) )
33- . spawn ( )
34- . expect ( "Couldn't get the current branch" )
35- . stdout
36- . unwrap ( )
37- . read_to_string ( & mut branch_buf) ;
38- let _ = Command :: new ( "git" )
39- . arg ( "rev-parse" )
40- . arg ( "HEAD" )
41- . stdout ( Stdio :: piped ( ) )
42- . spawn ( )
43- . expect ( "Couldn't get the current Git HEAD" )
44- . stdout
45- . unwrap ( )
46- . read_to_string ( & mut head_buf) ;
47-
48- branch_buf. remove ( branch_buf. len ( ) - 1 ) ;
49- head_buf. remove ( head_buf. len ( ) - 1 ) ;
20+ fs:: write ( & dest_path, format ! ( "{}" , version_str) ) . unwrap ( ) ;
5021
5122 println ! ( "cargo:rerun-if-changed=Cargo.toml" ) ;
5223
53- fs:: write (
54- & dest_path,
55- format ! ( "{} on {} with {}" , version_str, branch_buf, head_buf) ,
56- )
57- . unwrap ( ) ;
58-
5924 Ok ( ( ) )
6025}
0 commit comments