2
0
mirror of https://github.com/xvxx/phetch synced 2024-11-05 00:00:58 +00:00
phetch/build.rs

27 lines
756 B
Rust
Raw Normal View History

2020-01-06 18:18:27 +00:00
use std::{env, process};
2020-01-04 22:10:51 +00:00
fn main() {
2020-01-06 18:18:27 +00:00
println!("cargo:rustc-env=PLATFORM={}", env::var("TARGET").unwrap());
2020-01-06 18:26:48 +00:00
println!("cargo:rustc-env=BUILD_DATE={}", sh("date +%Y-%m-%d"));
2020-01-04 22:10:51 +00:00
println!(
2020-01-06 18:18:27 +00:00
"cargo:rustc-env=GIT_REF={}",
sh("git rev-parse --short HEAD")
)
}
fn sh(args: &str) -> String {
2020-02-02 00:01:35 +00:00
let args: Vec<&str> = args.split(' ').collect();
2020-01-06 18:18:27 +00:00
let cmd = args[0];
let args: Vec<_> = args.iter().skip(1).collect();
if let Ok(output) = process::Command::new(cmd).args(&args).output() {
if !output.status.success() {
eprintln!("Error running {} {:?}", cmd, args);
return "???".to_string();
2020-01-06 18:18:27 +00:00
}
String::from_utf8(output.stdout).unwrap()
} else {
String::new()
}
2020-01-04 22:10:51 +00:00
}