build.rs: factor out getting git command output into helper fn
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
		
							
								
								
									
										23
									
								
								build.rs
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								build.rs
									
									
									
									
									
								
							| @ -2,22 +2,19 @@ | |||||||
| use std::env; | use std::env; | ||||||
| use std::process::Command; | use std::process::Command; | ||||||
|  |  | ||||||
|  | fn git_command(args: &[&str]) -> String { | ||||||
|  |     match Command::new("git").args(args).output() { | ||||||
|  |         Ok(output) => String::from_utf8(output.stdout).unwrap().trim_end().to_string(), | ||||||
|  |         Err(err) => { | ||||||
|  |             panic!("git {:?} failed: {}", args, err); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| fn main() { | fn main() { | ||||||
|     let repoid = match env::var("REPOID") { |     let repoid = match env::var("REPOID") { | ||||||
|         Ok(repoid) => repoid, |         Ok(repoid) => repoid, | ||||||
|         Err(_) => { |         Err(_) => git_command(&["rev-parse", "HEAD"]), | ||||||
|             match Command::new("git") |  | ||||||
|                 .args(&["rev-parse", "HEAD"]) |  | ||||||
|                 .output() |  | ||||||
|             { |  | ||||||
|                 Ok(output) => { |  | ||||||
|                     String::from_utf8(output.stdout).unwrap() |  | ||||||
|                 } |  | ||||||
|                 Err(err) => { |  | ||||||
|                     panic!("git rev-parse failed: {}", err); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     println!("cargo:rustc-env=REPOID={}", repoid); |     println!("cargo:rustc-env=REPOID={}", repoid); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user