forked from Mufanc/DexHunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
27 lines (22 loc) · 721 Bytes
/
Copy pathbuild.rs
File metadata and controls
27 lines (22 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::env;
use std::error::Error;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
fn exec(args: &[&str]) -> Result<String, Box<dyn Error>> {
let output = String::from_utf8(Command::new(args[0]).args(&args[1..]).output()?.stdout)?;
Ok(String::from(output.trim()))
}
fn main() -> Result<(), Box<dyn Error>> {
let output_dir = PathBuf::from(env::var("OUT_DIR")?);
let mut version_file = File::create(output_dir.join("VERSION"))?;
write!(
version_file,
"{}.r{}.{}",
env::var("CARGO_PKG_VERSION")?,
exec(&["git", "rev-list", "--count", "HEAD"])?,
exec(&["git", "rev-parse", "--short", "HEAD"])?
)?;
Ok(())
}